Coverage for watcher/api/controllers/v1/data_model.py: 88%

28 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-17 12:22 +0000

1# -*- encoding: utf-8 -*- 

2# Copyright (c) 2019 ZTE Corporation 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 

13# implied. 

14# See the License for the specific language governing permissions and 

15# limitations under the License. 

16 

17""" 

18An Interface for users and admin to List Data Model. 

19""" 

20 

21import pecan 

22from pecan import rest 

23from wsme import types as wtypes 

24import wsmeext.pecan as wsme_pecan 

25 

26from watcher.api.controllers.v1 import types 

27from watcher.api.controllers.v1 import utils 

28from watcher.common import exception 

29from watcher.common import policy 

30from watcher.decision_engine import rpcapi 

31 

32 

33class DataModelController(rest.RestController): 

34 """REST controller for data model""" 

35 

36 def __init__(self): 

37 super(DataModelController, self).__init__() 

38 

39 from_data_model = False 

40 """A flag to indicate if the requests to this controller are coming 

41 from the top-level resource DataModel.""" 

42 

43 @wsme_pecan.wsexpose(wtypes.text, wtypes.text, types.uuid) 

44 def get_all(self, data_model_type='compute', audit_uuid=None): 

45 """Retrieve information about the given data model. 

46 

47 :param data_model_type: The type of data model user wants to list. 

48 Supported values: compute. 

49 Future support values: storage, baremetal. 

50 The default value is compute. 

51 :param audit_uuid: The UUID of the audit, used to filter data model 

52 by the scope in audit. 

53 """ 

54 if not utils.allow_list_datamodel(): 

55 raise exception.NotAcceptable 

56 if self.from_data_model: 56 ↛ 57line 56 didn't jump to line 57 because the condition on line 56 was never true

57 raise exception.OperationNotPermitted 

58 allowed_data_model_type = [ 

59 'compute', 

60 ] 

61 if data_model_type not in allowed_data_model_type: 61 ↛ 62line 61 didn't jump to line 62 because the condition on line 61 was never true

62 raise exception.DataModelTypeNotFound( 

63 data_model_type=data_model_type) 

64 context = pecan.request.context 

65 de_client = rpcapi.DecisionEngineAPI() 

66 policy.enforce(context, 'data_model:get_all', 

67 action='data_model:get_all') 

68 rpc_all_data_model = de_client.get_data_model_info( 

69 context, 

70 data_model_type, 

71 audit_uuid) 

72 return rpc_all_data_model