+ # 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,
+ )