diff options
-rw-r--r-- | lcm/pub/utils/toscaparser/basemodel.py | 40 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/nsdmodel.py | 46 |
2 files changed, 83 insertions, 3 deletions
diff --git a/lcm/pub/utils/toscaparser/basemodel.py b/lcm/pub/utils/toscaparser/basemodel.py index 254a326d..e1f841ff 100644 --- a/lcm/pub/utils/toscaparser/basemodel.py +++ b/lcm/pub/utils/toscaparser/basemodel.py @@ -190,4 +190,42 @@ class BaseInfoModel(object): def build_interfaces(self, node_template): if 'interfaces' in node_template.entity_tpl: return node_template.entity_tpl['interfaces'] - return None
\ No newline at end of file + return None + + def isVnf(self, node): + return node['nodeType'].upper().find('.VNF.') >= 0 or node['nodeType'].upper().endswith('.VNF') + + def isPnf(self, node): + return node['nodeType'].upper().find('.PNF.') >= 0 or node['nodeType'].upper().endswith('.PNF') + + def get_requirement_node_name(self, req_value): + return self.get_prop_from_obj(req_value, 'node') + + def get_prop_from_obj(self, obj, prop): + if isinstance(obj, str): + return obj + if (isinstance(obj, dict) and prop in obj): + return obj[prop] + return None + + def getNodeDependencys(self, node): + return self.getRequirementByName(node, 'dependency') + + def getRequirementByName(self, node, requirementName): + requirements = [] + if 'requirements' in node: + for item in node['requirements']: + for key, value in item.items(): + if key == requirementName: + requirements.append(value) + return requirements + + def get_networks(self, node): + rets = [] + if 'requirements' in node: + for item in node['requirements']: + for key, value in item.items(): + if key.upper().find('VIRTUALLINK') >=0: + rets.append({"key_name":key, "vl_id":self.get_requirement_node_name(value)}) + return rets + diff --git a/lcm/pub/utils/toscaparser/nsdmodel.py b/lcm/pub/utils/toscaparser/nsdmodel.py index c6e49430..7d7dafad 100644 --- a/lcm/pub/utils/toscaparser/nsdmodel.py +++ b/lcm/pub/utils/toscaparser/nsdmodel.py @@ -17,8 +17,8 @@ class EtsiNsdInfoModel(BaseInfoModel): nodeTemplates = map(functools.partial(self.buildNode, inputs=tosca.inputs, parsed_params=tosca.parsed_params), tosca.nodetemplates) - # self.vnfs = self._get_all_vnf(nodeTemplates) - # self.pnfs = self._get_all_pnf(nodeTemplates) + self.vnfs = self._get_all_vnf(nodeTemplates) + self.pnfs = self._get_all_pnf(nodeTemplates) # self.vls = self.get_all_vl(nodeTemplates) # self.cps = self.get_all_cp(nodeTemplates) # self.routers = self.get_all_router(nodeTemplates) @@ -57,3 +57,45 @@ class EtsiNsdInfoModel(BaseInfoModel): interfaces = self.build_interfaces(nodeTemplate) if interfaces: ret['interfaces'] = interfaces return ret + + def _get_all_vnf(self, nodeTemplates): + vnfs = [] + for node in nodeTemplates: + if self.isVnf(node): + vnf = {} + vnf['vnf_id'] = node['name'] + vnf['description'] = node['description'] + vnf['properties'] = node['properties'] + vnf['dependencies'] = map(lambda x: self.get_requirement_node_name(x), self.getNodeDependencys(node)) + vnf['networks'] = self.get_networks(node) + + vnfs.append(vnf) + return vnfs + + def _get_all_pnf(self, nodeTemplates): + pnfs = [] + for node in nodeTemplates: + if self.isPnf(node): + pnf = {} + pnf['pnf_id'] = node['name'] + pnf['description'] = node['description'] + pnf['properties'] = node['properties'] + pnf['cps'] = self.getVirtalBindingCpIds(node, nodeTemplates) + + pnfs.append(pnf) + return pnfs + + def getVirtalBindingCpIds(self, node, nodeTemplates): + return map(lambda x: x['name'], self.getVirtalBindingCps(node, nodeTemplates)) + + def getVirtalBindingCps(self, node, nodeTemplates): + cps = [] + for tmpnode in nodeTemplates: + if 'requirements' in tmpnode: + for item in tmpnode['requirements']: + for key, value in item.items(): + if key.upper().startswith('VIRTUALBINDING'): + req_node_name = self.get_requirement_node_name(value) + if req_node_name != None and req_node_name == node['name']: + cps.append(tmpnode) + return cps
\ No newline at end of file |