querystring = '?FORCE=True'
http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
ns['_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'
elif http_code == 204:
print 'Deleted'
else:
- raise ClientException("failed to delete ns {}: {}".format(name, resp))
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to delete ns {} - {}".format(name, msg))
def create(self, nsd_name, nsr_name, account, config=None,
ssh_keys=None, description='default description',
self._apiVersion, self._apiResource)
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
postfields_dict=ns)
- 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('unexpected response from server: '.format(
+ 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))
- else:
print resp['id']
+ else:
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException(msg)
except ClientException as exc:
message="failed to create ns: {} nsd: {}\nerror:\n{}".format(
nsr_name,
filter_string = ''
if filter:
filter_string = '&{}'.format(filter)
- http_code, resp = self._http.get2_cmd('{}?nsInstanceId={}'.format(self._apiBase, ns['_id'],
- filter_string) )
- resp = json.loads(resp)
+ http_code, resp = self._http.get2_cmd('{}?nsInstanceId={}'.format(
+ self._apiBase, ns['_id'],
+ filter_string) )
+ #print 'HTTP CODE: {}'.format(http_code)
#print 'RESP: {}'.format(resp)
if http_code == 200:
- return resp
+ if resp:
+ resp = json.loads(resp)
+ return resp
+ else:
+ raise ClientException('unexpected response from server')
else:
- raise ClientException('{}'.format(resp['detail']))
-
+ msg = ""
+ if resp:
+ try:
+ resp = json.loads(resp)
+ msg = resp['detail']
+ except ValueError:
+ msg = resp
+ raise ClientException(msg)
except ClientException as exc:
message="failed to get operation list of NS {}:\nerror:\n{}".format(
name,
self._apiBase = '{}{}{}'.format(self._apiName,
self._apiVersion, self._apiResource)
http_code, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, operationId))
- resp = json.loads(resp)
+ #print 'HTTP CODE: {}'.format(http_code)
#print 'RESP: {}'.format(resp)
if http_code == 200:
- return resp
+ if resp:
+ resp = json.loads(resp)
+ return resp
+ else:
+ raise ClientException('unexpected response from server')
else:
- raise ClientException("{}".format(resp['detail']))
+ msg = ""
+ if resp:
+ try:
+ resp = json.loads(resp)
+ msg = resp['detail']
+ except ValueError:
+ msg = resp
+ raise ClientException(msg)
except ClientException as exc:
message="failed to get status of operation {}:\nerror:\n{}".format(
operationId,
#print 'OP_NAME: {}'.format(op_name)
#print 'OP_DATA: {}'.format(json.dumps(op_data))
http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
- 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('unexpected response from server: '.format(
+ 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))
- else:
print resp['id']
+ else:
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException(msg)
except ClientException as exc:
message="failed to exec operation {}:\nerror:\n{}".format(
name,
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
+ #print 'HTTP CODE: {}'.format(http_code)
+ #print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
#resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
print 'Alarm created'
else:
- raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
- http_code, resp))
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException('error: code: {}, resp: {}'.format(
+ http_code, msg))
except ClientException as exc:
- message="failed to create alarm: alarm {}\nerror:\n{}".format(
+ message="failed to create alarm: alarm {}\n{}".format(
alarm,
exc.message)
raise ClientException(message)
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
postfields_dict=data)
+ #print 'HTTP CODE: {}'.format(http_code)
+ #print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
#resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
print 'Alarm deleted'
else:
- raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
- http_code, resp))
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException('error: code: {}, resp: {}'.format(
+ http_code, msg))
except ClientException as exc:
- message="failed to delete alarm: alarm {}\nerror:\n{}".format(
+ message="failed to delete alarm: alarm {}\n{}".format(
alarm,
exc.message)
raise ClientException(message)
try:
http_code, resp = self._http.post_cmd(endpoint='/test/message/metric_request',
postfields_dict=data)
+ #print 'HTTP CODE: {}'.format(http_code)
+ #print 'RESP: {}'.format(resp)
if http_code in (200, 201, 202, 204):
#resp = json.loads(resp)
- #print 'RESP: {}'.format(resp)
return 'Metric exported'
else:
- raise ClientException('unexpected response from server: code: {}, resp: {}'.format(
- http_code, resp))
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException('error: code: {}, resp: {}'.format(
+ http_code, msg))
except ClientException as exc:
- message="failed to export metric: metric {}\nerror:\n{}".format(
+ message="failed to export metric: metric {}\n{}".format(
metric,
exc.message)
raise ClientException(message)
headers = self._client._headers
headers['Accept'] = 'application/binary'
http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing))
- #print yaml.safe_dump(resp2)
- if resp:
- #store in a file
- return resp
- raise NotFound("nsd {} not found".format(name))
+ #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))
def get_descriptor(self, name, filename):
self.get_thing(name, 'nsd', filename)
querystring = '?FORCE=True'
http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
nsd['_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'
elif http_code == 204:
print 'Deleted'
else:
- raise ClientException("failed to delete nsd {}: {}".format(name, resp))
+ msg = ""
+ if resp:
+ try:
+ resp = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to delete nsd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
mime_type = magic.from_file(filename, mime=True)
self._apiVersion, self._apiResource)
endpoint = '{}{}'.format(self._apiBase,ow_string)
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
- if resp:
- resp = json.loads(resp)
- #print resp
- if not resp or 'id' not in resp:
- raise ClientException("failed to upload package")
- else:
+ #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 = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to create/update nsd - {}".format(name, msg))
def update(self, name, filename):
nsd = self.get(name)
for (key,val) in headers.items()]
self._http.set_http_header(http_header)
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
- if resp:
- resp = json.loads(resp)
- #print 'RESP: {}'.format(yaml.safe_dump(resp))
- if not resp or 'id' not in resp:
- raise ClientException("failed to upload package")
- else:
+ #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 = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to delete ns {} - {}".format(name, msg))
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))
- else:
+ 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 = ""
+ 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.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))
- else:
+ 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 = ""
+ 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)
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'
elif http_code == 204:
print 'Deleted'
- elif 'result' in resp:
+ 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
vim_account['name'] = name
vim_account = self.update_vim_account_dict(vim_account, vim_access)
- vim_config = {'hello': 'hello'}
+ vim_config = {}
if 'config' in vim_access and vim_access['config'] is not None:
vim_config = yaml.safe_load(vim_access['config'])
if sdn_controller:
postfields_dict=vim_account)
#print 'HTTP CODE: {}'.format(http_code)
#print 'RESP: {}'.format(resp)
- if resp:
- resp = json.loads(resp)
- if not resp or 'id' not in resp:
- raise ClientException('failed to create vim {}: {}'.format(
- name, resp))
- else:
+ 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 = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to create vim {} - {}".format(name, msg))
def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping):
vim = self.get(vim_name)
postfields_dict=vim_account)
#print 'HTTP CODE: {}'.format(http_code)
#print 'RESP: {}'.format(resp)
- if resp:
- resp = json.loads(resp)
- if not resp or 'id' not in resp:
- raise ClientException('failed to update vim: '.format(resp))
- else:
+ 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 = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to update vim {} - {}".format(vim_name, msg))
def update_vim_account_dict(self, vim_account, vim_access):
vim_account['vim_type'] = vim_access['vim-type']
querystring = '?FORCE=True'
http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
vim_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'
elif http_code == 204:
print 'Deleted'
else:
- raise ClientException("failed to delete vim {} - {}".format(vim_name, resp))
+ msg = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to delete vim {} - {}".format(vim_name, msg))
def list(self, filter=None):
"""Returns a list of VIM accounts
headers = self._client._headers
headers['Accept'] = 'application/binary'
http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing))
- #print yaml.safe_dump(resp2)
- if resp:
- #store in a file
- return resp
- raise NotFound("vnfd {} not found".format(name))
+ #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))
def get_descriptor(self, name, filename):
self.get_thing(name, 'vnfd', filename)
querystring = '?FORCE=True'
http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
vnfd['_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'
elif http_code == 204:
print 'Deleted'
else:
- raise ClientException("failed to delete vnfd {}: {}".format(name, resp))
+ msg = ""
+ 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):
mime_type = magic.from_file(filename, mime=True)
self._apiVersion, self._apiResource)
endpoint = '{}{}'.format(self._apiBase,ow_string)
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
- if resp:
- resp = json.loads(resp)
- #print resp
- if not resp or 'id' not in resp:
- raise ClientException("failed to upload package")
- else:
+ #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 = ""
+ if resp:
+ try:
+ msg = json.loads(resp)
+ except ValueError:
+ msg = resp
+ raise ClientException("failed to create/update vnfd - {}".format(name, msg))
def update(self, name, filename):
vnfd = self.get(name)