diff options
-rw-r--r-- | lcm/pub/utils/toscaparser/__init__.py | 4 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/basemodel.py (renamed from lcm/pub/utils/toscaparser/baseinfomodel.py) | 24 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/etsinsdinfomodel.py | 12 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/nsdmodel.py | 59 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/vnfdmodel.py (renamed from lcm/pub/utils/toscaparser/etsivnfdinfomodel.py) | 0 |
5 files changed, 72 insertions, 27 deletions
diff --git a/lcm/pub/utils/toscaparser/__init__.py b/lcm/pub/utils/toscaparser/__init__.py index 4d9064ed..b224f4ef 100644 --- a/lcm/pub/utils/toscaparser/__init__.py +++ b/lcm/pub/utils/toscaparser/__init__.py @@ -14,8 +14,8 @@ import json from lcm.pub.utils.toscaparser.convert import convert_nsd, convert_vnfd -from lcm.pub.utils.toscaparser.etsinsdinfomodel import EtsiNsdInfoModel -from lcm.pub.utils.toscaparser.etsivnfdinfomodel import EtsiVnfdInfoModel +from lcm.pub.utils.toscaparser.nsdmodel import EtsiNsdInfoModel +from lcm.pub.utils.toscaparser.vnfdmodel import EtsiVnfdInfoModel from lcm.pub.utils.toscaparser.parser import parse_nsd_model, parse_vnfd_model diff --git a/lcm/pub/utils/toscaparser/baseinfomodel.py b/lcm/pub/utils/toscaparser/basemodel.py index 0e186f60..19bde0db 100644 --- a/lcm/pub/utils/toscaparser/baseinfomodel.py +++ b/lcm/pub/utils/toscaparser/basemodel.py @@ -1,4 +1,6 @@ +import copy import os +import shutil import urllib from toscaparser.tosca_template import ToscaTemplate @@ -7,8 +9,6 @@ from lcm.pub.utils.toscaparser.dataentityext import DataEntityExt class BaseInfoModel(object): - def __init__(self, path, params): - pass def buildToscaTemplate(self, path, params): file_name = None @@ -44,17 +44,11 @@ class BaseInfoModel(object): print "-----------------------------" return tosca_tpl finally: - pass - # if tosca_tpl != None and hasattr(tosca_tpl, "temp_dir") and os.path.exists(tosca_tpl.temp_dir): - # try: - # shutil.rmtree(tosca_tpl.temp_dir) - # except Exception, e: - # pass - # # if tosca_tpl != None and tosca_tpl.temp_dir != None and os.path.exists(tosca_tpl.temp_dir): - # # try: - # # shutil.rmtree(tosca_tpl.temp_dir) - # # except Exception, e: - # # pass + if tosca_tpl != None and hasattr(tosca_tpl, "temp_dir") and os.path.exists(tosca_tpl.temp_dir): + try: + shutil.rmtree(tosca_tpl.temp_dir) + except Exception, e: + pass def _check_download_file(self, path): if (path.startswith("ftp") or path.startswith("sftp")): @@ -103,3 +97,7 @@ class BaseInfoModel(object): else: self.ftp_get(userName, userPwd, hostIp, hostPort, remoteFileName, localFileName) return localFileName + + def buidMetadata(self, tosca): + if 'metadata' in tosca.tpl: + self.metadata = copy.deepcopy(tosca.tpl['metadata'])
\ No newline at end of file diff --git a/lcm/pub/utils/toscaparser/etsinsdinfomodel.py b/lcm/pub/utils/toscaparser/etsinsdinfomodel.py deleted file mode 100644 index 693a7fdd..00000000 --- a/lcm/pub/utils/toscaparser/etsinsdinfomodel.py +++ /dev/null @@ -1,12 +0,0 @@ -from lcm.pub.utils.toscaparser.baseinfomodel import BaseInfoModel - - -class EtsiNsdInfoModel(BaseInfoModel): - - def __init__(self, path, params): - tosca = self.buildToscaTemplate(path, params) - self.parseModel(tosca) - - - def parseModel(self, tosca): - pass
\ No newline at end of file diff --git a/lcm/pub/utils/toscaparser/nsdmodel.py b/lcm/pub/utils/toscaparser/nsdmodel.py new file mode 100644 index 00000000..98b82136 --- /dev/null +++ b/lcm/pub/utils/toscaparser/nsdmodel.py @@ -0,0 +1,59 @@ +import functools + +from lcm.pub.utils.toscaparser.basemodel import BaseInfoModel + + +class EtsiNsdInfoModel(BaseInfoModel): + + def __init__(self, path, params): + tosca = self.buildToscaTemplate(path, params) + self.parseModel(tosca) + + def parseModel(self, tosca): + self.buidMetadata(tosca) + if hasattr(tosca, 'topology_template') and hasattr(tosca.topology_template, 'inputs'): + self.inputs = self.buildInputs(tosca.topology_template.inputs) + + 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.vls = self.get_all_vl(nodeTemplates) + # self.cps = self.get_all_cp(nodeTemplates) + # self.routers = self.get_all_router(nodeTemplates) + # self.fps = self._get_all_fp(nodeTemplates) + # self.vnffgs = self._get_all_vnffg(tosca.topology_template.groups) + # self.server_groups = self.get_all_server_group(tosca.topology_template.groups) + # self.ns_exposed = self.get_all_endpoint_exposed(tosca.topology_template) + # self.policies = self._get_policies_scaling(tosca.topology_template.policies) + # self.ns_flavours = self.get_all_flavour(tosca.topology_template.groups) + # self.nested_ns = self.get_all_nested_ns(nodeTemplates) + + def buildInputs(self, top_inputs): + ret = {} + for tmpinput in top_inputs: + tmp = {} + tmp['type'] = tmpinput.type + tmp['description'] = tmpinput.description + tmp['default'] = tmpinput.default + + ret[tmpinput.name] = tmp + return ret + + def buildNode(self, nodeTemplate, inputs, parsed_params): + ret ={} + # ret['name'] = nodeTemplate.name + # ret['nodeType'] = nodeTemplate.type + # if 'description' in nodeTemplate.entity_tpl: + # ret['description'] = nodeTemplate.entity_tpl['description'] + # else: + # ret['description'] = '' + # props = self.buildProperties(nodeTemplate, parsed_params) + # ret['properties'] = self.verify_properties(props, inputs, parsed_params) + # ret['requirements'] = self.build_requirements(nodeTemplate) + # self.buildCapabilities(nodeTemplate, inputs, ret) + # self.buildArtifacts(nodeTemplate, inputs, ret) + # interfaces = self.build_interfaces(nodeTemplate) + # if interfaces: ret['interfaces'] = interfaces + return ret
\ No newline at end of file diff --git a/lcm/pub/utils/toscaparser/etsivnfdinfomodel.py b/lcm/pub/utils/toscaparser/vnfdmodel.py index 39e9a18b..39e9a18b 100644 --- a/lcm/pub/utils/toscaparser/etsivnfdinfomodel.py +++ b/lcm/pub/utils/toscaparser/vnfdmodel.py |