fix(configuration): juju related changes and configuration issues
[osm/NBI.git] / osm_nbi / instance_topics.py
index b3eca02..cabfc1c 100644 (file)
@@ -419,18 +419,13 @@ class NsrTopic(BaseTopic):
 
                     sw_image_id = vdu.get("sw-image-desc")
                     if sw_image_id:
-                        sw_image_desc = utils.find_in_list(vnfd.get("sw-image-desc", ()),
-                                                           lambda sw: sw["id"] == sw_image_id)
-                        image_data = {}
-                        if sw_image_desc.get("image"):
-                            image_data["image"] = sw_image_desc["image"]
-                        if sw_image_desc.get("checksum"):
-                            image_data["image_checksum"] = sw_image_desc["checksum"]["hash"]
-                    img = next((f for f in nsr_descriptor["image"] if
-                                all(f.get(k) == image_data[k] for k in image_data)), None)
-                    if not img:
-                        image_data["id"] = str(len(nsr_descriptor["image"]))
-                        nsr_descriptor["image"].append(image_data)
+                        image_data = self._get_image_data_from_vnfd(vnfd, sw_image_id)
+                        self._add_image_to_nsr(nsr_descriptor, image_data)
+
+                    # also add alternative images to the list of images
+                    for alt_image in vdu.get("alternative-sw-image-desc", ()):
+                        image_data = self._get_image_data_from_vnfd(vnfd, alt_image)
+                        self._add_image_to_nsr(nsr_descriptor, image_data)
 
             for vld in nsr_vld:
                 vld["vnfd-connection-point-ref"] = all_vld_connection_point_data.get(vld.get("id"), [])
@@ -439,6 +434,28 @@ class NsrTopic(BaseTopic):
 
         return nsr_descriptor
 
+    def _get_image_data_from_vnfd(self, vnfd, sw_image_id):
+        sw_image_desc = utils.find_in_list(vnfd.get("sw-image-desc", ()),
+                                           lambda sw: sw["id"] == sw_image_id)
+        image_data = {}
+        if sw_image_desc.get("image"):
+            image_data["image"] = sw_image_desc["image"]
+        if sw_image_desc.get("checksum"):
+            image_data["image_checksum"] = sw_image_desc["checksum"]["hash"]
+        if sw_image_desc.get("vim-type"):
+            image_data["vim-type"] = sw_image_desc["vim-type"]
+        return image_data
+
+    def _add_image_to_nsr(self, nsr_descriptor, image_data):
+        """
+        Adds image to nsr checking first it is not already added
+        """
+        img = next((f for f in nsr_descriptor["image"] if
+                    all(f.get(k) == image_data[k] for k in image_data)), None)
+        if not img:
+            image_data["id"] = str(len(nsr_descriptor["image"]))
+            nsr_descriptor["image"].append(image_data)
+
     def _create_vnfr_descriptor_from_vnfd(self, nsd, vnfd, vnfd_id, vnf_index, nsr_descriptor,
                                           ns_request, ns_k8s_namespace):
         vnfr_id = str(uuid4())
@@ -592,13 +609,25 @@ class NsrTopic(BaseTopic):
                         # TODO: Change for multiple df support
                         for df in get_iterable(nsd.get("df")):
                             for vnf_profile in get_iterable(df.get("vnf-profile")):
-                                for vlc in get_iterable(vnf_profile.get("virtual-link-connectivity")):
+                                for vlc_index, vlc in \
+                                        enumerate(get_iterable(vnf_profile.get("virtual-link-connectivity"))):
                                     for cpd in get_iterable(vlc.get("constituent-cpd-id")):
                                         if cpd.get("constituent-cpd-id") == iface_ext_cp:
                                             vdu_iface["ns-vld-id"] = vlc.get("virtual-link-profile-id")
+                                            # if iface type is SRIOV or PASSTHROUGH, set pci-interfaces flag to True
+                                            if vdu_iface.get("type") in ("SR-IOV", "PCI-PASSTHROUGH"):
+                                                nsr_descriptor["vld"][vlc_index]["pci-interfaces"] = True
                                             break
                     elif vdu_iface.get("internal-connection-point-ref"):
                         vdu_iface["vnf-vld-id"] = icp.get("int-virtual-link-desc")
+                        # TODO: store fixed IP address in the record (if it exists in the ICP)
+                        # if iface type is SRIOV or PASSTHROUGH, set pci-interfaces flag to True
+                        if vdu_iface.get("type") in ("SR-IOV", "PCI-PASSTHROUGH"):
+                            ivld_index = utils.find_index_in_list(vnfd.get("int-virtual-link-desc", ()),
+                                                                  lambda ivld:
+                                                                  ivld["id"] == icp.get("int-virtual-link-desc")
+                                                                  )
+                            vnfr_descriptor["vld"][ivld_index]["pci-interfaces"] = True
 
                     vdur["interfaces"].append(vdu_iface)
 
@@ -612,6 +641,19 @@ class NsrTopic(BaseTopic):
                 )
                 vdur["ns-image-id"] = nsr_sw_image_data["id"]
 
+            if vdu.get("alternative-sw-image-desc"):
+                alt_image_ids = []
+                for alt_image_id in vdu.get("alternative-sw-image-desc", ()):
+                    sw_image = utils.find_in_list(
+                        vnfd.get("sw-image-desc", ()),
+                        lambda image: image["id"] == alt_image_id)
+                    nsr_sw_image_data = utils.find_in_list(
+                        nsr_descriptor["image"],
+                        lambda nsr_image: (nsr_image.get("image") == sw_image.get("image"))
+                    )
+                    alt_image_ids.append(nsr_sw_image_data["id"])
+                vdur["alt-image-ids"] = alt_image_ids
+
             flavor_data_name = vdu["id"][:56] + "-flv"
             nsr_flavor_desc = utils.find_in_list(
                 nsr_descriptor["flavor"],