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
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("")
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("")
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
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):