Fix output for ns-list and ns-op-list to show better info from record
[osm/osmclient.git] / osmclient / sol005 / nsi.py
index cf88114..c01b4e9 100644 (file)
@@ -24,6 +24,7 @@ from osmclient.common.exceptions import ClientException
 from osmclient.common.exceptions import NotFound
 import yaml
 import json
+import logging
 
 
 class Nsi(object):
@@ -31,6 +32,7 @@ class Nsi(object):
     def __init__(self, http=None, client=None):
         self._http = http
         self._client = client
+        self._logger = logging.getLogger('osmclient')
         self._apiName = '/nsilcm'
         self._apiVersion = '/v1'
         self._apiResource = '/netslice_instances_content'
@@ -39,6 +41,8 @@ class Nsi(object):
 
     # NSI '--wait' option
     def _wait(self, id, deleteFlag=False):
+        self._logger.debug("")
+        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 +57,8 @@ class Nsi(object):
     def list(self, filter=None):
         """Returns a list of NSI
         """
+        self._logger.debug("")
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -64,6 +70,8 @@ class Nsi(object):
     def get(self, name):
         """Returns an NSI based on name or id
         """
+        self._logger.debug("")
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for nsi in self.list():
                 if name == nsi['_id']:
@@ -75,7 +83,9 @@ class Nsi(object):
         raise NotFound("nsi {} not found".format(name))
 
     def get_individual(self, name):
+        self._logger.debug("")
         nsi_id = name
+        self._client.get_token()
         if not utils.validate_uuid4(name):
             for nsi in self.list():
                 if name == nsi['name']:
@@ -89,6 +99,7 @@ class Nsi(object):
         raise NotFound("nsi {} not found".format(name))
 
     def delete(self, name, force=False, wait=False):
+        self._logger.debug("")
         nsi = self.get(name)
         querystring = ''
         if force:
@@ -120,11 +131,14 @@ class Nsi(object):
                ssh_keys=None, description='default description',
                admin_status='ENABLED', wait=False):
 
+        self._logger.debug("")
+        self._client.get_token()
         nst = self._client.nst.get(nst_name)
 
         vim_account_id = {}
 
         def get_vim_account_id(vim_account):
+            self._logger.debug("")
             if vim_account_id.get(vim_account):
                 return vim_account_id[vim_account]
 
@@ -198,6 +212,8 @@ class Nsi(object):
                             not additional_param_subnet.get("additionalParamsForVnf"):
                         raise ValueError("Error at --config 'additionalParamsForSubnet' items must contain "
                                          "'additionalParamsForNs' and/or 'additionalParamsForVnf'")
+            if "timeout_nsi_deploy" in nsi_config:
+                nsi["timeout_nsi_deploy"] = nsi_config.pop("timeout_nsi_deploy")
 
         # print(yaml.safe_dump(nsi))
         try:
@@ -235,12 +251,13 @@ 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):
         """Returns the list of operations of a NSI
         """
+        self._logger.debug("")
         nsi = self.get(name)
         try:
             self._apiResource = '/nsi_lcm_op_occs'
@@ -272,12 +289,14 @@ 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._logger.debug("")
+        self._client.get_token()
         try:
             self._apiResource = '/nsi_lcm_op_occs'
             self._apiBase = '{}{}{}'.format(self._apiName,
@@ -303,12 +322,13 @@ 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):
         """Executes an operation on a NSI
         """
+        self._logger.debug("")
         nsi = self.get(name)
         try:
             self._apiResource = '/netslice_instances'
@@ -338,6 +358,6 @@ class Nsi(object):
         except ClientException as exc:
             message="failed to exec operation {}:\nerror:\n{}".format(
                     name,
-                    exc.message)
+                    str(exc))
             raise ClientException(message)