overwrite parameter deprecated and help parameter 17/8117/4
authorpinoa <alberto.pino@altran.com>
Tue, 5 Nov 2019 13:28:15 +0000 (14:28 +0100)
committerpinoa <alberto.pino@altran.com>
Mon, 11 Nov 2019 10:37:03 +0000 (11:37 +0100)
Change-Id: Ia2474fc1bd2c42e287f19517df216e0619eee7cb
Signed-off-by: pinoa <alberto.pino@altran.com>
16 files changed:
osmclient/scripts/osm.py
osmclient/sol005/client.py
osmclient/sol005/ns.py
osmclient/sol005/nsd.py
osmclient/sol005/nsi.py
osmclient/sol005/nst.py
osmclient/sol005/package.py
osmclient/sol005/pdud.py
osmclient/sol005/project.py
osmclient/sol005/role.py
osmclient/sol005/sdncontroller.py
osmclient/sol005/user.py
osmclient/sol005/vim.py
osmclient/sol005/vnf.py
osmclient/sol005/vnfd.py
osmclient/sol005/wim.py

index 7b2e1a3..6e8bd88 100755 (executable)
@@ -1049,8 +1049,11 @@ def nsd_create(ctx, filename, overwrite):
 
 @cli.command(name='nsd-create', short_help='creates a new NSD/NSpkg')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in NSD')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrite deprecated, use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def nsd_create1(ctx, filename, overwrite):
     """creates a new NSD/NSpkg
@@ -1062,8 +1065,11 @@ def nsd_create1(ctx, filename, overwrite):
 
 @cli.command(name='nspkg-create', short_help='creates a new NSD/NSpkg')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in NSD')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrite deprecated, use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def nsd_create2(ctx, filename, overwrite):
     """creates a new NSD/NSpkg
@@ -1084,8 +1090,11 @@ def vnfd_create(ctx, filename, overwrite):
 
 @cli.command(name='vnfd-create', short_help='creates a new VNFD/VNFpkg')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in VNFD')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrite deprecated, use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def vnfd_create1(ctx, filename, overwrite):
     """creates a new VNFD/VNFpkg
@@ -1097,8 +1106,11 @@ def vnfd_create1(ctx, filename, overwrite):
 
 @cli.command(name='vnfpkg-create', short_help='creates a new VNFD/VNFpkg')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in VNFD')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrite deprecated, use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def vnfd_create2(ctx, filename, overwrite):
     """creates a new VNFD/VNFpkg
@@ -1110,8 +1122,11 @@ def vnfd_create2(ctx, filename, overwrite):
 
 @cli.command(name='nfpkg-create', short_help='creates a new NFpkg')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in NFD')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrite deprecated, use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def nfpkg_create(ctx, filename, overwrite):
     """creates a new NFpkg
@@ -1187,8 +1202,11 @@ def nst_create(ctx, filename, overwrite):
 
 @cli.command(name='nst-create', short_help='creates a new Network Slice Template (NST)')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in NST')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrites deprecated use override')
+@click.option('--override', 'overwrite' ,default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def nst_create1(ctx, filename, overwrite):
     """creates a new Network Slice Template (NST)
@@ -1200,8 +1218,11 @@ def nst_create1(ctx, filename, overwrite):
 
 @cli.command(name='netslice-template-create', short_help='creates a new Network Slice Template (NST)')
 @click.argument('filename')
