diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-08-19 10:49:43 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-08-19 10:49:43 +0800 |
commit | ba414c7d4f7a6c91a2d045d0da7db89cd39701ff (patch) | |
tree | 436ec47e42b14a927275dd2214ac703972b8c55f | |
parent | 584308136c56f7834546f2b39079a74cb2a733f4 (diff) |
Add convert logic after parser
Change-Id: I64b47d3752d98d673b982a9f032de5b947a0b51d
Issue-ID: VFC-110
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | lcm/pub/utils/toscaparser/baseinfomodel.py | 24 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/etsinsdinfomodel.py | 51 |
2 files changed, 60 insertions, 15 deletions
diff --git a/lcm/pub/utils/toscaparser/baseinfomodel.py b/lcm/pub/utils/toscaparser/baseinfomodel.py index 0e186f60..19bde0db 100644 --- a/lcm/pub/utils/toscaparser/baseinfomodel.py +++ b/lcm/pub/utils/toscaparser/baseinfomodel.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 index 693a7fdd..ac932c26 100644 --- a/lcm/pub/utils/toscaparser/etsinsdinfomodel.py +++ b/lcm/pub/utils/toscaparser/etsinsdinfomodel.py @@ -1,3 +1,5 @@ +import functools + from lcm.pub.utils.toscaparser.baseinfomodel import BaseInfoModel @@ -7,6 +9,51 @@ class EtsiNsdInfoModel(BaseInfoModel): tosca = self.buildToscaTemplate(path, params) self.parseModel(tosca) - def parseModel(self, tosca): - pass
\ No newline at end of file + 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 |