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"), [])
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())
)
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"],