1 # Copyright 2017 ZTE Corporation.
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.
17 from lcm.pub.utils.toscaparser import EtsiNsdInfoModel
20 class EtsiVnfdInfoModel(EtsiNsdInfoModel):
22 def __init__(self, path, params):
23 super(EtsiVnfdInfoModel, self).__init__(path, params)
25 def parseModel(self, tosca):
26 self.buidMetadata(tosca)
27 if hasattr(tosca, 'topology_template') and hasattr(tosca.topology_template, 'inputs'):
28 self.inputs = self.buildInputs(tosca.topology_template.inputs)
30 nodeTemplates = map(functools.partial(self.buildNode, inputs=tosca.inputs, parsed_params=tosca.parsed_params),
33 self.services = self._get_all_services(nodeTemplates)
34 self.vcloud = self._get_all_vcloud(nodeTemplates)
35 self.vcenter = self._get_all_vcenter(nodeTemplates)
36 self.image_files = self._get_all_image_file(nodeTemplates)
37 self.local_storages = self._get_all_local_storage(nodeTemplates)
38 self.volume_storages = self._get_all_volume_storage(nodeTemplates)
39 self.vdus = self._get_all_vdu(nodeTemplates)
40 self.vls = self.get_all_vl(nodeTemplates)
41 self.cps = self.get_all_cp(nodeTemplates)
44 def _get_all_services(self, nodeTemplates):
46 for node in nodeTemplates:
47 if self.isService(node):
49 service['serviceId'] = node['name']
50 if 'description' in node:
51 service['description'] = node['description']
52 service['properties'] = node['properties']
53 service['dependencies'] = map(lambda x: self.get_requirement_node_name(x),
54 self.getNodeDependencys(node))
55 service['networks'] = map(lambda x: self.get_requirement_node_name(x), self.getVirtualLinks(node))
60 def _get_all_vcloud(self, nodeTemplates):
62 for node in nodeTemplates:
63 if self._isVcloud(node):
65 if 'vdc_name' in node['properties']:
66 ret['vdc_name'] = node['properties']['vdc_name']
69 if 'storage_clusters' in node['properties']:
70 ret['storage_clusters'] = node['properties']['storage_clusters']
72 ret['storage_clusters'] = []
77 def _isVcloud(self, node):
78 return node['nodeType'].upper().find('.VCLOUD.') >= 0 or node['nodeType'].upper().endswith('.VCLOUD')
80 def _get_all_vcenter(self, nodeTemplates):
82 for node in nodeTemplates:
83 if self._isVcenter(node):
85 if 'compute_clusters' in node['properties']:
86 ret['compute_clusters'] = node['properties']['compute_clusters']
88 ret['compute_clusters'] = []
89 if 'storage_clusters' in node['properties']:
90 ret['storage_clusters'] = node['properties']['storage_clusters']
92 ret['storage_clusters'] = []
93 if 'network_clusters' in node['properties']:
94 ret['network_clusters'] = node['properties']['network_clusters']
96 ret['network_clusters'] = []
101 def _isVcenter(self, node):
102 return node['nodeType'].upper().find('.VCENTER.') >= 0 or node['nodeType'].upper().endswith('.VCENTER')
104 def _get_all_image_file(self, nodeTemplates):
106 for node in nodeTemplates:
107 if self._isImageFile(node):
109 ret['image_file_id'] = node['name']
110 if 'description' in node:
111 ret['description'] = node['description']
112 ret['properties'] = node['properties']
117 def _isImageFile(self, node):
118 return node['nodeType'].upper().find('.IMAGEFILE.') >= 0 or node['nodeType'].upper().endswith('.IMAGEFILE')
120 def _get_all_local_storage(self, nodeTemplates):
122 for node in nodeTemplates:
123 if self._isLocalStorage(node):
125 ret['local_storage_id'] = node['name']
126 if 'description' in node:
127 ret['description'] = node['description']
128 ret['properties'] = node['properties']
133 def _isLocalStorage(self, node):
134 return node['nodeType'].upper().find('.LOCALSTORAGE.') >= 0 or node['nodeType'].upper().endswith(
137 def _get_all_volume_storage(self, nodeTemplates):
139 for node in nodeTemplates:
140 if self._isVolumeStorage(node):
142 ret['volume_storage_id'] = node['name']
143 if 'description' in node:
144 ret['description'] = node['description']
145 ret['properties'] = node['properties']
146 ret['image_file'] = map(lambda x: self.get_requirement_node_name(x),
147 self.getRequirementByName(node, 'image_file'))
152 def _isVolumeStorage(self, node):
153 return node['nodeType'].upper().find('.VOLUMESTORAGE.') >= 0 or node['nodeType'].upper().endswith(
156 def _get_all_vdu(self, nodeTemplates):
158 for node in nodeTemplates:
161 ret['vdu_id'] = node['name']
162 if 'description' in node:
163 ret['description'] = node['description']
164 ret['properties'] = node['properties']
165 ret['image_file'] = self.get_node_image_file(node)
166 local_storages = self.getRequirementByName(node, 'local_storage')
167 ret['local_storages'] = map(lambda x: self.get_requirement_node_name(x), local_storages)
168 volume_storages = self.getRequirementByName(node, 'volume_storage')
169 ret['volume_storages'] = map(functools.partial(self._trans_volume_storage), volume_storages)
170 ret['dependencies'] = map(lambda x: self.get_requirement_node_name(x), self.getNodeDependencys(node))
172 nfv_compute = self.getCapabilityByName(node, 'nfv_compute')
173 if nfv_compute != None and 'properties' in nfv_compute:
174 ret['nfv_compute'] = nfv_compute['properties']
176 ret['vls'] = self.get_linked_vl_ids(node, nodeTemplates)
178 scalable = self.getCapabilityByName(node, 'scalable')
179 if scalable != None and 'properties' in scalable:
180 ret['scalable'] = scalable['properties']
182 ret['cps'] = self.getVirtalBindingCpIds(node, nodeTemplates)
183 ret['artifacts'] = self._build_artifacts(node)
188 def get_node_image_file(self, node):
189 rets = map(lambda x: self.get_requirement_node_name(x), self.getRequirementByName(node, 'guest_os'))
194 def _trans_volume_storage(self, volume_storage):
195 if isinstance(volume_storage, str):
196 return {"volume_storage_id": volume_storage}
199 ret['volume_storage_id'] = self.get_requirement_node_name(volume_storage)
200 if 'relationship' in volume_storage and 'properties' in volume_storage['relationship']:
201 if 'location' in volume_storage['relationship']['properties']:
202 ret['location'] = volume_storage['relationship']['properties']['location']
203 if 'device' in volume_storage['relationship']['properties']:
204 ret['device'] = volume_storage['relationship']['properties']['device']
208 def get_linked_vl_ids(self, node, node_templates):
210 cps = self.getVirtalBindingCps(node, node_templates)
212 vl_reqs = self.getVirtualLinks(cp)
213 for vl_req in vl_reqs:
214 vl_ids.append(self.get_requirement_node_name(vl_req))
217 def _build_artifacts(self, node):
219 if 'artifacts' in node and len(node['artifacts']) > 0:
220 artifacts = node['artifacts']
221 for name, value in artifacts.items():
223 if isinstance(value, dict):
224 ret['artifact_name'] = name
225 ret['type'] = value.get('type', '')
226 ret['file'] = value.get('file', '')
227 ret['repository'] = value.get('repository', '')
228 ret['deploy_path'] = value.get('deploy_path', '')
230 ret['artifact_name'] = name
233 ret['repository'] = ''
234 ret['deploy_path'] = ''
238 def get_all_cp(self, nodeTemplates):
240 for node in nodeTemplates:
243 cp['cp_id'] = node['name']
244 cp['cpd_id'] = node['name']
245 cp['description'] = node['description']
246 cp['properties'] = node['properties']
247 cp['vl_id'] = self.get_node_vl_id(node)
248 cp['vdu_id'] = self.get_node_vdu_id(node)
249 vls = self.buil_cp_vls(node)