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