X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FLCM.git;a=blobdiff_plain;f=osm_lcm%2Fns.py;fp=osm_lcm%2Fns.py;h=f282b88c79febae259a6eaf7e27f026a60a9228b;hp=8238a242e4652882c4fe1c5ce86cbad961e565ad;hb=8f6b0e74d6a2595ec8d7176e31ac729afd54f75b;hpb=7f26b3f6740e12dd35d8024b14c3fe3a32ec5dbf diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 8238a24..f282b88 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -8743,6 +8743,10 @@ class NsLcm(LcmBase): db_nslcmop = None db_nslcmop_update = {} nslcmop_operation_state = None + old_db_update = {} + q_filter = {} + old_vdu_index = None + old_flavor_id = None db_nsr_update = {} target = {} exc = None @@ -8766,6 +8770,59 @@ class NsLcm(LcmBase): ) db_nslcmop = self.db.get_one("nslcmops", {"_id": nslcmop_id}) operationParams = db_nslcmop.get("operationParams") + # Update the VNFRS and NSRS with the requested flavour detail, So that ro tasks can function properly + db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) + db_flavor = db_nsr.get("flavor") + db_flavor_index = str(len(db_flavor)) + change_vnf_flavor_data = operationParams["changeVnfFlavorData"] + flavor_dict = change_vnf_flavor_data["additionalParams"] + count_index = flavor_dict["vduCountIndex"] + vdu_id_ref = flavor_dict["vduid"] + flavor_dict_update = { + "id": db_flavor_index, + "memory-mb": flavor_dict["virtualMemory"], + "name": f"{vdu_id_ref}-{count_index}-flv", + "storage-gb": flavor_dict["sizeOfStorage"], + "vcpu-count": flavor_dict["numVirtualCpu"], + } + db_flavor.append(flavor_dict_update) + db_update = {} + db_update["flavor"] = db_flavor + ns_q_filter = { + "_id": nsr_id, + } + self.db.set_one( + "nsrs", + q_filter=ns_q_filter, + update_dict=db_update, + fail_on_empty=True, + ) + db_vnfr = self.db.get_one( + "vnfrs", {"_id": change_vnf_flavor_data["vnfInstanceId"]} + ) + for vdu_index, vdur in enumerate(db_vnfr.get("vdur", ())): + if ( + vdur.get("count-index") == count_index + and vdur.get("vdu-id-ref") == vdu_id_ref + ): + old_flavor_id = vdur.get("ns-flavor-id", 0) + old_vdu_index = vdu_index + filter_text = { + "_id": change_vnf_flavor_data["vnfInstanceId"], + "vdur.count-index": count_index, + "vdur.vdu-id-ref": vdu_id_ref, + } + q_filter.update(filter_text) + db_update = {} + db_update[ + "vdur.{}.ns-flavor-id".format(vdu_index) + ] = db_flavor_index + self.db.set_one( + "vnfrs", + q_filter=q_filter, + update_dict=db_update, + fail_on_empty=True, + ) target = {} target.update(operationParams) desc = await self.RO.vertical_scale(nsr_id, target) @@ -8779,7 +8836,12 @@ class NsLcm(LcmBase): self.timeout.verticalscale, operation="verticalscale", ) - except (ROclient.ROClientException, DbException, LcmException) as e: + except ( + NgRoException, + ROclient.ROClientException, + DbException, + LcmException, + ) as e: self.logger.error("Exit Exception {}".format(e)) exc = e except asyncio.CancelledError: @@ -8800,6 +8862,9 @@ class NsLcm(LcmBase): if exc: db_nslcmop_update["detailed-status"] = "FAILED {}: {}".format(step, exc) nslcmop_operation_state = "FAILED" + old_db_update[ + "vdur.{}.ns-flavor-id".format(old_vdu_index) + ] = old_flavor_id else: nslcmop_operation_state = "COMPLETED" db_nslcmop_update["detailed-status"] = "Done" @@ -8812,6 +8877,16 @@ class NsLcm(LcmBase): operation_state=nslcmop_operation_state, other_update=db_nslcmop_update, ) + if old_vdu_index and old_db_update != {}: + self.logger.critical( + "Reverting Old Flavor -- : {}".format(old_db_update) + ) + self.db.set_one( + "vnfrs", + q_filter=q_filter, + update_dict=old_db_update, + fail_on_empty=True, + ) if nslcmop_operation_state: try: msg = {