fix/feat(relations): external connection point ref now works with multiple KDU
[osm/LCM.git] / osm_lcm / ns.py
index dc69449..443a09e 100644 (file)
@@ -2110,8 +2110,11 @@ class NsLcm(LcmBase):
             db_vnfd_list = db_nsr.get('vnfd-id')
             if db_vnfd_list:
                 for vnfd in db_vnfd_list:
+                    db_vnf_relations = None
                     db_vnfd = self.db.get_one("vnfds", {"_id": vnfd})
-                    db_vnf_relations = get_configuration(db_vnfd, db_vnfd["id"]).get("relation", [])
+                    db_vnf_configuration = get_configuration(db_vnfd, db_vnfd["id"])
+                    if db_vnf_configuration:
+                        db_vnf_relations = db_vnf_configuration.get("relation", [])
                     if db_vnf_relations:
                         for r in db_vnf_relations:
                             # check if this VCA is in the relation
@@ -2284,6 +2287,12 @@ class NsLcm(LcmBase):
 
             # Obtain management service info (if exists)
             vnfr_update_dict = {}
+            kdu_config = get_configuration(vnfd, kdud["name"])
+            if kdu_config:
+                target_ee_list = kdu_config.get("execution-environment-list", [])
+            else:
+                target_ee_list = []
+
             if services:
                 vnfr_update_dict["kdur.{}.services".format(kdu_index)] = services
                 mgmt_services = [service for service in kdud.get("service", []) if service.get("mgmt-service")]
@@ -2303,6 +2312,11 @@ class NsLcm(LcmBase):
                                 if deep_get(vnfd, ("mgmt-interface", "cp")) == service_external_cp:
                                     vnfr_update_dict["ip-address"] = ip
 
+                                if find_in_list(
+                                    target_ee_list,
+                                    lambda ee: ee.get("external-connection-point-ref", "") == service_external_cp
+                                ):
+                                    vnfr_update_dict["kdur.{}.ip-address".format(kdu_index)] = ip
                             break
                     else:
                         self.logger.warn("Mgmt service name: {} not found".format(mgmt_service["name"]))