Merge branch 'master' into v7.0
Change-Id: Id80cf649873e7678b1cda77102407be2b5628824
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osmclient/common/exceptions.py b/osmclient/common/exceptions.py
index 0be2778..12de003 100644
--- a/osmclient/common/exceptions.py
+++ b/osmclient/common/exceptions.py
@@ -19,5 +19,9 @@
pass
-class NotFound(ClientException):
+class OsmHttpException(ClientException):
+ pass
+
+
+class NotFound(OsmHttpException):
pass
diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py
index af8cab9..f61373e 100755
--- a/osmclient/scripts/osm.py
+++ b/osmclient/scripts/osm.py
@@ -3805,13 +3805,17 @@
def cli():
try:
cli_osm()
+ exit(0)
except pycurl.error as exc:
print(exc)
print('Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified')
- exit(1)
except ClientException as exc:
print("ERROR: {}".format(exc))
- exit(1)
+ 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
diff --git a/osmclient/sol005/client.py b/osmclient/sol005/client.py
index bf6f845..3ceb1b3 100644
--- a/osmclient/sol005/client.py
+++ b/osmclient/sol005/client.py
@@ -36,7 +36,6 @@
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
@@ -107,9 +106,9 @@
'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']
@@ -121,6 +120,6 @@
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"))
-
diff --git a/osmclient/sol005/http.py b/osmclient/sol005/http.py
index aca8a4b..3d21465 100644
--- a/osmclient/sol005/http.py
+++ b/osmclient/sol005/http.py
@@ -20,6 +20,7 @@
import logging
import copy
from osmclient.common import http
+from osmclient.common.exceptions import OsmHttpException, NotFound
class Http(http.Http):
@@ -54,10 +55,12 @@
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())))
- 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
@@ -106,9 +109,11 @@
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()
+ data_text = data.getvalue().decode()
+ self._logger.verbose("Response DATA: {}".format(data_text))
+ return http_code, data_text
else:
return http_code, None
@@ -150,8 +155,22 @@
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()
+ 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():
+ 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))
diff --git a/osmclient/sol005/k8scluster.py b/osmclient/sol005/k8scluster.py
index 5520787..0cdb089 100644
--- a/osmclient/sol005/k8scluster.py
+++ b/osmclient/sol005/k8scluster.py
@@ -17,8 +17,8 @@
"""
from osmclient.common import utils
-from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
+from osmclient.common.exceptions import ClientException
import json
class K8scluster(object):
@@ -45,21 +45,20 @@
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))
- 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 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 K8s cluster {} - {}".format(name, msg))
def update(self, name, k8s_cluster):
self._client.get_token()
@@ -68,16 +67,16 @@
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
@@ -104,12 +103,12 @@
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 K8s cluster {} - {}".format(name, msg))
def list(self, filter=None):
@@ -119,9 +118,9 @@
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):
@@ -131,10 +130,13 @@
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:
+ 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
- raise NotFound("K8s cluster {} not found".format(name))
+ except NotFound:
+ raise NotFound("K8s cluster {} not found".format(name))
diff --git a/osmclient/sol005/ns.py b/osmclient/sol005/ns.py
index 12c5416..f0877fc 100644
--- a/osmclient/sol005/ns.py
+++ b/osmclient/sol005/ns.py
@@ -61,9 +61,9 @@
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):
@@ -79,7 +79,7 @@
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("")
@@ -90,12 +90,15 @@
if name == ns['name']:
ns_id = ns['_id']
break
- resp = self._http.get_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
- 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("")
@@ -117,12 +120,12 @@
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 ns {} - {}".format(name, msg))
def create(self, nsd_name, nsr_name, account, config=None,
@@ -139,7 +142,6 @@
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))
@@ -148,11 +150,11 @@
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]
-
wim = self._client.wim.get(wim_account)
if wim is None:
raise NotFound("cannot find wim account '{}'".format(wim_account))
@@ -226,27 +228,28 @@
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'))
+ print(resp['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,
@@ -265,7 +268,7 @@
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) )
@@ -278,13 +281,13 @@
else:
raise ClientException('unexpected response from server')
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
+ msg = resp or ""
+ # 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(
@@ -311,13 +314,13 @@
else:
raise ClientException('unexpected response from server')
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- msg = resp['detail']
- except ValueError:
- msg = resp
+ msg = resp or ""
+ # 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(
@@ -341,25 +344,25 @@
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,
@@ -401,18 +404,18 @@
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))
+ # 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,
@@ -431,18 +434,18 @@
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))
+ # 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,
@@ -459,18 +462,18 @@
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))
+ # 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,
diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py
index bf91ca6..5979bc0 100644
--- a/osmclient/sol005/nsd.py
+++ b/osmclient/sol005/nsd.py
@@ -47,10 +47,10 @@
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):
@@ -69,14 +69,17 @@
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.get_cmd('{}/{}'.format(self._apiBase, nsd['_id']))
- #print(yaml.safe_dump(resp))
- if resp:
- return 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("")
@@ -87,17 +90,17 @@
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
+ #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
+ msg = resp or ""
+ # 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):
@@ -127,12 +130,12 @@
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 nsd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
@@ -175,23 +178,22 @@
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 ClientException('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("")
diff --git a/osmclient/sol005/nsi.py b/osmclient/sol005/nsi.py
index c01b4e9..4b522a8 100644
--- a/osmclient/sol005/nsi.py
+++ b/osmclient/sol005/nsi.py
@@ -62,9 +62,9 @@
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):
@@ -91,11 +91,14 @@
if name == nsi['name']:
nsi_id = nsi['_id']
break
- resp = self._http.get_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
+ 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):
@@ -119,12 +122,12 @@
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 nsi {} - {}".format(name, msg))
def create(self, nst_name, nsi_name, account, config=None,
@@ -226,27 +229,27 @@
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,
@@ -271,21 +274,21 @@
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,
@@ -304,21 +307,21 @@
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,
@@ -340,21 +343,21 @@
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,
diff --git a/osmclient/sol005/nst.py b/osmclient/sol005/nst.py
index e75c8f5..3b15e96 100644
--- a/osmclient/sol005/nst.py
+++ b/osmclient/sol005/nst.py
@@ -45,10 +45,10 @@
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):
@@ -69,32 +69,38 @@
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']))
- #print(yaml.safe_dump(resp))
- if resp:
- return 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'
- 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):
- 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("")
@@ -123,12 +129,12 @@
elif http_code == 204:
print('Deleted')
else:
- msg = ""
- if resp:
- try:
- resp = json.loads(resp)
- except ValueError:
- msg = resp
+ 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):
@@ -170,21 +176,20 @@
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 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))
def update(self, name, filename):
self._logger.debug("")
diff --git a/osmclient/sol005/package.py b/osmclient/sol005/package.py
index a52ba15..1ca3864 100644
--- a/osmclient/sol005/package.py
+++ b/osmclient/sol005/package.py
@@ -100,19 +100,18 @@
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 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))
diff --git a/osmclient/sol005/pdud.py b/osmclient/sol005/pdud.py
index 42fe40d..3abb78c 100644
--- a/osmclient/sol005/pdud.py
+++ b/osmclient/sol005/pdud.py
@@ -43,9 +43,9 @@
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):
@@ -66,11 +66,14 @@
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']))
+ 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 resp
- raise NotFound("pdu {} not found".format(name))
+ return json.loads(resp)
+ raise NotFound("pdu '{}' not found".format(name))
def delete(self, name, force=False):
self._logger.debug("")
@@ -87,12 +90,12 @@
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 pdu {} - {}".format(name, msg))
def create(self, pdu, update_endpoint=None):
@@ -111,21 +114,21 @@
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 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))
def update(self, name, filename):
self._logger.debug("")
diff --git a/osmclient/sol005/project.py b/osmclient/sol005/project.py
index 8f119e8..dc2e9a5 100644
--- a/osmclient/sol005/project.py
+++ b/osmclient/sol005/project.py
@@ -46,21 +46,21 @@
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 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))
def update(self, project, project_changes):
"""Updates an OSM project identified by name
@@ -81,14 +81,14 @@
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
@@ -110,12 +110,12 @@
elif resp and 'result' in resp:
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 project {} - {}".format(name, msg))
def list(self, filter=None):
@@ -126,10 +126,10 @@
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):
diff --git a/osmclient/sol005/repo.py b/osmclient/sol005/repo.py
index a8d8f17..7a31397 100644
--- a/osmclient/sol005/repo.py
+++ b/osmclient/sol005/repo.py
@@ -37,21 +37,21 @@
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 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))
def update(self, name, repo):
self._client.get_token()
@@ -60,16 +60,16 @@
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
@@ -97,12 +97,12 @@
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):
@@ -112,9 +112,9 @@
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):
@@ -124,10 +124,13 @@
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:
+ 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
- raise NotFound("Repo {} not found".format(name))
+ except NotFound:
+ raise NotFound("Repo {} not found".format(name))
diff --git a/osmclient/sol005/role.py b/osmclient/sol005/role.py
index 404784a..c80e50e 100644
--- a/osmclient/sol005/role.py
+++ b/osmclient/sol005/role.py
@@ -68,21 +68,21 @@
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 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))
def update(self, name, new_name, permissions, add=None, remove=None):
"""
@@ -156,18 +156,18 @@
resp = json.loads(resp)
if not resp or 'id' not in resp:
raise ClientException('Unexpected response from server - {}'.format(
- resp))
+ 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):
"""
@@ -194,12 +194,12 @@
elif resp and 'result' in resp:
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 role {} - {}".format(name, msg))
def list(self, filter=None):
@@ -214,10 +214,10 @@
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):
diff --git a/osmclient/sol005/sdncontroller.py b/osmclient/sol005/sdncontroller.py
index b2bbc37..35ad9ee 100644
--- a/osmclient/sol005/sdncontroller.py
+++ b/osmclient/sol005/sdncontroller.py
@@ -67,26 +67,28 @@
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 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))
def update(self, name, sdn_controller, wait=False):
self._logger.debug("")
@@ -97,23 +99,23 @@
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
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update SDN controller {} - {}".format(name, msg))
+ #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
+ #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("")
@@ -138,12 +140,12 @@
elif resp and 'result' in resp:
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 SDN controller {} - {}".format(name, msg))
def list(self, filter=None):
@@ -154,10 +156,10 @@
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):
diff --git a/osmclient/sol005/user.py b/osmclient/sol005/user.py
index 6c10325..fac26cd 100644
--- a/osmclient/sol005/user.py
+++ b/osmclient/sol005/user.py
@@ -68,21 +68,21 @@
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 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))
def update(self, name, user):
"""Updates an existing OSM user identified by name
@@ -157,14 +157,14 @@
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
@@ -186,12 +186,12 @@
elif resp and 'result' in resp:
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 user {} - {}".format(name, msg))
def list(self, filter=None):
@@ -202,10 +202,10 @@
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):
diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py
index 43911a6..9cd882c 100644
--- a/osmclient/sol005/vim.py
+++ b/osmclient/sol005/vim.py
@@ -94,24 +94,24 @@
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 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))
def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
self._logger.debug("")
@@ -138,23 +138,23 @@
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
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update vim {} - {}".format(vim_name, msg))
+ #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
+ #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("")
@@ -203,12 +203,12 @@
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 vim {} - {}".format(vim_name, msg))
def list(self, filter=None):
@@ -219,11 +219,11 @@
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
@@ -236,11 +236,13 @@
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:
+ 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
- raise NotFound("vim {} not found".format(name))
+ except NotFound:
+ raise NotFound("vim '{}' not found".format(name))
diff --git a/osmclient/sol005/vnf.py b/osmclient/sol005/vnf.py
index 6aa44d8..edae358 100644
--- a/osmclient/sol005/vnf.py
+++ b/osmclient/sol005/vnf.py
@@ -21,7 +21,7 @@
from osmclient.common import utils
from osmclient.common.exceptions import NotFound
import logging
-
+import json
class Vnf(object):
@@ -49,10 +49,10 @@
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):
@@ -66,7 +66,7 @@
return vnf
else:
for vnf in self.list():
- if name == vnf['name']:
+ if name == vnf.get('name'):
return vnf
raise NotFound("vnf {} not found".format(name))
@@ -79,9 +79,11 @@
if name == vnf['name']:
vnf_id = vnf['_id']
break
- resp = self._http.get_cmd('{}/{}'.format(self._apiBase, vnf_id))
- #print('RESP: {}'.format(resp))
- if resp:
- return 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))
diff --git a/osmclient/sol005/vnfd.py b/osmclient/sol005/vnfd.py
index ec54c95..8bf3552 100644
--- a/osmclient/sol005/vnfd.py
+++ b/osmclient/sol005/vnfd.py
@@ -47,9 +47,9 @@
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):
@@ -70,11 +70,14 @@
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']))
- #print(yaml.safe_dump(resp))
- if resp:
- return 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("")
@@ -84,18 +87,18 @@
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("")
@@ -125,12 +128,12 @@
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 vnfd {} - {}".format(name, msg))
def create(self, filename, overwrite=None, update_endpoint=None):
@@ -177,19 +180,18 @@
if resp:
resp = json.loads(resp)
if not resp or 'id' not in resp:
- raise ClientException('unexpected response from server: '.format(
- resp))
+ raise ClientException('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("")
diff --git a/osmclient/sol005/wim.py b/osmclient/sol005/wim.py
index 61c4dda..90632c6 100644
--- a/osmclient/sol005/wim.py
+++ b/osmclient/sol005/wim.py
@@ -88,24 +88,24 @@
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 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))
def update(self, wim_name, wim_account, wim_port_mapping=None, wait=False):
self._logger.debug("")
@@ -129,23 +129,23 @@
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
- else:
- msg = ""
- if resp:
- try:
- msg = json.loads(resp)
- except ValueError:
- msg = resp
- raise ClientException("failed to update wim {} - {}".format(wim_name, msg))
+ #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
+ #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("")
@@ -196,12 +196,12 @@
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 wim {} - {}".format(wim_name, msg))
def list(self, filter=None):
@@ -212,11 +212,11 @@
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
@@ -229,11 +229,13 @@
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
- raise NotFound("wim {} not found".format(name))
+ 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))
+ return json.loads(resp)
+ except NotFound:
+ raise NotFound("wim '{}' not found".format(name))
diff --git a/tox.ini b/tox.ini
index 6fdc825..b02cab2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -36,7 +36,7 @@
pyflakes osmclient
[testenv:build]
-basepython = python3
+basepython = python
deps = stdeb
setuptools-version-command
-r{toxinidir}/requirements.txt