class NotFound(ClientException):
pass
+
+class OsmHttpException(ClientException):
+ pass
from osmclient.sol005 import pdud
from osmclient.sol005 import k8scluster
from osmclient.sol005 import repo
-from osmclient.common.exceptions import ClientException
from osmclient.common import package_tool
import json
import logging
'project_id': self._project}
http_code, resp = self._http_client.post_cmd(endpoint=self._auth_endpoint,
postfields_dict=postfields_dict)
- if http_code not in (200, 201, 202, 204):
- message ='Authentication error: not possible to get auth token\nresp:\n{}'.format(resp)
- raise ClientException(message)
+# if http_code not in (200, 201, 202, 204):
+# message ='Authentication error: not possible to get auth token\nresp:\n{}'.format(resp)
+# raise ClientException(message)
token = json.loads(resp) if resp else None
self._token = token['id']
self._http_client.set_http_header(http_header)
def get_version(self):
- resp = self._http_client.get_cmd(endpoint="/version")
+ _, 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
+from osmclient.common.exceptions import OsmHttpException
class Http(http.Http):
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
curl_cmd.close()
+ 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())))
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
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()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
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()
return http_code, None
+ def check_http_response(self, http_code, data):
+ if http_code >= 300:
+ resp = ""
+ if data.getvalue():
+ resp=": " + data.getvalue().decode()
+ raise OsmHttpException("Error {}{}".format(http_code, resp))
"""
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
class K8scluster(object):
postfields_dict=k8s_cluster)
#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 http_code in (200, 201, 202, 204):
+ if resp:
+ resp = json.loads(resp)
print(resp['id'])
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to add K8s cluster {} - {}".format(name, msg))
+ if not resp or 'id' not in resp:
+ raise OsmHttpException('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 add K8s cluster {} - {}".format(name, msg))
def update(self, name, k8s_cluster):
self._client.get_token()
postfields_dict=k8s_cluster)
# print 'HTTP CODE: {}'.format(http_code)
# print 'RESP: {}'.format(resp)
- if http_code in (200, 201, 202, 204):
- pass
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update K8s cluster {} - {}".format(name, msg))
+ #if http_code in (200, 201, 202, 204):
+ #pass
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to update K8s cluster {} - {}".format(name, msg))
def get_id(self, name):
"""Returns a K8s cluster id from a K8s cluster name
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete K8s cluster {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete K8s cluster {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns a list of K8s clusters
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
cluster_id = name
if not utils.validate_uuid4(name):
cluster_id = self.get_id(name)
- resp = self._http.get_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:
- return resp
+ _, 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))
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
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
if name == ns['name']:
ns_id = ns['_id']
break
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase, ns_id))
+ _, 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 resp
+ return json.loads(resp)
raise NotFound("ns {} not found".format(name))
def delete(self, name, force=False, wait=False):
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete ns {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete ns {} - {}".format(name, msg))
def create(self, nsd_name, nsr_name, account, config=None,
ssh_keys=None, description='default description',
for (key,val) in list(headers.items())]
self._http.set_http_header(http_header)
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
- postfields_dict=ns)
+ postfields_dict=ns)
# 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(
+ #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 NS instance creation
- self._wait(resp.get('nslcmop_id'))
- return resp['id']
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ if wait:
+ # Wait for status for NS instance creation
+ self._wait(resp.get('nslcmop_id'))
+ return 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,
nsd_name,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
def list_op(self, name, filter=None):
"""Returns the list of operations of a NS
self._apiVersion, self._apiResource)
filter_string = ''
if filter:
- filter_string = '&{}'.format(filter)
+ filter_string = '&{}'.format(filter)
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:
- if resp:
- resp = json.loads(resp)
- return resp
- else:
- raise ClientException('unexpected response from server')
+ #if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ raise ClientException('unexpected response from server')
+ #else:
+ # 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,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
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))
- if http_code == 200:
- if resp:
- resp = json.loads(resp)
- return resp
- else:
- raise ClientException('unexpected response from server')
+ #if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ raise ClientException('unexpected response from server')
+ #else:
+ # 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,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
def exec_op(self, name, op_name, op_data=None, wait=False, ):
"""Executes an operation on a NS
http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
#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 NS instance action
- # For the 'action' operation, 'id' is used
- self._wait(resp.get('id'))
- return resp['id']
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ #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 NS instance action
+ # For the 'action' operation, 'id' is used
+ self._wait(resp.get('id'))
+ return 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,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
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
- 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))
- if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- print('Alarm created')
- else:
- 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 {}\n{}".format(
- alarm,
- str(exc))
- raise ClientException(message)
+ #if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ print('Alarm created')
+ #else:
+ # 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 {}\n{}".format(
+ # alarm,
+ # str(exc))
+ # raise ClientException(message)
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
- 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))
- if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- print('Alarm deleted')
- else:
- 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 {}\n{}".format(
- name,
- str(exc))
- raise ClientException(message)
+ #if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ print('Alarm deleted')
+ #else:
+ # 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 {}\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
- 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))
- if http_code in (200, 201, 202, 204):
- #resp = json.loads(resp)
- return 'Metric exported'
- else:
- 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 {}\n{}".format(
- metric,
- str(exc))
- raise ClientException(message)
+ #if http_code in (200, 201, 202, 204):
+ #resp = json.loads(resp)
+ return 'Metric exported'
+ #else:
+ # 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 {}\n{}".format(
+ # metric,
+ # str(exc))
+ # raise ClientException(message)
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 OsmHttpException
from osmclient.common import utils
import json
import magic
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase, filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
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.get_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
raise NotFound("nsd {} not found".format(name))
def get_thing(self, name, thing, filename):
http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing))
#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))
+ #if http_code in (200, 201, 202, 204):
+ if resp:
+ #store in a file
+ return json.loads(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._logger.debug("")
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete nsd {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete nsd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- if http_code in (200, 201, 202, 204):
+ if http_code in (200, 201, 202):
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server - {}'.format(
- resp))
+ raise OsmHttpException('unexpected response from server - {}'.format(resp))
print(resp['id'])
elif http_code == 204:
print('Updated')
- else:
- msg = "Error {}".format(http_code)
- if resp:
- try:
- msg = "{} - {}".format(msg, json.loads(resp))
- except ValueError:
- msg = "{} - {}".format(msg, resp)
- raise ClientException("failed to create/update nsd - {}".format(msg))
+ # else:
+ # msg = "Error {}".format(http_code)
+ # if resp:
+ # try:
+ # msg = "{} - {}".format(msg, json.loads(resp))
+ # except ValueError:
+ # msg = "{} - {}".format(msg, resp)
+ # raise ClientException("failed to create/update nsd - {}".format(msg))
def update(self, name, filename):
self._logger.debug("")
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
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
if name == nsi['name']:
nsi_id = nsi['_id']
break
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase, nsi_id))
+ _, 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 resp
+ return json.loads(resp)
raise NotFound("nsi {} not found".format(name))
def delete(self, name, force=False, wait=False):
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete nsi {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete nsi {} - {}".format(name, msg))
def create(self, nst_name, nsi_name, account, config=None,
ssh_keys=None, description='default description',
for (key,val) in list(headers.items())]
self._http.set_http_header(http_header)
http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
- postfields_dict=nsi)
+ postfields_dict=nsi)
#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 NSI instance creation
- self._wait(resp.get('nsilcmop_id'))
- print(resp['id'])
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ #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 NSI instance creation
+ self._wait(resp.get('nsilcmop_id'))
+ 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 nsi: {} nst: {}\nerror:\n{}".format(
nsi_name,
nst_name,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
def list_op(self, name, filter=None):
"""Returns the list of operations of a NSI
filter_string) )
#print('HTTP CODE: {}'.format(http_code))
#print('RESP: {}'.format(resp))
- if http_code == 200:
- if resp:
- resp = json.loads(resp)
- return resp
- else:
- raise ClientException('unexpected response from server')
+ #if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ raise ClientException('unexpected response from server')
+ #else:
+ # 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 NSI {}:\nerror:\n{}".format(
name,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
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))
- if http_code == 200:
- if resp:
- resp = json.loads(resp)
- return resp
- else:
- raise ClientException('unexpected response from server')
+ #if http_code == 200:
+ if resp:
+ resp = json.loads(resp)
+ return resp
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
- raise ClientException(msg)
+ raise ClientException('unexpected response from server')
+ #else:
+ # 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,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
def exec_op(self, name, op_name, op_data=None):
"""Executes an operation on a NSI
http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=op_data)
#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(msg)
+ #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(msg)
except ClientException as exc:
message="failed to exec operation {}:\nerror:\n{}".format(
name,
str(exc))
- raise ClientException(message)
+ raise OsmHttpException(message)
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
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase, filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase, filter_string))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
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.get_cmd('{}/{}'.format(self._apiBase, nst['_id']))
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, nst['_id']))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
raise NotFound("nst {} not found".format(name))
def get_thing(self, name, thing, filename):
http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nst['_id'], thing))
#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))
+ #if http_code in (200, 201, 202, 204):
+ if resp:
+ #store in a file
+ return json.loads(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._logger.debug("")
resp = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete nst {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete nst {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
self._logger.debug("")
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
#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 = "Error {}".format(http_code)
- if resp:
- try:
- msg = "{} - {}".format(msg, json.loads(resp))
- except ValueError:
- msg = "{} - {}".format(msg, resp)
- raise ClientException("failed to create/update nst - {}".format(msg))
+ # 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))
+ print(resp['id'])
+ # else:
+ # msg = "Error {}".format(http_code)
+ # if resp:
+ # try:
+ # msg = "{} - {}".format(msg, json.loads(resp))
+ # except ValueError:
+ # msg = "{} - {}".format(msg, resp)
+ # raise ClientException("failed to create/update nst - {}".format(msg))
def update(self, name, filename):
self._logger.debug("")
#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
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
#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 upload package - {}".format(msg))
-
+ #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))
+ print(resp['id'])
+ # else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to upload package - {}".format(msg))
"""
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 logging
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
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.get_cmd('{}/{}'.format(self._apiBase, pdud['_id']))
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, pdud['_id']))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
raise NotFound("pdu {} not found".format(name))
def delete(self, name, force=False):
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete pdu {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete pdu {} - {}".format(name, msg))
def create(self, pdu, update_endpoint=None):
self._logger.debug("")
http_code, resp = self._http.post_cmd(endpoint=endpoint, postfields_dict=pdu)
#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 = "Error {}".format(http_code)
- if resp:
- try:
- msg = "{} - {}".format(msg, json.loads(resp))
- except ValueError:
- msg = "{} - {}".format(msg, resp)
- raise ClientException("failed to create/update pdu - {}".format(msg))
+ #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))
+ print(resp['id'])
+ #else:
+ # msg = "Error {}".format(http_code)
+ # if resp:
+ # try:
+ # msg = "{} - {}".format(msg, json.loads(resp))
+ # except ValueError:
+ # msg = "{} - {}".format(msg, resp)
+ # raise ClientException("failed to create/update pdu - {}".format(msg))
def update(self, name, filename):
self._logger.debug("")
"""
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
postfields_dict=project)
#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 project {} - {}".format(name, msg))
+ #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))
+ print(resp['id'])
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to create project {} - {}".format(name, msg))
def update(self, project, project_changes):
"""Updates an OSM project identified by name
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server - {}'.format(
+ raise OsmHttpException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
elif http_code == 204:
print("Updated")
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update project {} - {}".format(project, msg))
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to update project {} - {}".format(project, msg))
def delete(self, name, force=False):
"""Deletes an OSM project identified by name
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete project {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete project {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns the list of OSM projects
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, 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):
"""
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
postfields_dict=repo)
#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 add repo {} - {}".format(name, msg))
+ #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))
+ print(resp['id'])
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to add repo {} - {}".format(name, msg))
def update(self, name, repo):
self._client.get_token()
postfields_dict=repo)
# print 'HTTP CODE: {}'.format(http_code)
# print 'RESP: {}'.format(resp)
- if http_code in (200, 201, 202, 204):
- pass
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update repo {} - {}".format(name, msg))
+ #if http_code in (200, 201, 202, 204):
+ # pass
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to update repo {} - {}".format(name, msg))
def get_id(self, name):
"""Returns a repo id from a repo name
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
repo_id = name
if not utils.validate_uuid4(name):
repo_id = self.get_id(name)
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase,repo_id))
- if not resp or '_id' not in resp:
- raise ClientException('failed to get repo info: '.format(resp))
- else:
- return resp
+ _, 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))
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
postfields_dict=role)
# 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 role {} - {}".format(name, msg))
+ #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))
+ print(resp['id'])
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("Failed to create role {} - {}".format(name, msg))
def update(self, name, new_name, permissions, add=None, remove=None):
"""
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise ClientException('Unexpected response from server - {}'.format(
+ raise OsmHttpException('Unexpected response from server - {}'.format(
resp))
print(resp['id'])
elif http_code == 204:
print("Updated")
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("Failed to update role {} - {}".format(name, msg))
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("Failed to update role {} - {}".format(name, msg))
def delete(self, name, force=False):
"""
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("Failed to delete role {} - {}".format(name, msg))
+ raise OsmHttpException("Failed to delete role {} - {}".format(name, msg))
def list(self, filter=None):
"""
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase, filter_string))
+ _, 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):
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):
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
postfields_dict=user)
#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 user {} - {}".format(name, msg))
+ #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))
+ print(resp['id'])
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to create user {} - {}".format(name, msg))
def update(self, name, user):
"""Updates an existing OSM user identified by name
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server - {}'.format(
+ raise OsmHttpException('unexpected response from server - {}'.format(
resp))
print(resp['id'])
elif http_code == 204:
print('Updated')
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update user {} - {}".format(name, msg))
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to update user {} - {}".format(name, msg))
def delete(self, name, force=False):
"""Deletes an existing OSM user identified by name
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete user {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete user {} - {}".format(name, msg))
def list(self, filter=None):
"""Returns the list of OSM users
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, 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):
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
postfields_dict=vim_account)
#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 VIM 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 vim {} - {}".format(name, msg))
+ #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 VIM 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 vim {} - {}".format(name, msg))
def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
self._logger.debug("")
postfields_dict=vim_account)
# 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 = vim_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 = vim_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 vim {} - {}".format(vim_name, msg))
+ pass
+ #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):
self._logger.debug("")
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete vim {} - {}".format(vim_name, msg))
+ raise OsmHttpException("failed to delete vim {} - {}".format(vim_name, msg))
def list(self, filter=None):
"""Returns a list of VIM accounts
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if not resp:
return list()
vim_accounts = []
- for datacenter in resp:
+ for datacenter in json.loads(resp):
vim_accounts.append({"name": datacenter['name'], "uuid": datacenter['_id']
if '_id' in datacenter else None})
return vim_accounts
vim_id = name
if not utils.validate_uuid4(name):
vim_id = self.get_id(name)
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase,vim_id))
- if not resp or '_id' not in resp:
- raise ClientException('failed to get vim info: '.format(
- resp))
- else:
- return resp
+ _, 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))
from osmclient.common import utils
from osmclient.common.exceptions import NotFound
import logging
-
+import json
class Vnf(object):
filter_string += ',nsr-id-ref={}'.format(ns_instance['_id'])
else:
filter_string = '?nsr-id-ref={}'.format(ns_instance['_id'])
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, 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):
if name == vnf['name']:
vnf_id = vnf['_id']
break
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase, vnf_id))
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnf_id))
#print('RESP: {}'.format(resp))
if resp:
- return resp
+ return json.loads(resp)
raise NotFound("vnf {} not found".format(name))
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
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if resp:
- return resp
+ return json.loads(resp)
return list()
def get(self, name):
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.get_cmd('{}/{}'.format(self._apiBase, vnfd['_id']))
+ _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnfd['_id']))
#print(yaml.safe_dump(resp))
if resp:
- return resp
+ return json.loads(resp)
raise NotFound("vnfd {} not found".format(name))
def get_thing(self, name, thing, filename):
http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, vnfd['_id'], thing))
#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))
+ #if http_code in (200, 201, 202, 204):
+ if resp:
+ #store in a file
+ return json.loads(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._logger.debug("")
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete vnfd {} - {}".format(name, msg))
+ raise OsmHttpException("failed to delete vnfd {} - {}".format(name, msg))
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:
- raise ClientException('unexpected response from server: '.format(
- resp))
+ raise OsmHttpException('unexpected response from server: '.format(resp))
print(resp['id'])
elif http_code == 204:
print('Updated')
- else:
- msg = "Error {}".format(http_code)
- if resp:
- try:
- msg = "{} - {}".format(msg, json.loads(resp))
- except ValueError:
- msg = "{} - {}".format(msg, resp)
- raise ClientException("failed to create/update vnfd - {}".format(msg))
+ # else:
+ # msg = "Error {}".format(http_code)
+ # if resp:
+ # try:
+ # msg = "{} - {}".format(msg, json.loads(resp))
+ # except ValueError:
+ # msg = "{} - {}".format(msg, resp)
+ # raise ClientException("failed to create/update vnfd - {}".format(msg))
def update(self, name, filename):
self._logger.debug("")
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
postfields_dict=wim_account)
#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 WIM 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 wim {} - {}".format(name, msg))
+ #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 WIM 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 wim {} - {}".format(name, msg))
def update(self, wim_name, wim_account, wim_port_mapping=None, wait=False):
self._logger.debug("")
postfields_dict=wim_account)
#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 = wim_id_for_wait
- # Wait for status for WIM 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 = wim_id_for_wait
+ # Wait for status for WIM instance update
+ self._wait(wait_id)
else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update wim {} - {}".format(wim_name, msg))
+ pass
+ #else:
+ # msg = ""
+ # if resp:
+ # try:
+ # msg = json.loads(resp)
+ # except ValueError:
+ # msg = resp
+ # raise ClientException("failed to update wim {} - {}".format(wim_name, msg))
def update_wim_account_dict(self, wim_account, wim_input):
self._logger.debug("")
msg = json.loads(resp)
except ValueError:
msg = resp
- raise ClientException("failed to delete wim {} - {}".format(wim_name, msg))
+ raise OsmHttpException("failed to delete wim {} - {}".format(wim_name, msg))
def list(self, filter=None):
"""Returns a list of VIM accounts
filter_string = ''
if filter:
filter_string = '?{}'.format(filter)
- resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+ _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
if not resp:
return list()
wim_accounts = []
- for datacenter in resp:
+ for datacenter in json.loads(resp):
wim_accounts.append({"name": datacenter['name'], "uuid": datacenter['_id']
if '_id' in datacenter else None})
return wim_accounts
wim_id = name
if not utils.validate_uuid4(name):
wim_id = self.get_id(name)
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase,wim_id))
- if not resp or '_id' not in resp:
- raise ClientException('failed to get wim info: '.format(
- resp))
- else:
- return resp
+ _, 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:
+ return json.loads(resp)
raise NotFound("wim {} not found".format(name))