1 # Copyright (c) 2019, CMCC Technologies. Co., Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from catalog.pub.utils.toscaparser.basemodel import BaseInfoModel
17 from catalog.pub.utils.toscaparser.servicemodel import SdcServiceModel
19 logger = logging.getLogger(__name__)
22 class SdInfoModel(BaseInfoModel):
23 def __init__(self, path, params):
24 super(SdInfoModel, self).__init__(path, params)
26 def parseModel(self, tosca):
27 self.metadata = self.buildMetadata(tosca)
28 self.inputs = self.build_inputs(tosca)
30 sdcModle = SdcServiceModel(tosca)
32 self.service = sdcModle.ns
33 if hasattr(tosca, 'nodetemplates'):
34 self.basepath = sdcModle.basepath
35 self.vnfs = sdcModle.vnfs
36 self.pnfs = sdcModle.pnfs
37 self.vls = sdcModle.vls
38 self.graph = sdcModle.graph
40 def build_inputs(self, tosca):
41 """ Get all the inputs for complex type"""
47 for input in tosca.inputs:
48 type = input.schema.type
49 if type.__eq__('list') or type.__eq__('map'):
51 entry_schema = self.get_entry_schema(input.schema.schema['entry_schema'])
52 self.get_child_input_repeat(complex_input, entry_schema, input)
53 result_inputs[input.schema.name] = complex_input
57 "type": input.schema.type,
58 "description": input.schema.description,
59 "required": input.schema.required,
61 result_inputs[input.schema.name] = simple_input
64 def get_child_input_repeat(self, complex_input, entry_schema, input):
65 custom_defs = input.custom_defs
66 properties = custom_defs[entry_schema]['properties']
67 for key, value in properties.items():
68 if value['type'].__eq__('list'):
69 child_complex_input = []
70 child_entry_schema = self.get_entry_schema(value['entry_schema'])
71 self.get_child_input_repeat(child_complex_input, child_entry_schema, input)
72 complex_input.append({key: child_complex_input})
74 if 'description' in list(value.keys()):
77 "type": value['type'],
78 "required": value['required'],
79 "description": value['description'],
84 "type": value['type'],
85 "required": value['required'],
87 complex_input.append(simple_input)
89 def get_entry_schema(self, entry_schema):
90 if isinstance(entry_schema, dict):
91 if 'type' in list(entry_schema.keys()):
92 entry_schema = entry_schema['type']