Merge "Add gitreview file of vfc-nfvo-lcm"
authorFu Jinhua <fu.jinhua@zte.com.cn>
Sat, 19 Aug 2017 06:03:55 +0000 (06:03 +0000)
committerGerrit Code Review <gerrit@onap.org>
Sat, 19 Aug 2017 06:03:55 +0000 (06:03 +0000)
lcm/pub/utils/toscaparser/__init__.py
lcm/pub/utils/toscaparser/basemodel.py [moved from lcm/pub/utils/toscaparser/baseinfomodel.py with 84% similarity]
lcm/pub/utils/toscaparser/etsinsdinfomodel.py [deleted file]
lcm/pub/utils/toscaparser/nsdmodel.py [new file with mode: 0644]
lcm/pub/utils/toscaparser/vnfdmodel.py [moved from lcm/pub/utils/toscaparser/etsivnfdinfomodel.py with 100% similarity]

index 4d9064e..b224f4e 100644 (file)
@@ -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
 
 
similarity index 84%
rename from lcm/pub/utils/toscaparser/baseinfomodel.py
rename to lcm/pub/utils/toscaparser/basemodel.py
index 0e186f6..19bde0d 100644 (file)
@@ -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 (file)
index 693a7fd..0000000
+++ /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 (file)
index 0000000..98b8213
--- /dev/null
@@ -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