Bug 1759 fix 29/11329/3
authorGulsum Atici <gulsum.atici@ulakhaberlesme.com.tr>
Wed, 10 Nov 2021 17:59:06 +0000 (20:59 +0300)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 16 Nov 2021 08:35:50 +0000 (09:35 +0100)
This fix makes ip-address (v4) assignment funtional in NSD.

Change-Id: I1731c22806f49e0365800e6ba197f85ff2fc8a2c
Signed-off-by: Gulsum Atici <gulsum.atici@ulakhaberlesme.com.tr>
osm_nbi/instance_topics.py

index fd2e6ab..6922112 100644 (file)
@@ -1608,6 +1608,68 @@ class NsLcmOpTopic(BaseTopic):
             # TODO check that this forcing is not incompatible with other forcing
         return ifaces_forcing_vim_network
 
+    def _update_vnfrs_from_nsd(self, nsr):
+        try:
+            nsr_id = nsr["_id"]
+            nsd = nsr["nsd"]
+
+            step = "Getting vnf_profiles from nsd"
+            vnf_profiles = nsd.get("df", [{}])[0].get("vnf-profile", ())
+            vld_fixed_ip_connection_point_data = {}
+
+            step = "Getting ip-address info from vnf_profile if it exists"
+            for vnfp in vnf_profiles:
+                # Checking ip-address info from nsd.vnf_profile and storing
+                for vlc in vnfp.get("virtual-link-connectivity", ()):
+                    for cpd in vlc.get("constituent-cpd-id", ()):
+                        if cpd.get("ip-address"):
+                            step = "Storing ip-address info"
+                            vld_fixed_ip_connection_point_data.update({vlc.get("virtual-link-profile-id") + '.' + cpd.get("constituent-base-element-id"): {
+                                "vnfd-connection-point-ref": cpd.get(
+                                    "constituent-cpd-id"),
+                                    "ip-address": cpd.get(
+                                    "ip-address")}})
+
+            # Inserting ip address to vnfr
+            if len(vld_fixed_ip_connection_point_data) > 0:
+                step = "Getting vnfrs"
+                vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": nsr_id})
+                for item in vld_fixed_ip_connection_point_data.keys():
+                    step = "Filtering vnfrs"
+                    vnfr = next(filter(lambda vnfr: vnfr["member-vnf-index-ref"] == item.split('.')[1], vnfrs), None)
+                    if vnfr:
+                        vnfr_update = {}
+                        for vdur_index, vdur in enumerate(vnfr["vdur"]):
+                            for iface_index, iface in enumerate(vdur["interfaces"]):
+                                step = "Looking for matched interface"
+                                if (
+                                        iface.get("external-connection-point-ref")
+                                        == vld_fixed_ip_connection_point_data[item].get("vnfd-connection-point-ref") and
+                                        iface.get("ns-vld-id") == item.split('.')[0]
+
+                                ):
+                                    vnfr_update_text = "vdur.{}.interfaces.{}".format(
+                                        vdur_index, iface_index
+                                    )
+                                    step = "Storing info in order to update vnfr"
+                                    vnfr_update[
+                                        vnfr_update_text + ".ip-address"
+                                        ] = increment_ip_mac(
+                                        vld_fixed_ip_connection_point_data[item].get("ip-address"),
+                                        vdur.get("count-index", 0), )
+                                    vnfr_update[vnfr_update_text + ".fixed-ip"] = True
+
+                        step = "updating vnfr at database"
+                        self.db.set_one("vnfrs", {"_id": vnfr["_id"]}, vnfr_update)
+        except (
+                ValidationError,
+                EngineException,
+                DbException,
+                MsgException,
+                FsException,
+        ) as e:
+            raise type(e)("{} while '{}'".format(e, step), http_code=e.http_code)
+
     def _update_vnfrs(self, session, rollback, nsr, indata):
         # get vnfr
         nsr_id = nsr["_id"]
@@ -1927,6 +1989,7 @@ class NsLcmOpTopic(BaseTopic):
             self._check_ns_operation(session, nsr, operation, indata)
 
             if operation == "instantiate":
+                self._update_vnfrs_from_nsd(nsr)
                 self._update_vnfrs(session, rollback, nsr, indata)
 
             nslcmop_desc = self._create_nslcmop(nsInstanceId, operation, indata)