X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns.py;h=84a800e22b55e9db9a0e3a79c2b170edb81c4b41;hb=cb7269c6ed3caa4ad7807e01bf0067f373423702;hp=75bae1b1d57d97097dea89d220e26f5afb1314f1;hpb=364627c364a86a85696781766326dd690a362bc4;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index 75bae1b1..84a800e2 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -818,17 +818,23 @@ class Ns(object): db = kwargs.get("db") target_vdur = {} + for vnf in indata.get("vnf", []): + for vdur in vnf.get("vdur", []): + if vdur.get("ns-flavor-id") == target_flavor.get("id"): + target_vdur = vdur + + vim_flavor_id = ( + target_vdur.get("additionalParams", {}).get("OSM", {}).get("vim_flavor_id") + ) + if vim_flavor_id: # vim-flavor-id was passed so flavor won't be created + return {"find_params": {"vim_flavor_id": vim_flavor_id}} + flavor_data = { "disk": int(target_flavor["storage-gb"]), "ram": int(target_flavor["memory-mb"]), "vcpus": int(target_flavor["vcpu-count"]), } - for vnf in indata.get("vnf", []): - for vdur in vnf.get("vdur", []): - if vdur.get("ns-flavor-id") == target_flavor.get("id"): - target_vdur = vdur - if db and isinstance(indata.get("vnf"), list): vnfd_id = indata.get("vnf")[0].get("vnfd-id") vnfd = db.get_one("vnfds", {"_id": vnfd_id}) @@ -999,6 +1005,7 @@ class Ns(object): disk_list.append(persistent_root_disk[vsd["id"]]) return persistent_root_disk + return persistent_root_disk @staticmethod def find_persistent_volumes( @@ -1422,7 +1429,9 @@ class Ns(object): persistent_root_disk: dict, persistent_ordinary_disk: dict, disk_list: list, + extra_dict: dict, vnf_id: str = None, + nsr_id: str = None, ) -> None: """Fill the disk list by adding persistent ordinary disks. @@ -1448,6 +1457,10 @@ class Ns(object): "multiattach": multiattach, } disk_list.append(persistent_ordinary_disk[disk["id"]]) + if multiattach: # VDU creation has to wait for shared volumes + extra_dict["depends_on"].append( + f"nsrs:{nsr_id}:shared-volumes.{name}" + ) @staticmethod def _prepare_vdu_affinity_group_list( @@ -1515,12 +1528,12 @@ class Ns(object): vnf_preffix = "vnfrs:{}".format(vnfr_id) ns_preffix = "nsrs:{}".format(nsr_id) image_text = ns_preffix + ":image." + target_vdu["ns-image-id"] - extra_dict = {"depends_on": [image_text]} + flavor_text = ns_preffix + ":flavor." + target_vdu["ns-flavor-id"] + extra_dict = {"depends_on": [image_text, flavor_text]} net_list = [] persistent_root_disk = {} persistent_ordinary_disk = {} vdu_instantiation_volumes_list = [] - vdu_instantiation_flavor_id = None disk_list = [] vnfd_id = vnfr["vnfd-id"] vnfd = db.get_one("vnfds", {"_id": vnfd_id}) @@ -1559,17 +1572,6 @@ class Ns(object): vdu_instantiation_volumes_list = ( target_vdu.get("additionalParams").get("OSM", {}).get("vdu_volumes") ) - vdu_instantiation_flavor_id = ( - target_vdu.get("additionalParams").get("OSM", {}).get("vim_flavor_id") - ) - - # flavor id - if vdu_instantiation_flavor_id: - flavor_id = vdu_instantiation_flavor_id - else: - flavor_text = ns_preffix + ":flavor." + target_vdu["ns-flavor-id"] - flavor_id = "TASK-" + flavor_text - extra_dict["depends_on"].append(flavor_text) if vdu_instantiation_volumes_list: # Find the root volumes and add to the disk_list @@ -1598,7 +1600,9 @@ class Ns(object): persistent_root_disk, persistent_ordinary_disk, disk_list, + extra_dict, vnfd["id"], + nsr_id, ) affinity_group_list = Ns._prepare_vdu_affinity_group_list( @@ -1615,7 +1619,7 @@ class Ns(object): "description": target_vdu["vdu-name"], "start": True, "image_id": "TASK-" + image_text, - "flavor_id": flavor_id, + "flavor_id": "TASK-" + flavor_text, "affinity_group_list": affinity_group_list, "net_list": net_list, "cloud_config": cloud_config or None, @@ -1638,6 +1642,7 @@ class Ns(object): "size": target_shared_volume["size-of-storage"], "name": target_shared_volume["id"], "type": target_shared_volume["type-of-storage"], + "keep": Ns.is_volume_keeping_required(target_shared_volume), } extra_dict["params"] = shared_volume_data return extra_dict @@ -2121,7 +2126,6 @@ class Ns(object): "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( @@ -2141,7 +2145,7 @@ class Ns(object): # VNF vlds and vdus for vnfr_id, vnfr in db_vnfrs.items(): # vnfr_id need to be set as global variable for among others nested method _process_vdu_params - for item in ["net", "vdu"]: + for item in ["net", "vdu", "shared-volumes"]: self.logger.debug("process VNF={} {}".format(vnfr_id, item)) diff_items, task_index = self.calculate_diff_items( indata=indata, @@ -2370,7 +2374,7 @@ class Ns(object): for target_vnf in target_list: # Find this VNF in the list from DB, raise exception if vnfInstanceId is not found vnfr_id = target_vnf["vnfInstanceId"] - existing_vnf = db_vnfrs.get(vnfr_id) + existing_vnf = db_vnfrs.get(vnfr_id, {}) db_record = "vnfrs:{}:{}".format(vnfr_id, db_path) # vim_account_id = existing_vnf.get("vim-account-id", "") @@ -2390,16 +2394,17 @@ class Ns(object): # For single session VDU count-indes is 0 count_index = target_vdu.get("count-index", 0) item_index = 0 - existing_instance = None - for instance in existing_vnf.get("vdur", None): - if ( - instance["vdu-name"] == vdu_name - and instance["count-index"] == count_index - ): - existing_instance = instance - break - else: - item_index += 1 + existing_instance = {} + if existing_vnf: + for instance in existing_vnf.get("vdur", {}): + if ( + instance["vdu-name"] == vdu_name + and instance["count-index"] == count_index + ): + existing_instance = instance + break + else: + item_index += 1 target_record_id = "{}.{}".format(db_record, existing_instance["id"]) @@ -2888,7 +2893,9 @@ class Ns(object): extra_dict, ): self._assign_vim(target_vim) - target_record = "vnfrs:{}:vdur.{}".format(vnf_id, vdu_index) + target_record = "vnfrs:{}:vdur.{}.vim_info.{}".format( + vnf_id, vdu_index, target_vim + ) target_record_id = "vnfrs:{}:vdur.{}".format(vnf_id, vdu_id) deployment_info = { "action_id": action_id, @@ -2994,7 +3001,9 @@ class Ns(object): ): target_vim, vim_info = next(k_v for k_v in vdu["vim_info"].items()) self._assign_vim(target_vim) - target_record = "vnfrs:{}:vdur.{}".format(vnf["_id"], vdu_index) + target_record = "vnfrs:{}:vdur.{}.vim_info.{}".format( + vnf["_id"], vdu_index, target_vim + ) target_record_id = "vnfrs:{}:vdur.{}".format(vnf["_id"], vdu["id"]) deployment_info = { "action_id": action_id, @@ -3108,7 +3117,9 @@ class Ns(object): ): target_vim, vim_info = next(k_v for k_v in vdu["vim_info"].items()) self._assign_vim(target_vim) - target_record = "vnfrs:{}:vdur.{}".format(vnf["_id"], vdu_index) + target_record = "vnfrs:{}:vdur.{}.vim_info.{}".format( + vnf["_id"], vdu_index, target_vim + ) target_record_id = "vnfrs:{}:vdur.{}".format(vnf["_id"], vdu["id"]) deployment_info = { "action_id": action_id,