"flavor": Ns._process_flavor_params,
"vdu": Ns._process_vdu_params,
"affinity-or-anti-affinity-group": Ns._process_affinity_group_params,
+ "shared-volumes": Ns._process_shared_volumes_params,
}
self.db_path_map = {
"net": "vld",
"flavor": "flavor",
"vdu": "vdur",
"affinity-or-anti-affinity-group": "affinity-or-anti-affinity-group",
+ "shared-volumes": "shared-volumes",
}
def init_db(self, target_version):
flavor_data_name = flavor_data.copy()
flavor_data_name["name"] = target_flavor["name"]
extra_dict["params"] = {"flavor_data": flavor_data_name}
-
return extra_dict
@staticmethod
if not virtual_storage_desc.get("vdu-storage-requirements"):
return False
for item in virtual_storage_desc.get("vdu-storage-requirements", {}):
- if item.get("key") == "keep-volume" and item.get("value") == "true":
+ if item.get("key") == "keep-volume" and item.get("value").lower() == "true":
return True
return False
+ @staticmethod
+ def is_shared_volume(
+ virtual_storage_desc: Dict[str, Any], vnfd_id: str
+ ) -> (str, bool):
+ """Function to decide if the volume type is multi attached or not .
+
+ Args:
+ virtual_storage_desc (Dict[str, Any]): virtual storage description dictionary
+ vnfd_id (str): vnfd id
+
+ Returns:
+ bool (True/False)
+ name (str) New name if it is a multiattach disk
+ """
+
+ if vdu_storage_requirements := virtual_storage_desc.get(
+ "vdu-storage-requirements", {}
+ ):
+ for item in vdu_storage_requirements:
+ if (
+ item.get("key") == "multiattach"
+ and item.get("value").lower() == "true"
+ ):
+ name = f"shared-{virtual_storage_desc['id']}-{vnfd_id}"
+ return name, True
+ return virtual_storage_desc["id"], False
+
@staticmethod
def _sort_vdu_interfaces(target_vdu: dict) -> None:
"""Sort the interfaces according to position number.
"size": root_disk["size-of-storage"],
"keep": Ns.is_volume_keeping_required(root_disk),
}
-
disk_list.append(persistent_root_disk[vsd["id"]])
break
persistent_root_disk: dict,
persistent_ordinary_disk: dict,
disk_list: list,
+ vnf_id: str = None,
) -> None:
"""Fill the disk list by adding persistent ordinary disks.
== "persistent-storage:persistent-storage"
and disk["id"] not in persistent_root_disk.keys()
):
+ name, multiattach = Ns.is_shared_volume(disk, vnf_id)
persistent_ordinary_disk[disk["id"]] = {
+ "name": name,
"size": disk["size-of-storage"],
"keep": Ns.is_volume_keeping_required(disk),
+ "multiattach": multiattach,
}
disk_list.append(persistent_ordinary_disk[disk["id"]])
image_text = ns_preffix + ":image." + target_vdu["ns-image-id"]
extra_dict = {"depends_on": [image_text]}
net_list = []
-
persistent_root_disk = {}
persistent_ordinary_disk = {}
vdu_instantiation_volumes_list = []
disk_list = []
vnfd_id = vnfr["vnfd-id"]
vnfd = db.get_one("vnfds", {"_id": vnfd_id})
-
# If the position info is provided for all the interfaces, it will be sorted
# according to position number ascendingly.
if all(
)
# Add the persistent non-root disks to disk_list
Ns._add_persistent_ordinary_disks_to_disk_list(
- target_vdu, persistent_root_disk, persistent_ordinary_disk, disk_list
+ target_vdu,
+ persistent_root_disk,
+ persistent_ordinary_disk,
+ disk_list,
+ vnfd["id"],
)
affinity_group_list = Ns._prepare_vdu_affinity_group_list(
"availability_zone_index": None, # TODO
"availability_zone_list": None, # TODO
}
+ return extra_dict
+ @staticmethod
+ def _process_shared_volumes_params(
+ target_shared_volume: Dict[str, Any],
+ indata: Dict[str, Any],
+ vim_info: Dict[str, Any],
+ target_record_id: str,
+ **kwargs: Dict[str, Any],
+ ) -> Dict[str, Any]:
+ extra_dict = {}
+ shared_volume_data = {
+ "size": target_shared_volume["size-of-storage"],
+ "name": target_shared_volume["id"],
+ "type": target_shared_volume["type-of-storage"],
+ }
+ extra_dict["params"] = shared_volume_data
return extra_dict
@staticmethod
extra_dict["params"] = {
"affinity_group_data": affinity_group_data,
}
-
return extra_dict
@staticmethod
vim_details = {}
vim_details_text = existing_vdu["vim_info"][target_id].get("vim_details", None)
+
if vim_details_text:
vim_details = yaml.safe_load(f"{vim_details_text}")
process_params = None
vdu2cloud_init = indata.get("cloud_init_content") or {}
ro_nsr_public_key = db_ro_nsr["public_key"]
-
# According to the type of item, the path, the target_list,
# the existing_list and the method to process params are set
db_path = self.db_path_map[item]
)
target_list = target_vnf.get(db_path, []) if target_vnf else []
existing_list = vnfr.get(db_path, [])
- elif item in ("image", "flavor", "affinity-or-anti-affinity-group"):
+ elif item in (
+ "image",
+ "flavor",
+ "affinity-or-anti-affinity-group",
+ "shared-volumes",
+ ):
db_record = "nsrs:{}:{}".format(nsr_id, db_path)
target_list = indata.get(item, [])
existing_list = db_nsr.get(item, [])
else:
raise NsException("Item not supported: {}", item)
-
# ensure all the target_list elements has an "id". If not assign the index as id
if target_list is None:
target_list = []
for target_index, tl in enumerate(target_list):
if tl and not tl.get("id"):
tl["id"] = str(target_index)
-
# step 1 items (networks,vdus,...) to be deleted/updated
for item_index, existing_item in enumerate(existing_list):
target_item = next(
(t for t in target_list if t["id"] == existing_item["id"]),
None,
)
-
for target_vim, existing_viminfo in existing_item.get(
"vim_info", {}
).items():
# step 2 items (networks,vdus,...) to be created
for target_item in target_list:
item_index = -1
-
for item_index, existing_item in enumerate(existing_list):
if existing_item["id"] == target_item["id"]:
break
}
)
self.logger.debug("calculate_diff_items kwargs={}".format(kwargs))
-
extra_dict = process_params(
target_item,
indata,
changes_list = []
# NS vld, image and flavor
- for item in ["net", "image", "flavor", "affinity-or-anti-affinity-group"]:
+ for item in [
+ "net",
+ "image",
+ "flavor",
+ "affinity-or-anti-affinity-group",
+ "shared-volumes",
+ ]:
self.logger.debug("process NS={} {}".format(nsr_id, item))
diff_items, task_index = self.calculate_diff_items(
indata=indata,