X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fns.py;h=d57b739b8f92c5d11e38f0581862f64012a70101;hb=349aa468cc1fce58d85f50a8bf650a94f73f938e;hp=02b9f089c882e5b56894156047dc1228b3bdf185;hpb=d708354a4c899a118bc68a93caf8b22aabd2e723;p=osm%2FLCM.git diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 02b9f08..d57b739 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -84,7 +84,12 @@ from osm_lcm.data_utils.vnfd import ( find_software_version, ) from osm_lcm.data_utils.list_utils import find_in_list -from osm_lcm.data_utils.vnfr import get_osm_params, get_vdur_index, get_kdur +from osm_lcm.data_utils.vnfr import ( + get_osm_params, + get_vdur_index, + get_kdur, + get_volumes_from_instantiation_params, +) from osm_lcm.data_utils.dict_utils import parse_yaml_strings from osm_lcm.data_utils.database.vim_account import VimAccountDB from n2vc.definitions import RelationEndpoint @@ -455,8 +460,7 @@ class NsLcm(LcmBase): def _get_vdu_additional_params(self, db_vnfr, vdu_id): vdur = next( - (vdur for vdur in db_vnfr.get("vdur") if vdu_id == vdur["vdu-id-ref"]), - {} + (vdur for vdur in db_vnfr.get("vdur") if vdu_id == vdur["vdu-id-ref"]), {} ) additional_params = vdur.get("additionalParams") return parse_yaml_strings(additional_params) @@ -547,21 +551,24 @@ class NsLcm(LcmBase): ) if not vdur: # Read the template saved in the db: - self.logger.debug(f"No vdur in the database. Using the vdur-template to scale") + self.logger.debug( + "No vdur in the database. Using the vdur-template to scale" + ) vdur_template = db_vnfr.get("vdur-template") if not vdur_template: raise LcmException( - "Error scaling OUT VNFR for {}. No vnfr or template exists".format( - vdu_id + "Error scaling OUT VNFR for {}. No vnfr or template exists".format( + vdu_id ) ) vdur = vdur_template[0] - #Delete a template from the database after using it - self.db.set_one("vnfrs", - {"_id": db_vnfr["_id"]}, - None, - pull={"vdur-template": {"_id": vdur['_id']}} - ) + # Delete a template from the database after using it + self.db.set_one( + "vnfrs", + {"_id": db_vnfr["_id"]}, + None, + pull={"vdur-template": {"_id": vdur["_id"]}}, + ) for count in range(vdu_count): vdur_copy = deepcopy(vdur) vdur_copy["status"] = "BUILD" @@ -595,7 +602,9 @@ class NsLcm(LcmBase): if vdu_delete: if len(db_vnfr["vdur"]) == 1: # The scale will move to 0 instances - self.logger.debug(f"Scaling to 0 !, creating the template with the last vdur") + self.logger.debug( + "Scaling to 0 !, creating the template with the last vdur" + ) template_vdur = [db_vnfr["vdur"][0]] for vdu_id, vdu_count in vdu_delete.items(): if mark_delete: @@ -1215,9 +1224,17 @@ class NsLcm(LcmBase): vdur["vim_info"] = {target_vim: {}} # instantiation parameters - # if vnf_params: - # vdu_instantiation_params = next((v for v in get_iterable(vnf_params, "vdu") if v["id"] == - # vdud["id"]), None) + if vnf_params: + vdu_instantiation_params = find_in_list( + get_iterable(vnf_params, "vdu"), + lambda i_vdu: i_vdu["id"] == vdud["id"], + ) + if vdu_instantiation_params: + # Parse the vdu_volumes from the instantiation params + vdu_volumes = get_volumes_from_instantiation_params( + vdu_instantiation_params, vdud + ) + vdur["additionalParams"]["OSM"]["vdu_volumes"] = vdu_volumes vdur_list.append(vdur) target_vnf["vdur"] = vdur_list target["vnf"].append(target_vnf) @@ -7222,16 +7239,18 @@ class NsLcm(LcmBase): try: # wait for any previous tasks in process step = "Waiting for previous operations to terminate" - await self.lcm_tasks.waitfor_related_HA('ns', 'nslcmops', nslcmop_id) + await self.lcm_tasks.waitfor_related_HA("ns", "nslcmops", nslcmop_id) self._write_ns_status( nsr_id=nsr_id, ns_state=None, current_operation="MIGRATING", - current_operation_id=nslcmop_id + current_operation_id=nslcmop_id, ) step = "Getting nslcmop from database" - self.logger.debug(step + " after having waited for previous tasks to be completed") + self.logger.debug( + step + " after having waited for previous tasks to be completed" + ) db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id}) migrate_params = db_nslcmop.get("operationParams") @@ -7251,7 +7270,9 @@ class NsLcm(LcmBase): exc = "Operation was cancelled" except Exception as e: exc = traceback.format_exc() - self.logger.critical("Exit Exception {} {}".format(type(e).__name__, e), exc_info=True) + self.logger.critical( + "Exit Exception {} {}".format(type(e).__name__, e), exc_info=True + ) finally: self._write_ns_status( nsr_id=nsr_id, @@ -7260,9 +7281,7 @@ class NsLcm(LcmBase): current_operation_id=None, ) if exc: - db_nslcmop_update[ - "detailed-status" - ] = "FAILED {}: {}".format(step, exc) + db_nslcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc) nslcmop_operation_state = "FAILED" else: nslcmop_operation_state = "COMPLETED"