X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=osmclient%2Fsol005%2Fsdncontroller.py;h=2a4d4092e27d75b9cace83bd534abea680452ccd;hb=refs%2Fchanges%2F85%2F8385%2F14;hp=b2bbc37d9d5104ee73dc53c0bd2ca44491c9deae;hpb=ac0e5fbbf8103186fe5a18f2420ddca87380552b;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/sdncontroller.py b/osmclient/sol005/sdncontroller.py index b2bbc37..2a4d409 100644 --- a/osmclient/sol005/sdncontroller.py +++ b/osmclient/sol005/sdncontroller.py @@ -20,8 +20,8 @@ OSM SDN controller 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 NotFound +from osmclient.common.exceptions import OsmHttpException import json import logging @@ -67,26 +67,28 @@ class SdnController(object): def create(self, name, sdn_controller, wait=False): self._logger.debug("") self._client.get_token() - http_code, resp = self._http.post_cmd(endpoint=self._apiBase, postfields_dict=sdn_controller) - # 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)) - if wait: - # Wait for status for SDNC instance creation - self._wait(resp.get('id')) - print(resp['id']) - else: - msg = "" - if resp: - try: - msg = json.loads(resp) - except ValueError: - msg = resp - raise ClientException("failed to create SDN controller {} - {}".format(name, msg)) + http_code, resp = self._http.post_cmd(endpoint=self._apiBase, + postfields_dict=sdn_controller) + #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 OsmHttpException('unexpected response from server - {}'.format( + resp)) + if wait: + # Wait for status for SDNC instance creation + self._wait(resp.get('id')) + print(resp['id']) + #else: + # 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, wait=False): self._logger.debug("") @@ -97,23 +99,23 @@ class SdnController(object): postfields_dict=sdn_controller) # print('HTTP CODE: {}'.format(http_code)) # print('RESP: {}'.format(resp)) - if http_code in (200, 201, 202, 204): - if wait: - # In this case, 'resp' always returns None, so 'resp['id']' cannot be used. - # Use the previously obtained id instead. - wait_id = sdnc_id_for_wait - # Wait for status for VI instance update - self._wait(wait_id) - else: - pass + #if http_code in (200, 201, 202, 204): + if wait: + # In this case, 'resp' always returns None, so 'resp['id']' cannot be used. + # Use the previously obtained id instead. + wait_id = sdnc_id_for_wait + # Wait for status for VI instance update + self._wait(wait_id) else: - msg = "" - if resp: - try: - msg = json.loads(resp) - except ValueError: - msg = resp - raise ClientException("failed to update SDN controller {} - {}".format(name, msg)) + pass + #else: + # 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, wait=False): self._logger.debug("") @@ -144,7 +146,7 @@ class SdnController(object): msg = json.loads(resp) except ValueError: msg = resp - raise ClientException("failed to delete SDN controller {} - {}".format(name, msg)) + raise OsmHttpException("failed to delete SDN controller {} - {}".format(name, msg)) def list(self, filter=None): """Returns a list of SDN controllers @@ -154,10 +156,10 @@ class SdnController(object): filter_string = '' if filter: filter_string = '?{}'.format(filter) - resp = self._http.get_cmd('{}{}'.format(self._apiBase, filter_string)) - # print('RESP: {}'.format(resp)) + _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string)) + #print('RESP: {}'.format(resp)) if resp: - return resp + return json.loads(resp) return list() def get(self, name):