diff options
-rw-r--r-- | catalog/packages/biz/ns_descriptor.py | 33 | ||||
-rw-r--r-- | catalog/packages/biz/vnf_package.py | 4 | ||||
-rw-r--r-- | catalog/packages/tests/const.py | 12 | ||||
-rw-r--r-- | catalog/packages/tests/test_nspackage.py | 12 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/basemodel.py | 19 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/nsdmodel.py | 27 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/testdata/ns/ran.csar | bin | 3067 -> 3036 bytes | |||
-rw-r--r-- | catalog/pub/utils/toscaparser/vnfdmodel.py | 54 |
8 files changed, 117 insertions, 44 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py index 9bd00692..bdd56bd1 100644 --- a/catalog/packages/biz/ns_descriptor.py +++ b/catalog/packages/biz/ns_descriptor.py @@ -25,7 +25,6 @@ from catalog.pub.database.models import NSPackageModel, PnfPackageModel, VnfPack from catalog.pub.exceptions import CatalogException, ResourceNotFoundException from catalog.pub.utils import fileutil, toscaparser from catalog.pub.utils.values import ignore_case_get -from catalog.pub.utils.toscaparser.const import NS_UUID, NS_INVARIANTUUID, NS_NAME, NS_VERSION, NS_DESIGNER, NS_DESCRIPTION logger = logging.getLogger(__name__) @@ -131,14 +130,20 @@ class NsDescriptor(object): logger.debug("%s", nsd_json) nsd = json.JSONDecoder().decode(nsd_json) - nsd_id = nsd[METADATA].get(NS_UUID, "undefined") - if nsd_id == "undefined": - raise CatalogException("Service UUID(%s) does not exist in metadata." % nsd_id) + nsd_id = nsd.get("ns", {}).get("properties", {}).get("descriptor_id", "") + nsd_name = nsd.get("ns", {}).get("properties", {}).get("name", "") + nsd_version = nsd.get("ns", {}).get("properties", {}).get("version", "") + nsd_desginer = nsd.get("ns", {}).get("properties", {}).get("desginer", "") + invariant_id = nsd.get("ns", {}).get("properties", {}).get("invariant_id", "") + if nsd_id == "": + raise CatalogException("nsd_id(%s) does not exist in metadata." % nsd_id) if NSPackageModel.objects.filter(nsdId=nsd_id): raise CatalogException("NSD(%s) already exists." % nsd_id) for vnf in nsd["vnfs"]: - vnfd_id = vnf["properties"].get("id", "undefined") + vnfd_id = vnf["properties"].get("descriptor_id", "undefined") + if vnfd_id == "undefined": + vnfd_id = vnf["properties"].get("id", "undefined") pkg = VnfPackageModel.objects.filter(vnfdId=vnfd_id) if not pkg: vnfd_name = vnf.get("vnf_id", "undefined") @@ -147,11 +152,11 @@ class NsDescriptor(object): ns_pkgs.update( nsdId=nsd_id, - nsdName=nsd[METADATA].get(NS_NAME, "undefined"), - nsdDesginer=nsd[METADATA].get(NS_DESIGNER, "undefined"), - nsdDescription=nsd[METADATA].get(NS_DESCRIPTION, ""), - nsdVersion=nsd[METADATA].get(NS_VERSION, "undefined"), - invariantId=nsd[METADATA].get(NS_INVARIANTUUID, "undefined"), + nsdName=nsd_name, + nsdDesginer=nsd_desginer, + nsdDescription=nsd.get("description", ""), + nsdVersion=nsd_version, + invariantId=invariant_id, onboardingState=PKG_STATUS.ONBOARDED, operationalState=PKG_STATUS.ENABLED, usageState=PKG_STATUS.NOT_IN_USE, @@ -185,7 +190,9 @@ class NsDescriptor(object): nsd_model = json.JSONDecoder().decode(ns_pkg.nsdModel) vnf_pkg_ids = [] for vnf in nsd_model['vnfs']: - vnfd_id = vnf["properties"]["id"] + vnfd_id = vnf["properties"].get("descriptor_id", "undefined") + if vnfd_id == "undefined": + vnfd_id = vnf["properties"].get("id", "undefined") pkgs = VnfPackageModel.objects.filter(vnfdId=vnfd_id) for pkg in pkgs: vnf_pkg_ids.append(pkg.vnfPackageId) @@ -193,7 +200,9 @@ class NsDescriptor(object): pnf_info_ids = [] for pnf in nsd_model['pnfs']: - pnfd_id = pnf["properties"]["id"] + pnfd_id = pnf["properties"].get("descriptor_id", "undefined") + if pnfd_id == "undefined": + pnfd_id = pnf["properties"].get("id", "undefined") pkgs = PnfPackageModel.objects.filter(pnfdId=pnfd_id) for pkg in pkgs: pnf_info_ids.append(pkg.pnfPackageId) diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py index 1d014bc3..368d6f60 100644 --- a/catalog/packages/biz/vnf_package.py +++ b/catalog/packages/biz/vnf_package.py @@ -93,7 +93,7 @@ class VnfPackage(object): if not nsd_model: continue for vnf in nsd_model['vnfs']: - if del_vnfd_id == vnf["properties"]["id"]: + if del_vnfd_id == vnf["properties"]["descriptor_id"]: raise CatalogException('VNFD(%s) is referenced.' % del_vnfd_id) vnf_pkg.delete() vnf_pkg_path = os.path.join(CATALOG_ROOT_PATH, vnf_pkg_id) @@ -202,9 +202,11 @@ def parse_vnfd_and_save(vnf_pkg_id, vnf_pkg_path): vnf_provider = vnfd["vnf"].get("provider", "") vnfd_ver = vnfd["vnf"]["properties"].get("descriptor_verison", "") vnf_software_version = vnfd["vnf"]["properties"].get("software_version", "") + vnfd_product_name = vnfd["vnf"]["properties"].get("product_name", "") vnf_pkg.update( vnfPackageId=vnf_pkg_id, vnfdId=vnfd_id, + vnfdProductName=vnfd_product_name, vnfVendor=vnf_provider, vnfdVersion=vnfd_ver, vnfSoftwareVersion=vnf_software_version, diff --git a/catalog/packages/tests/const.py b/catalog/packages/tests/const.py index 78f61b77..caf60e3b 100644 --- a/catalog/packages/tests/const.py +++ b/catalog/packages/tests/const.py @@ -438,7 +438,17 @@ nsd_data = {"vnffgs": [{"vnffg_id": "vnffg1", "version": 1, "vendor": "ZTE", "id": "VCPE_NS", - "description": "vcpe_ns"}} + "description": "vcpe_ns"}, + "ns": { + "properties": { + "descriptor_id": "VCPE_NS", + "version": 1, + "name": "VCPE_NS", + "desginer": "ZTE", + "invariant_id": "vcpe_ns_sff_1" + } +} +} pnfd_data = { "metadata": { diff --git a/catalog/packages/tests/test_nspackage.py b/catalog/packages/tests/test_nspackage.py index 80b4acb4..4503bace 100644 --- a/catalog/packages/tests/test_nspackage.py +++ b/catalog/packages/tests/test_nspackage.py @@ -239,7 +239,17 @@ class TestNsPackage(TestCase): "version": 1, "vendor": "ZTE", "id": "VCPE_NS", - "description": "vcpe_ns"}} + "description": "vcpe_ns"}, + "ns": { + "properties": { + "descriptor_id": "VCPE_NS", + "version": 1, + "name": "VCPE_NS", + "desginer": "ZTE", + "invariant_id": "vcpe_ns_sff_1" + } + } + } def tearDown(self): pass diff --git a/catalog/pub/utils/toscaparser/basemodel.py b/catalog/pub/utils/toscaparser/basemodel.py index 705e3aaf..89e669a2 100644 --- a/catalog/pub/utils/toscaparser/basemodel.py +++ b/catalog/pub/utils/toscaparser/basemodel.py @@ -53,6 +53,7 @@ class BaseInfoModel(object): def __init__(self, path, params): tosca = self.buildToscaTemplate(path, params) + self.description = tosca.description self.parseModel(tosca) def parseModel(self, tosca): @@ -491,3 +492,21 @@ class BaseInfoModel(object): else: next_node = requirement[k] graph.add_node(next_node, [node.name]) + + def get_substitution_mappings(self, tosca): + node = { + 'properties': {}, + 'requirements': {}, + 'capabilities': {}, + 'metadata': {} + } + 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', {}) + node['metadata'] = metadata if metadata and metadata != {} else self.buildMetadata(tosca) + return node diff --git a/catalog/pub/utils/toscaparser/nsdmodel.py b/catalog/pub/utils/toscaparser/nsdmodel.py index 03133861..096579c2 100644 --- a/catalog/pub/utils/toscaparser/nsdmodel.py +++ b/catalog/pub/utils/toscaparser/nsdmodel.py @@ -36,6 +36,7 @@ class EtsiNsdInfoModel(BaseInfoModel): def parseModel(self, tosca): self.metadata = self.buildMetadata(tosca) + self.ns = self._build_ns(tosca) self.inputs = self.buildInputs(tosca) nodeTemplates = map(functools.partial(self.buildNode, tosca=tosca), tosca.nodetemplates) types = tosca.topology_template.custom_defs @@ -176,3 +177,29 @@ class EtsiNsdInfoModel(BaseInfoModel): for key, value in item.items(): rets.append({"key_name": key, "vl_id": self.get_requirement_node_name(value)}) return rets + + def _build_ns(self, tosca): + ns = self.get_substitution_mappings(tosca) + properties = ns.get("properties", {}) + metadata = ns.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("verison", "") == "": + version = metadata.get("template_version", "") + if version == "": + version = metadata.get("version", "") + properties["verison"] = version + if properties.get("designer", "") == "": + author = metadata.get("template_author", "") + properties["designer"] = author + if properties.get("name", "") == "": + template_name = metadata.get("template_name", "") + if template_name == "": + template_name = metadata.get("name", "") + properties["name"] = template_name + return ns diff --git a/catalog/pub/utils/toscaparser/testdata/ns/ran.csar b/catalog/pub/utils/toscaparser/testdata/ns/ran.csar Binary files differindex ad9c7d96..a9f85a53 100644 --- a/catalog/pub/utils/toscaparser/testdata/ns/ran.csar +++ b/catalog/pub/utils/toscaparser/testdata/ns/ran.csar diff --git a/catalog/pub/utils/toscaparser/vnfdmodel.py b/catalog/pub/utils/toscaparser/vnfdmodel.py index 0494bd63..ce0206fe 100644 --- a/catalog/pub/utils/toscaparser/vnfdmodel.py +++ b/catalog/pub/utils/toscaparser/vnfdmodel.py @@ -34,7 +34,7 @@ class EtsiVnfdInfoModel(BaseInfoModel): def parseModel(self, tosca): self.vnf = {} - self.vnf = self.build_vnf(tosca) + self.vnf = self._build_vnf(tosca) self.metadata = self.buildMetadata(tosca) self.inputs = self.buildInputs(tosca) nodeTemplates = map(functools.partial(self.buildNode, tosca=tosca), @@ -45,7 +45,7 @@ class EtsiVnfdInfoModel(BaseInfoModel): self.vdus = self._get_all_vdu(nodeTemplates, node_types) self.vls = self._get_all_vl(nodeTemplates, node_types) self.cps = self._get_all_cp(nodeTemplates, node_types) - self.vnf_exposed = self._get_all_endpoint_exposed(tosca.topology_template) + self.vnf_exposed = self._get_all_endpoint_exposed() self.graph = self.get_deploy_graph(tosca, NFV_VNF_RELATIONSHIPS) def _get_all_volume_storage(self, nodeTemplates, node_types): @@ -189,54 +189,52 @@ class EtsiVnfdInfoModel(BaseInfoModel): cp_vl[key] = value return cp_vl - def _get_all_endpoint_exposed(self, topo_tpl): - if 'substitution_mappings' in topo_tpl.tpl: - external_cps = self._get_external_cps(topo_tpl.tpl['substitution_mappings']) - forward_cps = self._get_forward_cps(topo_tpl.tpl['substitution_mappings']) + def _get_all_endpoint_exposed(self): + if self.vnf: + external_cps = self._get_external_cps(self.vnf.get('requirements', None)) + forward_cps = self._get_forward_cps(self.vnf.get('capabilities', None)) return {"external_cps": external_cps, "forward_cps": forward_cps} return {} - def _get_external_cps(self, subs_mappings): + def _get_external_cps(self, vnf_requirements): external_cps = [] - if 'requirements' in subs_mappings: - for key, value in subs_mappings['requirements'].items(): + if vnf_requirements: + for key, value in vnf_requirements.items(): if isinstance(value, list) and len(value) > 0: external_cps.append({"key_name": key, "cpd_id": value[0]}) else: external_cps.append({"key_name": key, "cpd_id": value}) return external_cps - def _get_forward_cps(self, subs_mappings): + def _get_forward_cps(self, vnf_capabilities): forward_cps = [] - if 'capabilities' in subs_mappings: - for key, value in subs_mappings['capabilities'].items(): + if vnf_capabilities: + for key, value in vnf_capabilities.items(): if isinstance(value, list) and len(value) > 0: forward_cps.append({"key_name": key, "cpd_id": value[0]}) else: forward_cps.append({"key_name": key, "cpd_id": value}) return forward_cps - def get_substitution_mappings(self, tosca): - node = {} - substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None) - if substitution_mappings: - node = substitution_mappings.get('properties', {}) - node['type'] = substitution_mappings['node_type'] - return node + # def get_substitution_mappings(self, tosca): + # node = {} + # substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None) + # if substitution_mappings: + # node = substitution_mappings.get('properties', {}) + # node['type'] = substitution_mappings['node_type'] + # return node - def build_vnf(self, tosca): - properties = self.get_substitution_mappings(tosca) - metadata = self.buildMetadata(tosca) + def _build_vnf(self, tosca): + vnf = self.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", "") - # if descriptor_id == "": - # raise CatalogException('descriptor_id is Null.') - else: - properties["descriptor_id"] = descriptor_id + properties["descriptor_id"] = descriptor_id if properties.get("descriptor_verison", "") == "": version = metadata.get("template_version", "") @@ -255,7 +253,5 @@ class EtsiVnfdInfoModel(BaseInfoModel): if template_name == "": template_name = metadata.get("template_name", "") properties["template_name"] = template_name - vnf = {} - vnf['properties'] = properties - vnf['metadata'] = metadata + return vnf |