migration to Python3: fix printing exception message
[osm/osmclient.git] / osmclient / sol005 / nsi.py
index ab6cf0a..0fcfe1d 100644 (file)
@@ -39,6 +39,7 @@ class Nsi(object):
 
     # NSI '--wait' option
     def _wait(self, id, deleteFlag=False):
+        self._client.get_token()
         # Endpoint to get operation status
         apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/nsi_lcm_op_occs')
         # Wait for status for NSI instance creation/update/deletion
@@ -53,6 +54,7 @@ class Nsi(object):
     def list(self, filter=None):
         """Returns a list of NSI
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -64,6 +66,7 @@ class Nsi(object):
     def get(self, name):
         """Returns an NSI based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for nsi in self.list():
                 if name == nsi['_id']:
@@ -76,6 +79,7 @@ class Nsi(object):
 
     def get_individual(self, name):
         nsi_id = name
+        self._client.get_token()
         if not utils.validate_uuid4(name):
             for nsi in self.list():
                 if name == nsi['name']:
@@ -120,6 +124,7 @@ class Nsi(object):
                ssh_keys=None, description='default description',
                admin_status='ENABLED', wait=False):
 
+        self._client.get_token()
         nst = self._client.nst.get(nst_name)
 
         vim_account_id = {}
@@ -155,7 +160,7 @@ class Nsi(object):
                 with open(pubkeyfile, 'r') as f:
                     nsi['ssh_keys'].append(f.read())
         if config:
-            nsi_config = yaml.load(config)
+            nsi_config = yaml.safe_load(config)
             if "netslice-vld" in nsi_config:
                 for vld in nsi_config["netslice-vld"]:
                     if vld.get("vim-network-name"):
@@ -235,7 +240,7 @@ class Nsi(object):
             message="failed to create nsi: {} nst: {}\nerror:\n{}".format(
                     nsi_name,
                     nst_name,
-                    exc.message)
+                    str(exc))
             raise ClientException(message)
 
     def list_op(self, name, filter=None):
@@ -272,12 +277,13 @@ class Nsi(object):
         except ClientException as exc:
             message="failed to get operation list of NSI {}:\nerror:\n{}".format(
                     name,
-                    exc.message)
+                    str(exc))
             raise ClientException(message)
 
     def get_op(self, operationId):
         """Returns the status of an operation
         """
+        self._client.get_token()
         try:
             self._apiResource = '/nsi_lcm_op_occs'
             self._apiBase = '{}{}{}'.format(self._apiName,
@@ -303,7 +309,7 @@ class Nsi(object):
         except ClientException as exc:
             message="failed to get status of operation {}:\nerror:\n{}".format(
                     operationId,
-                    exc.message)
+                    str(exc))
             raise ClientException(message)
 
     def exec_op(self, name, op_name, op_data=None):
@@ -338,6 +344,6 @@ class Nsi(object):
         except ClientException as exc:
             message="failed to exec operation {}:\nerror:\n{}".format(
                     name,
-                    exc.message)
+                    str(exc))
             raise ClientException(message)