X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fns.py;h=8328dba40afdc7adf5192ae571795aefd45958e5;hb=f5b188e14053b2246be507a23d9eef5ff7e42123;hp=c84d090f05fa346caebcdf6498bc352b32edf041;hpb=29c6d8d0418e15012524b57a99adfbaeba59a712;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py index c84d090..8328dba 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, @@ -586,7 +613,7 @@ class Ns(object): http_code, resp = self._http.get2_cmd( "{}/{}".format(self._apiBase, uuid) ) - if not uuid: + else: # if not uuid http_code, resp = self._http.get2_cmd( "{}/{}/{}/{}".format(self._apiBase, uuid, project_name, ns_id) )