X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fwim.py;h=0ba8ab4279bfc1effb8d6908a64d61abc4dcb92b;hb=refs%2Fchanges%2F38%2F8738%2F9;hp=b5a03b856b556326166f3c4fa3692da5a89b6b50;hpb=70d6f1843686f323ced68a253127fedde86a1c25;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/wim.py b/osmclient/sol005/wim.py index b5a03b8..0ba8ab4 100644 --- a/osmclient/sol005/wim.py +++ b/osmclient/sol005/wim.py @@ -21,7 +21,6 @@ OSM wim API handling from osmclient.common import utils from osmclient.common import wait as WaitForStatus from osmclient.common.exceptions import ClientException -from osmclient.common.exceptions import OsmHttpException from osmclient.common.exceptions import NotFound import yaml import json @@ -40,16 +39,18 @@ class Wim(object): self._apiVersion, self._apiResource) # WIM '--wait' option - def _wait(self, id, deleteFlag=False): + def _wait(self, id, wait_time, deleteFlag=False): self._logger.debug("") self._client.get_token() # Endpoint to get operation status apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/wim_accounts') # Wait for status for WIM instance creation/deletion + if isinstance(wait_time, bool): + wait_time = WaitForStatus.TIMEOUT_WIM_OPERATION WaitForStatus.wait_for_status( 'WIM', str(id), - WaitForStatus.TIMEOUT_WIM_OPERATION, + wait_time, apiUrlStatus, self._http.get2_cmd, deleteFlag=deleteFlag) @@ -93,11 +94,11 @@ class Wim(object): if resp: resp = json.loads(resp) if not resp or 'id' not in resp: - raise OsmHttpException('unexpected response from server - {}'.format( + raise ClientException('unexpected response from server - {}'.format( resp)) if wait: # Wait for status for WIM instance creation - self._wait(resp.get('id')) + self._wait(resp.get('id'), wait) print(resp['id']) #else: # msg = "" @@ -136,9 +137,9 @@ class Wim(object): # Use the previously obtained id instead. wait_id = wim_id_for_wait # Wait for status for WIM instance update - self._wait(wait_id) - else: - pass + self._wait(wait_id, wait) + # else: + # pass #else: # msg = "" # if resp: @@ -191,19 +192,19 @@ class Wim(object): resp = json.loads(resp) wait_id = resp.get('id') # Wait for status for WIM account deletion - self._wait(wait_id, deleteFlag=True) + self._wait(wait_id, wait, deleteFlag=True) else: print('Deletion in progress') elif http_code == 204: print('Deleted') else: - msg = "" - if resp: - try: - msg = json.loads(resp) - except ValueError: - msg = resp - raise OsmHttpException("failed to delete wim {} - {}".format(wim_name, msg)) + msg = resp or "" + # if resp: + # try: + # msg = json.loads(resp) + # except ValueError: + # msg = resp + raise ClientException("failed to delete wim {} - {}".format(wim_name, msg)) def list(self, filter=None): """Returns a list of VIM accounts @@ -230,12 +231,13 @@ class Wim(object): wim_id = name if not utils.validate_uuid4(name): wim_id = self.get_id(name) - _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,wim_id)) -# if not resp or '_id' not in resp: -# raise ClientException('failed to get wim info: '.format( -# resp)) -# else: - if resp: - return json.loads(resp) - raise NotFound("wim {} not found".format(name)) + try: + _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,wim_id)) + if resp: + resp = json.loads(resp) + if not resp or '_id' not in resp: + raise ClientException('failed to get wim info: '.format(resp)) + return resp + except NotFound: + raise NotFound("wim '{}' not found".format(name))