X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fvnfd.py;h=8bf3552b8013765d021f95ddc5333593053e1650;hb=51489a0d10ee934d3dc2278018112c8257aceb24;hp=ec54c95b609836e4e402c1e3ae16bbf7ab00b3d0;hpb=6bc001c642c74e6742d0a5dd5922738ae4c4fb0d;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py index ec54c95..8bf3552 100644 --- a/osmclient/sol005/vnfd.py +++ b/osmclient/sol005/vnfd.py @@ -47,9 +47,9 @@ class Vnfd(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)) if resp: - return resp + return json.loads(resp) return list() def get(self, name): @@ -70,11 +70,14 @@ class Vnfd(object): vnfd = self.get(name) # It is redundant, since the previous one already gets the whole vnfpkginfo # The only difference is that a different primitive is exercised - resp = self._http.get_cmd('{}/{}'.format(self._apiBase, vnfd['_id'])) - #print(yaml.safe_dump(resp)) - if resp: - return resp - raise NotFound("vnfd {} not found".format(name)) + try: + _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnfd['_id'])) + #print(yaml.safe_dump(resp)) + if resp: + return json.loads(resp) + except NotFound: + raise NotFound("vnfd '{}' not found".format(name)) + raise NotFound("vnfd '{}' not found".format(name)) def get_thing(self, name, thing, filename): self._logger.debug("") @@ -84,18 +87,18 @@ class Vnfd(object): http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing)) #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("") @@ -125,12 +128,12 @@ class Vnfd(object): elif http_code == 204: print('Deleted') else: - msg = "" - if resp: - try: - msg = json.loads(resp) - except ValueError: - msg = resp + msg = resp or "" + # if resp: + # try: + # msg = json.loads(resp) + # except ValueError: + # msg = resp raise ClientException("failed to delete vnfd {} - {}".format(name, msg)) def create(self, filename, overwrite=None, update_endpoint=None): @@ -177,19 +180,18 @@ class Vnfd(object): if resp: resp = json.loads(resp) if not resp or 'id' not in resp: - raise ClientException('unexpected response from server: '.format( - resp)) + raise ClientException('unexpected response from server: '.format(resp)) print(resp['id']) elif http_code == 204: print('Updated') - 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 vnfd - {}".format(msg)) + # 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 vnfd - {}".format(msg)) def update(self, name, filename): self._logger.debug("")