X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_nbi%2Finstance_topics.py;h=8488a935520b37d84b9b9b8a19938af038c0936a;hb=refs%2Fchanges%2F44%2F14044%2F3;hp=60722676126f9b6781da9691ecbc2bbbd2f54fed;hpb=4606e4a16206757655e95deeed44457f821f9e4e;p=osm%2FNBI.git diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 6072267..8488a93 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -31,6 +31,7 @@ from osm_nbi.validation import ( nsi_instantiate, ns_migrate, ns_verticalscale, + nslcmop_cancel, ) from osm_nbi.base_topic import ( BaseTopic, @@ -1202,6 +1203,7 @@ class NsLcmOpTopic(BaseTopic): "terminate": ns_terminate, "migrate": ns_migrate, "verticalscale": ns_verticalscale, + "cancel": nslcmop_cancel, } def __init__(self, db, fs, msg, auth): @@ -2370,6 +2372,41 @@ class NsLcmOpTopic(BaseTopic): # except DbException as e: # raise EngineException("Cannot get ns_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND) + def cancel(self, rollback, session, indata=None, kwargs=None, headers=None): + validate_input(indata, self.operation_schema["cancel"]) + # Override descriptor with query string kwargs + self._update_input_with_kwargs(indata, kwargs, yaml_format=True) + nsLcmOpOccId = indata["nsLcmOpOccId"] + cancelMode = indata["cancelMode"] + # get nslcmop from nsLcmOpOccId + _filter = BaseTopic._get_project_filter(session) + _filter["_id"] = nsLcmOpOccId + nslcmop = self.db.get_one("nslcmops", _filter) + # Fail is this is not an ongoing nslcmop + if nslcmop.get("operationState") not in [ + "STARTING", + "PROCESSING", + "ROLLING_BACK", + ]: + raise EngineException( + "Operation is not in STARTING, PROCESSING or ROLLING_BACK state", + http_code=HTTPStatus.CONFLICT, + ) + nsInstanceId = nslcmop["nsInstanceId"] + update_dict = { + "isCancelPending": True, + "cancelMode": cancelMode, + } + self.db.set_one( + "nslcmops", q_filter=_filter, update_dict=update_dict, fail_on_empty=False + ) + data = { + "_id": nsLcmOpOccId, + "nsInstanceId": nsInstanceId, + "cancelMode": cancelMode, + } + self.msg.write("nslcmops", "cancel", data) + def delete(self, session, _id, dry_run=False, not_send_msg=None): raise EngineException( "Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR