X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fns.py;fp=osmclient%2Fsol005%2Fns.py;h=e8442f9df994b350490847dc0ff9e46fdfd0fbdb;hb=84fdd949fd48ea5da6939d711617c4b50b6cd2cf;hp=c84d090f05fa346caebcdf6498bc352b32edf041;hpb=93c410936ee7e7114a98d1fd109c30cf48a9af46;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index c84d090..e8442f9 100644 --- a/osmclient/sol005/ns.py +++ b/osmclient/sol005/ns.py @@ -40,7 +40,7 @@ class Ns(object): ) # NS '--wait' option - def _wait(self, id, wait_time, deleteFlag=False): + def _wait(self, id, wait_time, deleteFlag=False, entity="NS"): self._logger.debug("") # Endpoint to get operation status apiUrlStatus = "{}{}{}".format( @@ -50,7 +50,7 @@ class Ns(object): if isinstance(wait_time, bool): wait_time = WaitForStatus.TIMEOUT_NS_OPERATION WaitForStatus.wait_for_status( - "NS", + entity, str(id), wait_time, apiUrlStatus, @@ -431,6 +431,33 @@ class Ns(object): message = "failed to exec operation {}:\nerror:\n{}".format(name, str(exc)) raise ClientException(message) + def cancel_op(self, operation_id, cancel_mode, wait=False): + """Cancels an LCM operation""" + self._client.get_token() + self._apiResource = "/ns_lcm_op_occs" + self._apiBase = "{}{}{}".format( + self._apiName, self._apiVersion, self._apiResource + ) + endpoint = "{}/{}/cancel".format(self._apiBase, operation_id) + op_data = {"cancelMode": cancel_mode} + try: + http_code, resp = self._http.post_cmd( + endpoint=endpoint, postfields_dict=op_data + ) + if http_code == 202: + if wait: + self._wait(operation_id, wait, deleteFlag=True, entity="OPCANCEL") + else: + print("Cancellation in progress") + else: + msg = resp or "" + raise ClientException(msg) + except ClientException as exc: + message = "failed to exec operation {}:\nerror:\n{}".format( + operation_id, str(exc) + ) + raise ClientException(message) + def scale_vnf( self, ns_name,