summaryrefslogtreecommitdiffstats
path: root/genericparser/pub
diff options
context:
space:
mode:
authoryangyan <yangyanyj@chinamobile.com>2019-05-21 16:38:42 +0800
committeryangyan <yangyanyj@chinamobile.com>2019-05-21 16:38:49 +0800
commite7310fb508784f72f54fbad5762cec67b134241b (patch)
treeeab03cb91156889e6271f2576b5ae527ab78c887 /genericparser/pub
parent0cd4e54ded5de005d5480d5b0d85535c1462b8eb (diff)
update code of genericparser
Change-Id: Ie8e9ee79ddf5f74d3b8ff4621698eb3651415b62 Issue-ID: VFC-1391 Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Diffstat (limited to 'genericparser/pub')
-rw-r--r--genericparser/pub/utils/toscaparsers/basemodel.py23
-rw-r--r--genericparser/pub/utils/toscaparsers/testdata/vnf/vcpesriov/vgw.csarbin15054 -> 23182 bytes
-rw-r--r--genericparser/pub/utils/toscaparsers/vnfdmodel.py2
-rw-r--r--genericparser/pub/utils/toscaparsers/vnfdparser/vnfd_sol_251.py78
4 files changed, 72 insertions, 31 deletions
diff --git a/genericparser/pub/utils/toscaparsers/basemodel.py b/genericparser/pub/utils/toscaparsers/basemodel.py
index a5c1f45..2b21456 100644
--- a/genericparser/pub/utils/toscaparsers/basemodel.py
+++ b/genericparser/pub/utils/toscaparsers/basemodel.py
@@ -515,10 +515,23 @@ class BaseInfoModel(object):
metadata = None
substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None)
if substitution_mappings:
- node['type'] = substitution_mappings['node_type']
- node['properties'] = substitution_mappings.get('properties', {})
- node['requirements'] = substitution_mappings.get('requirements', {})
- node['capabilities'] = substitution_mappings.get('capabilities', {})
- metadata = substitution_mappings.get('metadata', {})
+ nodeType = substitution_mappings['node_type']
+ logger.debug("nodeType %s", nodeType)
+ if "node_types" in tosca.tpl:
+ node_types = tosca.tpl['node_types'].get(nodeType, None)
+ derivedFrom = node_types.get('derived_from', "")
+ node['type'] = derivedFrom
+ node['properties'] = node_types.get('properties', {})
+ node['requirements'] = node_types.get('requirements', {})
+ node['capabilities'] = node_types.get('capabilities', {})
+ metadata = node_types.get('metadata', {})
+
+ if "type" not in node or node['type'] == "":
+ node['type'] = nodeType
+ node['properties'] = substitution_mappings.get('properties', {})
+ node['requirements'] = substitution_mappings.get('requirements', {})
+ node['capabilities'] = substitution_mappings.get('capabilities', {})
+ metadata = substitution_mappings.get('metadata', {})
+
node['metadata'] = metadata if metadata and metadata != {} else self.buildMetadata(tosca)
return node
diff --git a/genericparser/pub/utils/toscaparsers/testdata/vnf/vcpesriov/vgw.csar b/genericparser/pub/utils/toscaparsers/testdata/vnf/vcpesriov/vgw.csar
index 5e47b77..79e0d20 100644
--- a/genericparser/pub/utils/toscaparsers/testdata/vnf/vcpesriov/vgw.csar
+++ b/genericparser/pub/utils/toscaparsers/testdata/vnf/vcpesriov/vgw.csar
Binary files differ
diff --git a/genericparser/pub/utils/toscaparsers/vnfdmodel.py b/genericparser/pub/utils/toscaparsers/vnfdmodel.py
index 37a6472..95ae2c1 100644
--- a/genericparser/pub/utils/toscaparsers/vnfdmodel.py
+++ b/genericparser/pub/utils/toscaparsers/vnfdmodel.py
@@ -17,7 +17,7 @@ import logging
from genericparser.pub.config.config import VNFD_SCHEMA_VERSION_DEFAULT
from genericparser.pub.utils.toscaparsers.basemodel import BaseInfoModel
from genericparser.pub.utils.toscaparsers.vnfdparser import CreateVnfdSOLParser
-# from genericparser.pub.exceptions import CatalogException
+
logger = logging.getLogger(__name__)
diff --git a/genericparser/pub/utils/toscaparsers/vnfdparser/vnfd_sol_251.py b/genericparser/pub/utils/toscaparsers/vnfdparser/vnfd_sol_251.py
index d2f1229..6ad26e8 100644
--- a/genericparser/pub/utils/toscaparsers/vnfdparser/vnfd_sol_251.py
+++ b/genericparser/pub/utils/toscaparsers/vnfdparser/vnfd_sol_251.py
@@ -32,31 +32,52 @@ class VnfdSOL251():
vnf = self.model.get_substitution_mappings(tosca)
properties = vnf.get("properties", {})
metadata = vnf.get("metadata", {})
- if properties.get("descriptor_id", "") == "":
- descriptor_id = metadata.get("descriptor_id", "")
- if descriptor_id == "":
- descriptor_id = metadata.get("id", "")
- if descriptor_id == "":
- descriptor_id = metadata.get("UUID", "")
- properties["descriptor_id"] = descriptor_id
-
- if properties.get("descriptor_version", "") == "":
- version = metadata.get("template_version", "")
- if version == "":
- version = metadata.get("version", "")
- properties["descriptor_version"] = version
-
- if properties.get("provider", "") == "":
- provider = metadata.get("template_author", "")
- if provider == "":
- provider = metadata.get("provider", "")
- properties["provider"] = provider
-
- if properties.get("template_name", "") == "":
- template_name = metadata.get("template_name", "")
- if template_name == "":
- template_name = metadata.get("template_name", "")
- properties["template_name"] = template_name
+
+ for key, value in properties.items():
+ if isinstance(value, dict):
+ if value["type"] == "string":
+ properties[key] = value.get("default", "")
+ elif value["type"] == "list":
+ properties[key] = value.get("default", {})
+ else:
+ properties[key] = value.get("default", "")
+ ptype = "descriptor_id"
+ meta_types = ["descriptor_id", "id", "UUID"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "descriptor_version"
+ meta_types = ["template_version", "version"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "provider"
+ meta_types = ["template_author", "provider"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "template_name"
+ meta_types = ["template_name"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "software_version"
+ meta_types = ["software_version"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "product_name"
+ meta_types = ["product_name"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "flavour_description"
+ meta_types = ["flavour_description"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "vnfm_info"
+ meta_types = ["vnfm_info"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ ptype = "flavour_id"
+ meta_types = ["flavour_id"]
+ self._get_property(properties, metadata, ptype, meta_types)
+
+ logger.debug("vnf:%s", vnf)
return vnf
@@ -148,6 +169,13 @@ class VnfdSOL251():
return {"external_cps": external_cps, "forward_cps": forward_cps}
return {}
+ def _get_property(self, properties, metadata, ptype, meta_types):
+ if ptype not in properties or properties[ptype] == "":
+ for mtype in meta_types:
+ data = metadata.get(mtype, "")
+ if data != "":
+ properties[ptype] = data
+
def _trans_virtual_storage(self, virtual_storage):
if isinstance(virtual_storage, str):
return {"virtual_storage_id": virtual_storage}