fix(query): new query to get VNFD using the session object. Bug 1390
[osm/NBI.git] / osm_nbi / instance_topics.py
index cabfc1c..7b3e9ad 100644 (file)
@@ -233,7 +233,7 @@ class NsrTopic(BaseTopic):
 
             step = "filling nsr from input data"
             nsr_id = str(uuid4())
-            nsr_descriptor = self._create_nsr_descriptor_from_nsd(nsd, ns_request, nsr_id)
+            nsr_descriptor = self._create_nsr_descriptor_from_nsd(nsd, ns_request, nsr_id, session)
 
             # Create VNFRs
             needed_vnfds = {}
@@ -306,7 +306,7 @@ class NsrTopic(BaseTopic):
 
         return ns_k8s_namespace
 
-    def _create_nsr_descriptor_from_nsd(self, nsd, ns_request, nsr_id):
+    def _create_nsr_descriptor_from_nsd(self, nsd, ns_request, nsr_id, session):
         now = time()
         additional_params, _ = self._format_additional_params(ns_request, descriptor=nsd)
 
@@ -367,10 +367,7 @@ class NsrTopic(BaseTopic):
                             "vnfd-id-ref": vnf_profile.get("vnfd-id")
                         })
 
-                vnfd = self.db.get_one("vnfds",
-                                       {"id": vnf_profile.get("vnfd-id")},
-                                       fail_on_empty=True,
-                                       fail_on_more=True)
+                vnfd = self._get_vnfd_from_db(vnf_profile.get("vnfd-id"), session)
 
                 for vdu in vnfd.get("vdu", ()):
                     flavor_data = {}
@@ -547,6 +544,21 @@ class NsrTopic(BaseTopic):
         vnfd_mgmt_cp = vnfd.get("mgmt-cp")
 
         for vdu in vnfd.get("vdu", ()):
+            vdu_mgmt_cp = []
+            try:
+                configs = vnfd.get("df")[0]["lcm-operations-configuration"]["operate-vnf-op-config"]["day1-2"]
+                vdu_config = utils.find_in_list(configs, lambda config: config["id"] == vdu["id"])
+            except Exception:
+                vdu_config = None
+            
+            if vdu_config:
+                external_connection_ee = utils.filter_in_list(
+                    vdu_config.get("execution-environment-list", []),
+                    lambda ee: "external-connection-point-ref" in ee
+                )
+                for ee in external_connection_ee:
+                    vdu_mgmt_cp.append(ee["external-connection-point-ref"])
+
             additional_params, vdu_params = self._format_additional_params(
                 ns_request, vnf_index, vdu_id=vdu["id"], descriptor=vnfd)
             vdur = {
@@ -598,7 +610,11 @@ class NsrTopic(BaseTopic):
 
                     if vnfd_mgmt_cp and vdu_iface.get("external-connection-point-ref") == vnfd_mgmt_cp:
                         vdu_iface["mgmt-vnf"] = True
-                        vdu_iface["mgmt-interface"] = True  # TODO change to mgmt-vdu
+                        vdu_iface["mgmt-interface"] = True
+
+                    for ecp in vdu_mgmt_cp:
+                        if vdu_iface.get("external-connection-point-ref") == ecp:
+                            vdu_iface["mgmt-interface"] = True
 
                     if iface.get("virtual-interface"):
                         vdu_iface.update(deepcopy(iface["virtual-interface"]))