-@click.option('--overwrite', default=None,
-              help='overwrites some fields in NST')
+@click.option('--overwrite', 'overwrite', default=None,
+              help='overwrites deprecated use override')
+@click.option('--override', 'overwrite', default=None,
+              help='overrides fields in descriptor, format: '
+                   '"key1.key2...=value[;key3...=value;...]"')
 @click.pass_context
 def nst_create2(ctx, filename, overwrite):
     """creates a new Network Slice Template (NST)
@@ -2980,7 +3001,6 @@ def role_show(ctx, name):
     table.align = 'l'
     print(table)
 
-
 if __name__ == '__main__':
     try:
         cli()
index 513e947..a4f952c 100644 (file)
@@ -54,6 +54,7 @@ class Client(object):
         self._project = project
         self._auth_endpoint = '/admin/v1/tokens'
         self._headers = {}
+        self._token = None
 
         if len(host.split(':')) > 1:
             # backwards compatible, port provided as part of host
@@ -71,14 +72,6 @@ class Client(object):
                        for (key, val) in list(self._headers.items())]
         self._http_client.set_http_header(http_header)
 
-        token = self.get_token()
-        if not token:
-            raise ClientException(
-                    'Authentication error: not possible to get auth token')
-        self._headers['Authorization'] = 'Bearer {}'.format(token)
-        http_header.append('Authorization: Bearer {}'.format(token))
-        self._http_client.set_http_header(http_header)
-
         self.vnfd = vnfd.Vnfd(self._http_client, client=self)
         self.nsd = nsd.Nsd(self._http_client, client=self)
         self.nst = nst.Nst(self._http_client, client=self)
@@ -99,15 +92,21 @@ class Client(object):
         '''
 
     def get_token(self):
-        postfields_dict = {'username': self._user,
-                           'password': self._password,
-                           '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):
-            raise ClientException(resp)
-        token = json.loads(resp) if resp else None
-        if token is not None:
-            return token['_id']
-        return None
+        if self._token is None:
+            postfields_dict = {'username': self._user,
+                               'password': self._password,
+                               '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)
+
+            token = json.loads(resp) if resp else None
+            self._token = token['id']
 
+            if self._token is not None:
+                self._headers['Authorization'] = 'Bearer {}'.format(self._token)
+                http_header = ['{}: {}'.format(key, val)
+                               for (key, val) in list(self._headers.items())]
+                self._http_client.set_http_header(http_header)
index e3fe17d..b0c37f1 100644 (file)
@@ -53,6 +53,7 @@ class Ns(object):
     def list(self, filter=None):
         """Returns a list of NS
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -64,6 +65,7 @@ class Ns(object):
     def get(self, name):
         """Returns an NS based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for ns in self.list():
                 if name == ns['_id']:
@@ -75,6 +77,7 @@ class Ns(object):
         raise NotFound("ns {} not found".format(name))
 
     def get_individual(self, name):
+        self._client.get_token()
         ns_id = name
         if not utils.validate_uuid4(name):
             for ns in self.list():
@@ -118,7 +121,7 @@ class Ns(object):
     def create(self, nsd_name, nsr_name, account, config=None,
                ssh_keys=None, description='default description',
                admin_status='ENABLED', wait=False):
-
+        self._client.get_token()
         nsd = self._client.nsd.get(nsd_name)
 
         vim_account_id = {}
@@ -282,6 +285,7 @@ class Ns(object):
     def get_op(self, operationId):
         """Returns the status of an operation
         """
+        self._client.get_token()
         try:
             self._apiResource = '/ns_lcm_op_occs'
             self._apiBase = '{}{}{}'.format(self._apiName,
@@ -352,6 +356,7 @@ class Ns(object):
     def scale_vnf(self, ns_name, vnf_name, scaling_group, scale_in, scale_out, wait=False):
         """Scales a VNF by adding/removing VDUs
         """
+        self._client.get_token()
         try:
             op_data={}
             op_data["scaleType"] = "SCALE_VNF"
@@ -371,6 +376,7 @@ class Ns(object):
             raise ClientException(message)
 
     def create_alarm(self, alarm):
+        self._client.get_token()
         data = {}
         data["create_alarm_request"] = {}
         data["create_alarm_request"]["alarm_create_request"] = alarm
@@ -398,6 +404,7 @@ class Ns(object):
             raise ClientException(message)
 
     def delete_alarm(self, name):
+        self._client.get_token()
         data = {}
         data["delete_alarm_request"] = {}
         data["delete_alarm_request"]["alarm_delete_request"] = {}
@@ -426,6 +433,7 @@ class Ns(object):
             raise ClientException(message)
 
     def export_metric(self, metric):
+        self._client.get_token()
         data = {}
         data["read_metric_data_request"] = metric
         try:
index bbfed17..9adc8f7 100644 (file)
@@ -40,6 +40,7 @@ class Nsd(object):
         #self._apiBase='/nsds'
 
     def list(self, filter=None):
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -50,6 +51,7 @@ class Nsd(object):
         return list()
 
     def get(self, name):
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for nsd in self.list():
                 if name == nsd['_id']:
@@ -61,6 +63,7 @@ class Nsd(object):
         raise NotFound("nsd {} not found".format(name))
 
     def get_individual(self, name):
+        # Called 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
@@ -122,6 +125,7 @@ class Nsd(object):
             raise ClientException("failed to delete nsd {} - {}".format(name, msg))
 
     def create(self, filename, overwrite=None, update_endpoint=None):
+        self._client.get_token()
         mime_type = magic.from_file(filename, mime=True)
         if mime_type is None:
             raise ClientException(
index cf88114..d670a05 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 = {}
@@ -278,6 +283,7 @@ class Nsi(object):
     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,
index bd453bf..f0da0f5 100644 (file)
@@ -38,6 +38,7 @@ class Nst(object):
                                         self._apiVersion, self._apiResource)
 
     def list(self, filter=None):
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -48,6 +49,7 @@ class Nst(object):
         return list()
 
     def get(self, name):
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for nst in self.list():
                 if name == nst['_id']:
@@ -120,6 +122,7 @@ class Nst(object):
             raise ClientException("failed to delete nst {} - {}".format(name, msg))
 
     def create(self, filename, overwrite=None, update_endpoint=None):
+        self._client.get_token()
         mime_type = magic.from_file(filename, mime=True)
         if mime_type is None:
             raise ClientException(
index 330df3c..c383862 100644 (file)
@@ -58,6 +58,7 @@ class Package(object):
         """wait(block) for an upload to succeed.
            The filename passed is assumed to be a descriptor tarball.
         """
+        self._client.get_token()
         pkg_type = utils.get_key_val_from_pkg(filename)
 
         if pkg_type is None:
@@ -68,6 +69,7 @@ class Package(object):
                                   .format(filename))
 
     def upload(self, filename):
+        self._client.get_token()
         pkg_type = utils.get_key_val_from_pkg(filename)
         if pkg_type is None:
             raise ClientException("Cannot determine package type")
index a3995d6..22ca8bc 100644 (file)
@@ -36,6 +36,7 @@ class Pdu(object):
                                         self._apiVersion, self._apiResource)
 
     def list(self, filter=None):
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -45,6 +46,7 @@ class Pdu(object):
         return list()
 
     def get(self, name):
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for pdud in self.list():
                 if name == pdud['_id']:
@@ -88,6 +90,7 @@ class Pdu(object):
             raise ClientException("failed to delete pdu {} - {}".format(name, msg))
 
     def create(self, pdu, update_endpoint=None):
+        self._client.get_token()
         headers= self._client._headers
         headers['Content-Type'] = 'application/yaml'
         http_header = ['{}: {}'.format(key,val)
index a66d84b..fe0f23c 100644 (file)
@@ -38,6 +38,7 @@ class Project(object):
     def create(self, name, project):
         """Creates a new OSM project
         """
+        self._client.get_token()
         http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
                                               postfields_dict=project)
         #print('HTTP CODE: {}'.format(http_code))
@@ -61,6 +62,7 @@ class Project(object):
     def update(self, project, project_changes):
         """Updates an OSM project identified by name
         """
+        self._client.get_token()
         proj = self.get(project)
         http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']),
                                              postfields_dict=project_changes)
@@ -87,6 +89,7 @@ class Project(object):
     def delete(self, name, force=False):
         """Deletes an OSM project identified by name
         """
+        self._client.get_token()
         project = self.get(name)
         querystring = ''
         if force:
@@ -113,6 +116,7 @@ class Project(object):
     def list(self, filter=None):
         """Returns the list of OSM projects
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -125,6 +129,7 @@ class Project(object):
     def get(self, name):
         """Returns a specific OSM project based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for proj in self.list():
                 if name == proj['_id']:
index 64e84f9..faa381b 100644 (file)
@@ -46,6 +46,7 @@ class Role(object):
         :raises ClientException: when receives an unexpected from the server.
         :raises ClientException: when fails creating a role.
         """
