Change-Id: I6fb4e88e16957725c595bd3dcabc6f74c04537ef
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
20 files changed:
-class NotFound(ClientException):
+class OsmHttpException(ClientException):
-class OsmHttpException(ClientException):
+
+class NotFound(OsmHttpException):
def cli():
try:
cli_osm()
def cli():
try:
cli_osm()
except pycurl.error as exc:
print(exc)
print('Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified')
except pycurl.error as exc:
print(exc)
print('Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified')
except ClientException as exc:
print("ERROR: {}".format(exc))
except ClientException as exc:
print("ERROR: {}".format(exc))
+ except (FileNotFoundError, PermissionError) as exc:
+ print("Cannot open file: {}".format(exc))
+ except yaml.YAMLError as exc:
+ print("Invalid YAML format: {}".format(exc))
+ exit(1)
# TODO capture other controlled exceptions here
# TODO remove the ClientException captures from all places, unless they do something different
# TODO capture other controlled exceptions here
# TODO remove the ClientException captures from all places, unless they do something different
_, resp = self._http_client.get2_cmd(endpoint="/version")
resp = json.loads(resp)
return "{} {}".format(resp.get("version"), resp.get("date"))
_, resp = self._http_client.get2_cmd(endpoint="/version")
resp = json.loads(resp)
return "{} {}".format(resp.get("version"), resp.get("date"))
import logging
import copy
from osmclient.common import http
import logging
import copy
from osmclient.common import http
-from osmclient.common.exceptions import OsmHttpException
+from osmclient.common.exceptions import OsmHttpException, NotFound
self.check_http_response(http_code, data)
# TODO 202 accepted should be returned somehow
if data.getvalue():
self.check_http_response(http_code, data)
# TODO 202 accepted should be returned somehow
if data.getvalue():
- self._logger.verbose("Response DATA: {}".format(json.loads(data.getvalue().decode())))
- return http_code, data.getvalue().decode()
+ data_text = data.getvalue().decode()
+ self._logger.verbose("Response DATA: {}".format(data_text))
+ return http_code, data_text
else:
return http_code, None
else:
return http_code, None
curl_cmd.close()
self.check_http_response(http_code, data)
if data.getvalue():
curl_cmd.close()
self.check_http_response(http_code, data)
if data.getvalue():
- self._logger.verbose("Response DATA: {}".format(json.loads(data.getvalue().decode())))
- return http_code, data.getvalue().decode()
+ data_text = data.getvalue().decode()
+ self._logger.verbose("Response DATA: {}".format(data_text))
+ return http_code, data_text
else:
return http_code, None
else:
return http_code, None
curl_cmd.close()
self.check_http_response(http_code, data)
if data.getvalue():
curl_cmd.close()
self.check_http_response(http_code, data)
if data.getvalue():
- self._logger.debug("Response DATA: {}".format(json.loads(data.getvalue().decode())))
- return http_code, data.getvalue().decode()
+ data_text = data.getvalue().decode()
+ self._logger.verbose("Response DATA: {}".format(data_text))
+ return http_code, data_text
return http_code, None
def check_http_response(self, http_code, data):
if http_code >= 300:
resp = ""
if data.getvalue():
return http_code, None
def check_http_response(self, http_code, data):
if http_code >= 300:
resp = ""
if data.getvalue():
- resp=": " + data.getvalue().decode()
+ data_text = data.getvalue().decode()
+ self._logger.verbose("Response {} DATA: {}".format(http_code, data_text))
+ resp = ": " + data_text
+ else:
+ self._logger.verbose("Response {}".format(http_code))
+ if http_code == 404:
+ raise NotFound("Error {}{}".format(http_code, resp))
raise OsmHttpException("Error {}{}".format(http_code, resp))
raise OsmHttpException("Error {}{}".format(http_code, resp))
from osmclient.common import utils
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
+from osmclient.common.exceptions import ClientException
import json
class K8scluster(object):
import json
class K8scluster(object):
#if http_code in (200, 201, 202, 204):
if resp:
resp = json.loads(resp)
#if http_code in (200, 201, 202, 204):
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
- resp))
+ raise ClientException('unexpected response from server - {}'.format(resp))
print(resp['id'])
#else:
# msg = ""
print(resp['id'])
#else:
# msg = ""
# print 'HTTP CODE: {}'.format(http_code)
# print 'RESP: {}'.format(resp)
#if http_code in (200, 201, 202, 204):
# print 'HTTP CODE: {}'.format(http_code)
# print 'RESP: {}'.format(resp)
#if http_code in (200, 201, 202, 204):
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete K8s cluster {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete K8s cluster {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns a list of K8s clusters
def list(self, filter=None):
"""Returns a list of K8s clusters
cluster_id = name
if not utils.validate_uuid4(name):
cluster_id = self.get_id(name)
cluster_id = name
if not utils.validate_uuid4(name):
cluster_id = self.get_id(name)
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,cluster_id))
-# if not resp or '_id' not in resp:
-# raise ClientException('failed to get K8s cluster info: '.format(resp))
-# else:
- if resp:
- return json.loads(resp)
- raise NotFound("K8s cluster {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,cluster_id))
+ if resp:
+ resp = json.loads(resp)
+ if not resp or '_id' not in resp:
+ raise ClientException('failed to get K8s cluster info: '.format(resp))
+ return resp
+ except NotFound:
+ raise NotFound("K8s cluster {} not found".format(name))
from osmclient.common import wait as WaitForStatus
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
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 yaml
import json
import logging
import yaml
import json
import logging
for ns in self.list():
if name == ns['name']:
return ns
for ns in self.list():
if name == ns['name']:
return ns
- raise NotFound("ns {} not found".format(name))
+ raise NotFound("ns '{}' not found".format(name))
def get_individual(self, name):
self._logger.debug("")
def get_individual(self, name):
self._logger.debug("")
if name == ns['name']:
ns_id = ns['_id']
break
if name == ns['name']:
ns_id = ns['_id']
break
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, ns_id))
- #resp = self._http.get_cmd('{}/{}/nsd_content'.format(self._apiBase, ns_id))
- #print(yaml.safe_dump(resp))
- if resp:
- return json.loads(resp)
- raise NotFound("ns {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, ns_id))
+ #resp = self._http.get_cmd('{}/{}/nsd_content'.format(self._apiBase, ns_id))
+ #print(yaml.safe_dump(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("ns '{}' not found".format(name))
+ raise NotFound("ns '{}' not found".format(name))
def delete(self, name, force=False, wait=False):
self._logger.debug("")
def delete(self, name, force=False, wait=False):
self._logger.debug("")
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete ns {} - {}".format(name, msg))
+ msg = resp or ""
+ # 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',
def create(self, nsd_name, nsr_name, account, config=None,
ssh_keys=None, description='default description',
self._logger.debug("")
if vim_account_id.get(vim_account):
return vim_account_id[vim_account]
self._logger.debug("")
if vim_account_id.get(vim_account):
return vim_account_id[vim_account]
vim = self._client.vim.get(vim_account)
if vim is None:
raise NotFound("cannot find vim account '{}'".format(vim_account))
vim = self._client.vim.get(vim_account)
if vim is None:
raise NotFound("cannot find vim account '{}'".format(vim_account))
def get_wim_account_id(wim_account):
self._logger.debug("")
def get_wim_account_id(wim_account):
self._logger.debug("")
+ # wim_account can be False (boolean) to indicate not use wim account
if not isinstance(wim_account, str):
return wim_account
if wim_account_id.get(wim_account):
return wim_account_id[wim_account]
if not isinstance(wim_account, str):
return wim_account
if wim_account_id.get(wim_account):
return wim_account_id[wim_account]
wim = self._client.wim.get(wim_account)
if wim is None:
raise NotFound("cannot find wim account '{}'".format(wim_account))
wim = self._client.wim.get(wim_account)
if wim is None:
raise NotFound("cannot find wim account '{}'".format(wim_account))
if wait:
# Wait for status for NS instance creation
self._wait(resp.get('nslcmop_id'))
if wait:
# Wait for status for NS instance creation
self._wait(resp.get('nslcmop_id'))
return resp['id']
#else:
# msg = ""
return resp['id']
#else:
# msg = ""
nsr_name,
nsd_name,
str(exc))
nsr_name,
nsd_name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def list_op(self, name, filter=None):
"""Returns the list of operations of a NS
def list_op(self, name, filter=None):
"""Returns the list of operations of a NS
filter_string) )
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
filter_string) )
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- #if http_code == 200:
- if resp:
- resp = json.loads(resp)
- return resp
+ if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
+ else:
+ raise ClientException('unexpected response from server')
- raise ClientException('unexpected response from server')
- #else:
- # msg = ""
# if resp:
# try:
# resp = json.loads(resp)
# msg = resp['detail']
# except ValueError:
# msg = resp
# if resp:
# try:
# resp = json.loads(resp)
# msg = resp['detail']
# except ValueError:
# msg = resp
- # raise ClientException(msg)
+ raise ClientException(msg)
except ClientException as exc:
message="failed to get operation list of NS {}:\nerror:\n{}".format(
name,
str(exc))
except ClientException as exc:
message="failed to get operation list of NS {}:\nerror:\n{}".format(
name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def get_op(self, operationId):
"""Returns the status of an operation
def get_op(self, operationId):
"""Returns the status of an operation
http_code, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, operationId))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
http_code, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, operationId))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- #if http_code == 200:
- if resp:
- resp = json.loads(resp)
- return resp
+ if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
+ else:
+ raise ClientException('unexpected response from server')
- raise ClientException('unexpected response from server')
- #else:
- # msg = ""
# if resp:
# try:
# resp = json.loads(resp)
# msg = resp['detail']
# except ValueError:
# msg = resp
# if resp:
# try:
# resp = json.loads(resp)
# msg = resp['detail']
# except ValueError:
# msg = resp
- # raise ClientException(msg)
+ raise ClientException(msg)
except ClientException as exc:
message="failed to get status of operation {}:\nerror:\n{}".format(
operationId,
str(exc))
except ClientException as exc:
message="failed to get status of operation {}:\nerror:\n{}".format(
operationId,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def exec_op(self, name, op_name, op_data=None, wait=False, ):
"""Executes an operation on a NS
def exec_op(self, name, op_name, op_data=None, wait=False, ):
"""Executes an operation on a NS
message="failed to exec operation {}:\nerror:\n{}".format(
name,
str(exc))
message="failed to exec operation {}:\nerror:\n{}".format(
name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def scale_vnf(self, ns_name, vnf_name, scaling_group, scale_in, scale_out, wait=False):
"""Scales a VNF by adding/removing VDUs
def scale_vnf(self, ns_name, vnf_name, scaling_group, scale_in, scale_out, wait=False):
"""Scales a VNF by adding/removing VDUs
data = {}
data["create_alarm_request"] = {}
data["create_alarm_request"]["alarm_create_request"] = alarm
data = {}
data["create_alarm_request"] = {}
data["create_alarm_request"]["alarm_create_request"] = alarm
- #try:
- http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
- postfields_dict=data)
+ 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))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- #if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- print('Alarm created')
+ # if http_code in (200, 201, 202, 204):
+ # resp = json.loads(resp)
+ print('Alarm created')
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
- #except ClientException as exc:
- # message="failed to create alarm: alarm {}\n{}".format(
- # alarm,
- # str(exc))
- # raise ClientException(message)
+ except ClientException as exc:
+ message="failed to create alarm: alarm {}\n{}".format(
+ alarm,
+ str(exc))
+ raise ClientException(message)
def delete_alarm(self, name):
self._logger.debug("")
def delete_alarm(self, name):
self._logger.debug("")
data["delete_alarm_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"]["alarm_uuid"] = name
data["delete_alarm_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"] = {}
data["delete_alarm_request"]["alarm_delete_request"]["alarm_uuid"] = name
- #try:
- http_code, resp = self._http.post_cmd(endpoint='/test/message/alarm_request',
- postfields_dict=data)
+ 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))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- #if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- print('Alarm deleted')
+ # if http_code in (200, 201, 202, 204):
+ # resp = json.loads(resp)
+ print('Alarm deleted')
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
- #except ClientException as exc:
- # message="failed to delete alarm: alarm {}\n{}".format(
- # name,
- # str(exc))
- # raise ClientException(message)
+ except ClientException as exc:
+ message="failed to delete alarm: alarm {}\n{}".format(
+ name,
+ str(exc))
+ raise ClientException(message)
def export_metric(self, metric):
self._logger.debug("")
self._client.get_token()
data = {}
data["read_metric_data_request"] = metric
def export_metric(self, metric):
self._logger.debug("")
self._client.get_token()
data = {}
data["read_metric_data_request"] = metric
- #try:
- http_code, resp = self._http.post_cmd(endpoint='/test/message/metric_request',
- postfields_dict=data)
+ 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))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- #if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- return 'Metric exported'
+ # if http_code in (200, 201, 202, 204):
+ # resp = json.loads(resp)
+ return 'Metric exported'
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
# msg = resp
# raise ClientException('error: code: {}, resp: {}'.format(
# http_code, msg))
- #except ClientException as exc:
- # message="failed to export metric: metric {}\n{}".format(
- # metric,
- # str(exc))
- # raise ClientException(message)
+ except ClientException as exc:
+ message="failed to export metric: metric {}\n{}".format(
+ metric,
+ str(exc))
+ raise ClientException(message)
def get_field(self, ns_name, field):
self._logger.debug("")
def get_field(self, ns_name, field):
self._logger.debug("")
from osmclient.common.exceptions import NotFound
from osmclient.common.exceptions import ClientException
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 magic
from osmclient.common import utils
import json
import magic
def get_individual(self, name):
self._logger.debug("")
# Call to get_token not required, because will be implicitly called by get.
def get_individual(self, name):
self._logger.debug("")
# Call to get_token not required, because will be implicitly called by get.
- nsd = self.get(name)
- # It is redundant, since the previous one already gets the whole nsdinfo
- # The only difference is that a different primitive is exercised
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
- #print(yaml.safe_dump(resp))
- if resp:
- return json.loads(resp)
- raise NotFound("nsd {} not found".format(name))
+ try:
+ nsd = self.get(name)
+ # It is redundant, since the previous one already gets the whole nsdinfo
+ # The only difference is that a different primitive is exercised
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
+ #print(yaml.safe_dump(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("nsd '{}' not found".format(name))
+ raise NotFound("nsd '{}' not found".format(name))
def get_thing(self, name, thing, filename):
self._logger.debug("")
def get_thing(self, name, thing, filename):
self._logger.debug("")
if resp:
#store in a file
return json.loads(resp)
if resp:
#store in a file
return json.loads(resp)
+ else:
+ msg = resp or ""
# if resp:
# try:
# msg = json.loads(resp)
# except ValueError:
# msg = resp
# if resp:
# try:
# msg = json.loads(resp)
# except ValueError:
# msg = resp
- # raise ClientException("failed to get {} from {} - {}".format(thing, name, msg))
+ raise ClientException("failed to get {} from {} - {}".format(thing, name, msg))
def get_descriptor(self, name, filename):
self._logger.debug("")
def get_descriptor(self, name, filename):
self._logger.debug("")
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete nsd {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = 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):
self._logger.debug("")
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(resp))
+ raise ClientException('unexpected response from server - {}'.format(resp))
print(resp['id'])
elif http_code == 204:
print('Updated')
print(resp['id'])
elif http_code == 204:
print('Updated')
from osmclient.common import wait as WaitForStatus
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
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 yaml
import json
import logging
import yaml
import json
import logging
if name == nsi['name']:
nsi_id = nsi['_id']
break
if name == nsi['name']:
nsi_id = nsi['_id']
break
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsi_id))
- #resp = self._http.get_cmd('{}/{}/nsd_content'.format(self._apiBase, nsi_id))
- #print(yaml.safe_dump(resp))
- if resp:
- return json.loads(resp)
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsi_id))
+ #resp = self._http.get_cmd('{}/{}/nsd_content'.format(self._apiBase, nsi_id))
+ #print(yaml.safe_dump(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("nsi '{}' not found".format(name))
raise NotFound("nsi {} not found".format(name))
def delete(self, name, force=False, wait=False):
raise NotFound("nsi {} not found".format(name))
def delete(self, name, force=False, wait=False):
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete nsi {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete nsi {} - {}".format(name, msg))
def create(self, nst_name, nsi_name, account, config=None,
ssh_keys=None, description='default description',
def create(self, nst_name, nsi_name, account, config=None,
ssh_keys=None, description='default description',
nsi_name,
nst_name,
str(exc))
nsi_name,
nst_name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def list_op(self, name, filter=None):
"""Returns the list of operations of a NSI
def list_op(self, name, filter=None):
"""Returns the list of operations of a NSI
message="failed to get operation list of NSI {}:\nerror:\n{}".format(
name,
str(exc))
message="failed to get operation list of NSI {}:\nerror:\n{}".format(
name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def get_op(self, operationId):
"""Returns the status of an operation
def get_op(self, operationId):
"""Returns the status of an operation
message="failed to get status of operation {}:\nerror:\n{}".format(
operationId,
str(exc))
message="failed to get status of operation {}:\nerror:\n{}".format(
operationId,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
def exec_op(self, name, op_name, op_data=None):
"""Executes an operation on a NSI
def exec_op(self, name, op_name, op_data=None):
"""Executes an operation on a NSI
message="failed to exec operation {}:\nerror:\n{}".format(
name,
str(exc))
message="failed to exec operation {}:\nerror:\n{}".format(
name,
str(exc))
- raise OsmHttpException(message)
+ raise ClientException(message)
from osmclient.common.exceptions import NotFound
from osmclient.common.exceptions import ClientException
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 magic
from osmclient.common import utils
import json
import magic
nst = self.get(name)
# It is redundant, since the previous one already gets the whole nstinfo
# The only difference is that a different primitive is exercised
nst = self.get(name)
# It is redundant, since the previous one already gets the whole nstinfo
# The only difference is that a different primitive is exercised
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nst['_id']))
- #print(yaml.safe_dump(resp))
- if resp:
- return json.loads(resp)
- raise NotFound("nst {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nst['_id']))
+ #print(yaml.safe_dump(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("nst '{}' not found".format(name))
+ raise NotFound("nst '{}' not found".format(name))
def get_thing(self, name, thing, filename):
self._logger.debug("")
nst = self.get(name)
headers = self._client._headers
headers['Accept'] = 'application/binary'
def get_thing(self, name, thing, filename):
self._logger.debug("")
nst = self.get(name)
headers = self._client._headers
headers['Accept'] = 'application/binary'
- http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nst['_id'], thing))
+ try:
+ http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nst['_id'], thing))
+ except NotFound:
+ raise NotFound("nst '{} 'not found".format(name))
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
#if http_code in (200, 201, 202, 204):
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
#if http_code in (200, 201, 202, 204):
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete nst {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # resp = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete nst {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(resp))
+ raise ClientException('unexpected response from server - {}'.format(resp))
print(resp['id'])
# else:
# msg = "Error {}".format(http_code)
print(resp['id'])
# else:
# msg = "Error {}".format(http_code)
#from os import stat
#from os.path import basename
#from os import stat
#from os.path import basename
-from osmclient.common.exceptions import OsmHttpException
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
# else:
resp))
print(resp['id'])
# else:
"""
from osmclient.common.exceptions import NotFound
"""
from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
+from osmclient.common.exceptions import ClientException
from osmclient.common import utils
import json
import logging
from osmclient.common import utils
import json
import logging
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
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.get2_cmd('{}/{}'.format(self._apiBase, pdud['_id']))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, pdud['_id']))
+ except NotFound:
+ raise NotFound("pdu '{}' not found".format(name))
#print(yaml.safe_dump(resp))
if resp:
return json.loads(resp)
#print(yaml.safe_dump(resp))
if resp:
return json.loads(resp)
- raise NotFound("pdu {} not found".format(name))
+ raise NotFound("pdu '{}' not found".format(name))
def delete(self, name, force=False):
self._logger.debug("")
def delete(self, name, force=False):
self._logger.debug("")
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete pdu {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete pdu {} - {}".format(name, msg))
def create(self, pdu, update_endpoint=None):
self._logger.debug("")
def create(self, pdu, update_endpoint=None):
self._logger.debug("")
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server: '.format(
+ raise ClientException('unexpected response from server: '.format(
resp))
print(resp['id'])
#else:
resp))
print(resp['id'])
#else:
"""
from osmclient.common import utils
"""
from osmclient.common import utils
+from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
import json
import logging
import json
import logging
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
#else:
resp))
print(resp['id'])
#else:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
elif http_code == 204:
resp))
print(resp['id'])
elif http_code == 204:
elif resp and 'result' in resp:
print('Deleted')
else:
elif resp and 'result' in resp:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete project {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete project {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns the list of OSM projects
def list(self, filter=None):
"""Returns the list of OSM projects
"""
from osmclient.common import utils
"""
from osmclient.common import utils
-from osmclient.common.exceptions import OsmHttpException
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
import json
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
import json
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
- resp))
+ raise ClientException('unexpected response from server - {}'.format(
+ resp))
print(resp['id'])
#else:
# msg = ""
print(resp['id'])
#else:
# msg = ""
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
raise ClientException("failed to delete repo {} - {}".format(name, msg))
def list(self, filter=None):
raise ClientException("failed to delete repo {} - {}".format(name, msg))
def list(self, filter=None):
repo_id = name
if not utils.validate_uuid4(name):
repo_id = self.get_id(name)
repo_id = name
if not utils.validate_uuid4(name):
repo_id = self.get_id(name)
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,repo_id))
-# if not resp or '_id' not in resp:
-# raise ClientException('failed to get repo info: '.format(resp))
-# else:
- if resp:
- return json.loads(resp)
- raise NotFound("Repo {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,repo_id))
+ if resp:
+ resp = json.loads(resp)
+ if not resp or '_id' not in resp:
+ raise ClientException('failed to get repo info: '.format(resp))
+ return resp
+ except NotFound:
+ raise NotFound("Repo {} not found".format(name))
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
import json
import yaml
import logging
import json
import yaml
import logging
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('Unexpected response from server - {}'.format(
- resp))
+ raise ClientException('Unexpected response from server - {}'.format(
+ resp))
print(resp['id'])
#else:
# msg = ""
print(resp['id'])
#else:
# msg = ""
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('Unexpected response from server - {}'.format(
- resp))
+ raise ClientException('Unexpected response from server - {}'.format(
+ resp))
print(resp['id'])
elif http_code == 204:
print("Updated")
print(resp['id'])
elif http_code == 204:
print("Updated")
elif resp and 'result' in resp:
print('Deleted')
else:
elif resp and 'result' in resp:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("Failed to delete role {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("Failed to delete role {} - {}".format(name, msg))
def list(self, filter=None):
"""
def list(self, filter=None):
"""
from osmclient.common import utils
from osmclient.common import wait as WaitForStatus
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 NotFound
-from osmclient.common.exceptions import OsmHttpException
import json
import logging
import json
import logging
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
if wait:
# Wait for status for SDNC instance creation
resp))
if wait:
# Wait for status for SDNC instance creation
wait_id = sdnc_id_for_wait
# Wait for status for VI instance update
self._wait(wait_id)
wait_id = sdnc_id_for_wait
# Wait for status for VI instance update
self._wait(wait_id)
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
elif resp and 'result' in resp:
print('Deleted')
else:
elif resp and 'result' in resp:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete SDN controller {} - {}".format(name, msg))
+ msg = resp or ""
+ # 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
def list(self, filter=None):
"""Returns a list of SDN controllers
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
import json
import logging
import json
import logging
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
- resp))
+ raise ClientException('unexpected response from server - {}'.format(
+ resp))
print(resp['id'])
#else:
# msg = ""
print(resp['id'])
#else:
# msg = ""
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
elif http_code == 204:
resp))
print(resp['id'])
elif http_code == 204:
elif resp and 'result' in resp:
print('Deleted')
else:
elif resp and 'result' in resp:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete user {} - {}".format(name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete user {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns the list of OSM users
def list(self, filter=None):
"""Returns the list of OSM users
from osmclient.common import wait as WaitForStatus
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
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 yaml
import json
import logging
import yaml
import json
import logging
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
if wait:
# Wait for status for VIM instance creation
resp))
if wait:
# Wait for status for VIM instance creation
wait_id = vim_id_for_wait
# Wait for status for VI instance update
self._wait(wait_id)
wait_id = vim_id_for_wait
# Wait for status for VI instance update
self._wait(wait_id)
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete vim {} - {}".format(vim_name, msg))
+ msg = resp or ""
+ # 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
def list(self, filter=None):
"""Returns a list of VIM accounts
vim_id = name
if not utils.validate_uuid4(name):
vim_id = self.get_id(name)
vim_id = name
if not utils.validate_uuid4(name):
vim_id = self.get_id(name)
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,vim_id))
-# if not resp or '_id' not in resp:
-# raise ClientException('failed to get vim info: '.format(
-# resp))
-# else:
- if resp:
- return json.loads(resp)
- raise NotFound("vim {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,vim_id))
+ if resp:
+ resp = json.loads(resp)
+ if not resp or '_id' not in resp:
+ raise ClientException('failed to get vim info: {}'.format(resp))
+ return resp
+ except NotFound:
+ raise NotFound("vim '{}' not found".format(name))
if name == vnf['name']:
vnf_id = vnf['_id']
break
if name == vnf['name']:
vnf_id = vnf['_id']
break
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnf_id))
- #print('RESP: {}'.format(resp))
- if resp:
- return json.loads(resp)
- raise NotFound("vnf {} not found".format(name))
-
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnf_id))
+ #print('RESP: {}'.format(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("vnf '{}' not found".format(name))
+ raise NotFound("vnf '{}' not found".format(name))
from osmclient.common.exceptions import NotFound
from osmclient.common.exceptions import ClientException
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 magic
from osmclient.common import utils
import json
import magic
vnfd = self.get(name)
# It is redundant, since the previous one already gets the whole vnfpkginfo
# The only difference is that a different primitive is exercised
vnfd = self.get(name)
# It is redundant, since the previous one already gets the whole vnfpkginfo
# The only difference is that a different primitive is exercised
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnfd['_id']))
- #print(yaml.safe_dump(resp))
- if resp:
- return json.loads(resp)
- raise NotFound("vnfd {} not found".format(name))
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnfd['_id']))
+ #print(yaml.safe_dump(resp))
+ if resp:
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("vnfd '{}' not found".format(name))
+ raise NotFound("vnfd '{}' not found".format(name))
def get_thing(self, name, thing, filename):
self._logger.debug("")
def get_thing(self, name, thing, filename):
self._logger.debug("")
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete vnfd {} - {}".format(name, msg))
+ msg = resp or ""
+ # 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):
self._logger.debug("")
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server: '.format(resp))
+ raise ClientException('unexpected response from server: '.format(resp))
print(resp['id'])
elif http_code == 204:
print('Updated')
print(resp['id'])
elif http_code == 204:
print('Updated')
from osmclient.common import utils
from osmclient.common import wait as WaitForStatus
from osmclient.common.exceptions import ClientException
from osmclient.common import utils
from osmclient.common import wait as WaitForStatus
from osmclient.common.exceptions import ClientException
-from osmclient.common.exceptions import OsmHttpException
from osmclient.common.exceptions import NotFound
import yaml
import json
from osmclient.common.exceptions import NotFound
import yaml
import json
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise OsmHttpException('unexpected response from server - {}'.format(
+ raise ClientException('unexpected response from server - {}'.format(
resp))
if wait:
# Wait for status for WIM instance creation
resp))
if wait:
# Wait for status for WIM instance creation
wait_id = wim_id_for_wait
# Wait for status for WIM instance update
self._wait(wait_id)
wait_id = wim_id_for_wait
# Wait for status for WIM instance update
self._wait(wait_id)
#else:
# msg = ""
# if resp:
#else:
# msg = ""
# if resp:
elif http_code == 204:
print('Deleted')
else:
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise OsmHttpException("failed to delete wim {} - {}".format(wim_name, msg))
+ msg = resp or ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ raise ClientException("failed to delete wim {} - {}".format(wim_name, msg))
def list(self, filter=None):
"""Returns a list of VIM accounts
def list(self, filter=None):
"""Returns a list of VIM accounts
wim_id = name
if not utils.validate_uuid4(name):
wim_id = self.get_id(name)
wim_id = name
if not utils.validate_uuid4(name):
wim_id = self.get_id(name)
- _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,wim_id))
-# if not resp or '_id' not in resp:
-# raise ClientException('failed to get wim info: '.format(
-# resp))
-# else:
- if resp:
+ try:
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase,wim_id))
+ if resp:
+ resp = json.loads(resp)
+ if not resp or '_id' not in resp:
+ raise ClientException('failed to get wim info: '.format(resp))
- raise NotFound("wim {} not found".format(name))
+ except NotFound:
+ raise NotFound("wim '{}' not found".format(name))