X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fsdncontroller.py;h=61299612c11d277971b7bef4be6bf4b6da9f2418;hb=119f79ff8103018c12d9f3f5083a97e5a34aecba;hp=29b8f6897b2281420c0aa4c32361bdf2a50e56ae;hpb=1b6c5b581dc29170b0bc81f909a41a322760de9a;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/sdncontroller.py b/osmclient/sol005/sdncontroller.py index 29b8f68..6129961 100644 --- a/osmclient/sol005/sdncontroller.py +++ b/osmclient/sol005/sdncontroller.py @@ -21,7 +21,6 @@ OSM SDN controller API handling from osmclient.common import utils from osmclient.common.exceptions import ClientException from osmclient.common.exceptions import NotFound -import yaml import json @@ -37,27 +36,45 @@ class SdnController(object): def create(self, name, sdn_controller): http_code, resp = self._http.post_cmd(endpoint=self._apiBase, postfields_dict=sdn_controller) - if resp: - resp = json.loads(resp) + #print 'HTTP CODE: {}'.format(http_code) #print 'RESP: {}'.format(resp) - if not resp or 'id' not in resp: - raise ClientException('failed to create SDN controller: '.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: - print resp['id'] + msg = "" + if resp: + try: + msg = json.loads(resp) + except ValueError: + msg = resp + raise ClientException("failed to create SDN controller {} - {}".format(name, msg)) def update(self, name, sdn_controller): sdnc = self.get(name) - http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']), + http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']), postfields_dict=sdn_controller) - if resp: - resp = json.loads(resp) + #print 'HTTP CODE: {}'.format(http_code) #print 'RESP: {}'.format(resp) - if not resp or 'id' not in resp: - raise ClientException('failed to update SDN controller: '.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: - print resp['id'] + msg = "" + if resp: + try: + msg = json.loads(resp) + except ValueError: + msg = resp + raise ClientException("failed to update SDN controller {} - {}".format(name, msg)) def delete(self, name, force=False): sdn_controller = self.get(name) @@ -66,17 +83,22 @@ class SdnController(object): querystring = '?FORCE=True' http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase, sdn_controller['_id'], querystring)) - if resp: - resp = json.loads(resp) + #print 'HTTP CODE: {}'.format(http_code) #print 'RESP: {}'.format(resp) if http_code == 202: - print 'Deletion in progress' + print('Deletion in progress') elif http_code == 204: - print 'Deleted' - elif 'result' in resp: - print 'Deleted' + print('Deleted') + elif resp and 'result' in resp: + print('Deleted') else: - raise ClientException("failed to delete vim {} - {}".format(name, resp)) + msg = "" + if resp: + try: + msg = json.loads(resp) + except ValueError: + msg = resp + raise ClientException("failed to delete SDN controller {} - {}".format(name, msg)) def list(self, filter=None): """Returns a list of SDN controllers