+        self._client.get_token()
         role = {"name": name}
 
         if permissions:
@@ -94,6 +95,7 @@ class Role(object):
         :raises ClientException: when receives an unexpected response from the server.
         :raises ClientException: when fails updating a role.
         """
+        self._client.get_token()
         if new_name is None and permissions is None and add is None and remove is None:
             raise ClientException('At least one option should be provided')
         elif permissions and (add or remove):
@@ -171,6 +173,7 @@ class Role(object):
         :param force:
         :raises ClientException: when fails to delete a role.
         """
+        self._client.get_token()
         role = self.get(name)
         querystring = ''
         if force:
@@ -201,6 +204,7 @@ class Role(object):
         :param filter:
         :returns:
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -218,6 +222,7 @@ class Role(object):
         :raises NotFound: when the role is not found.
         :returns: the specified role.
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for role in self.list():
                 if name == role['_id']:
index 4036dfb..690fa07 100644 (file)
@@ -37,6 +37,7 @@ class SdnController(object):
 
     # SDNC '--wait' option
     def _wait(self, id, deleteFlag=False):
+        self._client.get_token()
         # Endpoint to get operation status
         apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/sdns')
         # Wait for status for SDN instance creation/update/deletion
@@ -59,6 +60,7 @@ class SdnController(object):
         return ''
 
     def create(self, name, sdn_controller, wait=False):
