X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=osmclient%2Fsol005%2Fnst.py;h=3b15e9699900f3f252574a0155abe95fe00b3adb;hb=bd39b09580560307a1ac23be4984783d1bea9238;hp=e75c8f51c19da3890ce218d4e5b3e90a0e25ca86;hpb=6bc001c642c74e6742d0a5dd5922738ae4c4fb0d;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/nst.py b/osmclient/sol005/nst.py index e75c8f5..3b15e96 100644 --- a/osmclient/sol005/nst.py +++ b/osmclient/sol005/nst.py @@ -45,10 +45,10 @@ class Nst(object): filter_string = '' if filter: filter_string = '?{}'.format(filter) - resp = self._http.get_cmd('{}{}'.format(self._apiBase, filter_string)) + _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string)) #print(yaml.safe_dump(resp)) if resp: - return resp + return json.loads(resp) return list() def get(self, name): @@ -69,32 +69,38 @@ class Nst(object): nst = self.get(name) # It is redundant, since the previous one already gets the whole nstinfo # The only difference is that a different primitive is exercised - resp = self._http.get_cmd('{}/{}'.format(self._apiBase, nst['_id'])) - #print(yaml.safe_dump(resp)) - if resp: - return resp - raise NotFound("nst {} not found".format(name)) + try: + _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nst['_id'])) + #print(yaml.safe_dump(resp)) + if resp: + return json.loads(resp) + except NotFound: + raise NotFound("nst '{}' not found".format(name)) + raise NotFound("nst '{}' not found".format(name)) def get_thing(self, name, thing, filename): self._logger.debug("") nst = self.get(name) headers = self._client._headers headers['Accept'] = 'application/binary' - http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nst['_id'], thing)) + try: + http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nst['_id'], thing)) + except NotFound: + raise NotFound("nst '{} 'not found".format(name)) #print('HTTP CODE: {}'.format(http_code)) #print('RESP: {}'.format(resp)) - if http_code in (200, 201, 202, 204): - if resp: - #store in a file - return resp - else: - msg = "" - if resp: - try: - msg = json.loads(resp) - except ValueError: - msg = resp - raise ClientException("failed to get {} from {} - {}".format(thing, name, msg)) + #if http_code in (200, 201, 202, 204): + if resp: + #store in a file + return json.loads(resp) + #else: + # msg = "" + # if resp: + # try: + # msg = json.loads(resp) + # except ValueError: + # msg = resp + # raise ClientException("failed to get {} from {} - {}".format(thing, name, msg)) def get_descriptor(self, name, filename): self._logger.debug("") @@ -123,12 +129,12 @@ class Nst(object): elif http_code == 204: print('Deleted') else: - msg = "" - if resp: - try: - resp = json.loads(resp) - except ValueError: - msg = resp + msg = resp or "" + # if resp: + # try: + # resp = json.loads(resp) + # except ValueError: + # msg = resp raise ClientException("failed to delete nst {} - {}".format(name, msg)) def create(self, filename, overwrite=None, update_endpoint=None): @@ -170,21 +176,20 @@ class Nst(object): http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename) #print('HTTP CODE: {}'.format(http_code)) #print('RESP: {}'.format(resp)) - if http_code in (200, 201, 202, 204): - if resp: - resp = json.loads(resp) - if not resp or 'id' not in resp: - raise ClientException('unexpected response from server - {}'.format( - resp)) - print(resp['id']) - else: - msg = "Error {}".format(http_code) - if resp: - try: - msg = "{} - {}".format(msg, json.loads(resp)) - except ValueError: - msg = "{} - {}".format(msg, resp) - raise ClientException("failed to create/update nst - {}".format(msg)) + # if http_code in (200, 201, 202, 204): + if resp: + resp = json.loads(resp) + if not resp or 'id' not in resp: + raise ClientException('unexpected response from server - {}'.format(resp)) + print(resp['id']) + # else: + # msg = "Error {}".format(http_code) + # if resp: + # try: + # msg = "{} - {}".format(msg, json.loads(resp)) + # except ValueError: + # msg = "{} - {}".format(msg, resp) + # raise ClientException("failed to create/update nst - {}".format(msg)) def update(self, name, filename): self._logger.debug("")