X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fpdud.py;fp=osmclient%2Fsol005%2Fpdud.py;h=9b15ca7b20e00a0fea197d0a0f63b8989e5a31f6;hb=70d6f1843686f323ced68a253127fedde86a1c25;hp=42fe40d842fd6fb5413b7175d590e2a3c7b33acc;hpb=ac0e5fbbf8103186fe5a18f2420ddca87380552b;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/pdud.py b/osmclient/sol005/pdud.py index 42fe40d..9b15ca7 100644 --- a/osmclient/sol005/pdud.py +++ b/osmclient/sol005/pdud.py @@ -19,7 +19,7 @@ OSM pdud API handling """ from osmclient.common.exceptions import NotFound -from osmclient.common.exceptions import ClientException +from osmclient.common.exceptions import OsmHttpException from osmclient.common import utils import json import logging @@ -43,9 +43,9 @@ class Pdu(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): @@ -66,10 +66,10 @@ class Pdu(object): pdud = self.get(name) # It is redundant, since the previous one already gets the whole pdudInfo # The only difference is that a different primitive is exercised - resp = self._http.get_cmd('{}/{}'.format(self._apiBase, pdud['_id'])) + _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, pdud['_id'])) #print(yaml.safe_dump(resp)) if resp: - return resp + return json.loads(resp) raise NotFound("pdu {} not found".format(name)) def delete(self, name, force=False): @@ -93,7 +93,7 @@ class Pdu(object): msg = json.loads(resp) except ValueError: msg = resp - raise ClientException("failed to delete pdu {} - {}".format(name, msg)) + raise OsmHttpException("failed to delete pdu {} - {}".format(name, msg)) def create(self, pdu, update_endpoint=None): self._logger.debug("") @@ -111,21 +111,21 @@ class Pdu(object): http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=pdu) #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 pdu - {}".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 OsmHttpException('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 pdu - {}".format(msg)) def update(self, name, filename): self._logger.debug("")