+        self._client.get_token()
         http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
                                        postfields_dict=sdn_controller)
         #print('HTTP CODE: {}'.format(http_code))
@@ -83,6 +85,7 @@ class SdnController(object):
             raise ClientException("failed to create SDN controller {} - {}".format(name, msg))
 
     def update(self, name, sdn_controller, wait=False):
+        self._client.get_token()
         sdnc = self.get(name)
         sdnc_id_for_wait = self._get_id_for_wait(name)
         http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,sdnc['_id']),
@@ -108,6 +111,7 @@ class SdnController(object):
             raise ClientException("failed to update SDN controller {} - {}".format(name, msg))
 
     def delete(self, name, force=False, wait=False):
+        self._client.get_token()
         sdn_controller = self.get(name)
         sdnc_id_for_wait = self._get_id_for_wait(name)
         querystring = ''
@@ -139,6 +143,7 @@ class SdnController(object):
     def list(self, filter=None):
         """Returns a list of SDN controllers
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -151,6 +156,7 @@ class SdnController(object):
     def get(self, name):
         """Returns an SDN controller based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for sdnc in self.list():
                 if name == sdnc['_id']:
index 2f635f0..689d359 100644 (file)
@@ -38,6 +38,7 @@ class User(object):
     def create(self, name, user):
         """Creates a new OSM user
         """
+        self._client.get_token()
         if not user["projects"] or (len(user["projects"]) == 1 and not user["projects"][0]):
             del user["projects"]
         elif len(user["projects"]) == 1:
@@ -83,6 +84,7 @@ class User(object):
     def update(self, name, user):
         """Updates an existing OSM user identified by name
         """
+        self._client.get_token()
         # print(user)
         myuser = self.get(name)
         update_user = {
@@ -163,6 +165,7 @@ class User(object):
     def delete(self, name, force=False):
         """Deletes an existing OSM user identified by name
         """
+        self._client.get_token()
         user = self.get(name)
         querystring = ''
         if force:
@@ -189,6 +192,7 @@ class User(object):
     def list(self, filter=None):
         """Returns the list of OSM users
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -201,6 +205,7 @@ class User(object):
     def get(self, name):
         """Returns an OSM user based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for user in self.list():
                 if name == user['_id']:
index ad6f9b7..421f8a5 100644 (file)
@@ -35,8 +35,10 @@ class Vim(object):
         self._apiResource = '/vim_accounts'
         self._apiBase = '{}{}{}'.format(self._apiName,
                                         self._apiVersion, self._apiResource)
+
     # VIM '--wait' option
     def _wait(self, id, deleteFlag=False):
+        self._client.get_token()
         # Endpoint to get operation status
         apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/vim_accounts')
         # Wait for status for VIM instance creation/deletion
@@ -59,6 +61,7 @@ class Vim(object):
         return ''
 
     def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None, wait=False):
+        self._client.get_token()
         if 'vim-type' not in vim_access:
             #'openstack' not in vim_access['vim-type']):
             raise Exception("vim type not provided")
@@ -104,6 +107,7 @@ class Vim(object):
             raise ClientException("failed to create vim {} - {}".format(name, msg))
 
     def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False):
+        self._client.get_token()
         vim = self.get(vim_name)
         vim_id_for_wait = self._get_id_for_wait(vim_name)
         vim_config = {}
@@ -162,6 +166,7 @@ class Vim(object):
         raise NotFound("vim {} not found".format(name))
 
     def delete(self, vim_name, force=False, wait=False):
+        self._client.get_token()
         vim_id = vim_name
         if not utils.validate_uuid4(vim_name):
             vim_id = self.get_id(vim_name)
