X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_nbi%2Fosm_vnfm%2Fvnf_instance_actions.py;h=b34d2030657f86a7aebbeb1753fb6e0a332e93a4;hb=592e293bdaa0a3784a46b898cdf68b59a7785527;hp=93c91c5569a041ae0c529b9a52a84eedaa921d41;hpb=59e9d88971c2f513c85ca7095a1e8493f9ebb513;p=osm%2FNBI.git diff --git a/osm_nbi/osm_vnfm/vnf_instance_actions.py b/osm_nbi/osm_vnfm/vnf_instance_actions.py index 93c91c5..b34d203 100644 --- a/osm_nbi/osm_vnfm/vnf_instance_actions.py +++ b/osm_nbi/osm_vnfm/vnf_instance_actions.py @@ -21,7 +21,6 @@ from .base_methods import BaseMethod class VnfLcmOp2NsLcmOp: - def __init__(self, db, fs, msg, auth): """ Constructor of Vnf lcm op to Ns lcm op @@ -66,7 +65,6 @@ class VnfLcmOp2NsLcmOp: class NewVnfLcmOp(BaseMethod): - def __init__(self, db, fs, msg, auth): """ Constructor of new Vnf Lcm Op @@ -85,7 +83,7 @@ class NewVnfLcmOp(BaseMethod): :return: id of nsd id """ nsr = self.nsrtopic.show(session, vnf_instance_id) - return nsr['nsd']['_id'] + return nsr["nsd"]["_id"] def __get_formatted_indata(self, session, indata): """ @@ -103,12 +101,12 @@ class NewVnfLcmOp(BaseMethod): "vimAccountId": indata["vimAccountId"], "nsr_id": indata["vnfInstanceId"], "lcmOperationType": indata["lcmOperationType"], - "nsInstanceId": indata["vnfInstanceId"] + "nsInstanceId": indata["vnfInstanceId"], } elif indata["lcmOperationType"] == "terminate": formatted_indata = { "lcmOperationType": indata["lcmOperationType"], - "nsInstanceId": indata["vnfInstanceId"] + "nsInstanceId": indata["vnfInstanceId"], } elif indata["lcmOperationType"] == "scale": formatted_indata = { @@ -119,9 +117,11 @@ class NewVnfLcmOp(BaseMethod): "scaleVnfType": indata["type"], "scaleByStepData": { "scaling-group-descriptor": indata["aspectId"], - "member-vnf-index": indata["additionalParams"]["member-vnf-index"] - } - } + "member-vnf-index": indata["additionalParams"][ + "member-vnf-index" + ], + }, + }, } elif indata["lcmOperationType"] == "action": formatted_indata = { @@ -129,10 +129,38 @@ class NewVnfLcmOp(BaseMethod): "nsInstanceId": indata["vnfInstanceId"], "member_vnf_index": indata["member_vnf_index"], "primitive": indata["primitive"], - "primitive_params": indata["primitive_params"] + "primitive_params": indata["primitive_params"], } return formatted_indata + def notify_operation(self, session, _id, lcm_operation, op_id): + """ + Formats the operation message params and sends to kafka + :param session: contains "username", "admin", "force", "public", "project_id", "set_project" + :param _id: vnf instance id + :param lcm_operation: lcm operation type of a VNF (instantiate, scale, terminate) + :param op_id: lcm operation id of a VNF + :return: None + """ + vnfInstanceId = _id + operation = lcm_operation + nslcmop_rec = self.nslcmoptopic.show(session, op_id) + operation_status = nslcmop_rec["operationState"] + vnfr = self.vnfrtopic.show(session, vnfInstanceId) + links = { + "self": "/osm/vnflcm/v1/vnf_lcm_op_occs/" + op_id, + "vnfInstance": "/osm/vnflcm/v1/vnf_instances/" + vnfInstanceId, + } + params = { + "vnfdId": vnfr["vnfd-ref"], + "vnfInstanceId": vnfInstanceId, + "operationState": operation_status, + "vnfLcmOpOccId": op_id, + "_links": links, + } + self.msg.write("vnf", operation, params) + return None + def action(self, rollback, session, indata=None, kwargs=None, headers=None): """ Creates an new lcm operation. @@ -149,11 +177,11 @@ class NewVnfLcmOp(BaseMethod): indata["vnfInstanceId"] = vnfr.get("nsr-id-ref") indata = self.__get_formatted_indata(session, indata) op_id, _ = self.nslcmoptopic.new(rollback, session, indata, kwargs, headers) + self.notify_operation(session, vnfInstanceId, lcm_operation, op_id) return op_id, _ class ListVnfLcmOp(BaseMethod): - def __init__(self, db, fs, msg, auth): """ Constructor call for listing vnf lcm operations @@ -175,14 +203,13 @@ class ListVnfLcmOp(BaseMethod): for record in records: ns_id = record.get("nsInstanceId") nsr = self.nsrtopic.show(session, ns_id) - vnfInstance_id = nsr['constituent-vnfr-ref'][0] + vnfInstance_id = nsr["constituent-vnfr-ref"][0] outdata = sol003_projection(record, vnfInstance_id) list.append(outdata) return list class ShowVnfLcmOp(BaseMethod): - def __init__(self, db, fs, msg, auth): """ Constructor call for showing vnf lcm operation @@ -202,7 +229,7 @@ class ShowVnfLcmOp(BaseMethod): record = self.nslcmoptopic.show(session, _id, api_req) ns_id = record.get("nsInstanceId") nsr = self.nsrtopic.show(session, ns_id) - vnfinstance_id = nsr['constituent-vnfr-ref'][0] + vnfinstance_id = nsr["constituent-vnfr-ref"][0] outdata = sol003_projection(record, vnfinstance_id) return outdata