@@ -198,6 +203,7 @@ class Vim(object):
     def list(self, filter=None):
         """Returns a list of VIM accounts
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -213,6 +219,7 @@ class Vim(object):
     def get(self, name):
         """Returns a VIM account based on name or id
         """
+        self._client.get_token()
         vim_id = name
         if not utils.validate_uuid4(name):
             vim_id = self.get_id(name)
index 6da13f5..b7ac856 100644 (file)
@@ -36,6 +36,7 @@ class Vnf(object):
     def list(self, ns=None, filter=None):
         """Returns a list of VNF instances
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -54,6 +55,7 @@ class Vnf(object):
     def get(self, name):
         """Returns a VNF instance based on name or id
         """
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for vnf in self.list():
                 if name == vnf['_id']:
@@ -65,6 +67,7 @@ class Vnf(object):
         raise NotFound("vnf {} not found".format(name))
 
     def get_individual(self, name):
+        self._client.get_token()
         vnf_id = name
         if not utils.validate_uuid4(name):
             for vnf in self.list():
index 8ad11c6..ffa0182 100644 (file)
@@ -40,6 +40,7 @@ class Vnfd(object):
         #self._apiBase='/vnfds'
 
     def list(self, filter=None):
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -49,6 +50,7 @@ class Vnfd(object):
         return list()
 
     def get(self, name):
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for vnfd in self.list():
                 if name == vnfd['_id']:
@@ -99,6 +101,7 @@ class Vnfd(object):
         self.get_thing(name, 'artifacts/{}'.format(artifact), filename)
 
     def delete(self, name, force=False):
+        self._client.get_token()
         vnfd = self.get(name)
         querystring = ''
         if force:
@@ -121,6 +124,7 @@ class Vnfd(object):
             raise ClientException("failed to delete vnfd {} - {}".format(name, msg))
 
     def create(self, filename, overwrite=None, update_endpoint=None):
+        self._client.get_token()
         mime_type = magic.from_file(filename, mime=True)
         if mime_type is None:
             raise ClientException(
@@ -177,6 +181,7 @@ class Vnfd(object):
             raise ClientException("failed to create/update vnfd - {}".format(msg))
 
     def update(self, name, filename):
+        self._client.get_token()
         vnfd = self.get(name)
         endpoint = '{}/{}/package_content'.format(self._apiBase, vnfd['_id'])
         self.create(filename=filename, update_endpoint=endpoint)
index 30b36e7..c2ada69 100644 (file)
@@ -35,8 +35,10 @@ class Wim(object):
         self._apiResource = '/wim_accounts'
         self._apiBase = '{}{}{}'.format(self._apiName,
                                         self._apiVersion, self._apiResource)
+
     # WIM '--wait' option
     def _wait(self, id, deleteFlag=False):
+        self._client.get_token()
         # Endpoint to get operation status
         apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/wim_accounts')
         # Wait for status for WIM instance creation/deletion
@@ -59,6 +61,7 @@ class Wim(object):
         return ''
 
     def create(self, name, wim_input, wim_port_mapping=None, wait=False):
+        self._client.get_token()
         if 'wim_type' not in wim_input:
             raise Exception("wim type not provided")
 
@@ -99,6 +102,7 @@ class Wim(object):
             raise ClientException("failed to create wim {} - {}".format(name, msg))
 
     def update(self, wim_name, wim_account, wim_port_mapping=None, wait=False):
+        self._client.get_token()
         wim = self.get(wim_name)
         wim_id_for_wait = self._get_id_for_wait(wim_name)
         wim_config = {}
@@ -154,6 +158,7 @@ class Wim(object):
         raise NotFound("wim {} not found".format(name))
 
     def delete(self, wim_name, force=False, wait=False):
+        self._client.get_token()
         wim_id = wim_name
         wim_id_for_wait = self._get_id_for_wait(wim_name)
         if not utils.validate_uuid4(wim_name):
@@ -192,6 +197,7 @@ class Wim(object):
     def list(self, filter=None):
         """Returns a list of VIM accounts
         """
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -207,6 +213,7 @@ class Wim(object):
     def get(self, name):
         """Returns a VIM account based on name or id
         """
+        self._client.get_token()
         wim_id = name
         if not utils.validate_uuid4(name):
             wim_id = self.get_id(name)