Allow ns-terminate params. Some other updates at ns 17/8717/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 23 Mar 2020 06:34:43 +0000 (06:34 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 30 Mar 2020 15:37:04 +0000 (15:37 +0000)
Change-Id: Ic0ccbbc391c9a90b934d183b7b7986c1819a35b3
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/ns.py

index 80c5e41..bd61408 100755 (executable)
@@ -711,12 +711,12 @@ def ns_op_list(ctx, name, long):
             action_name = op['operationParams']['primitive']
         detail = "-"
         if op['operationState']=='PROCESSING':
-            if op['lcmOperationType']=='instantiate':
+            if op['lcmOperationType'] in ('instantiate', 'terminate'):
                 if op['stage']:
                     detail = op['stage']
             else:
                 detail = "In queue. Current position: {}".format(op['queuePosition'])
-        elif op['operationState']=='FAILED' or op['operationState']=='FAILED_TEMP':
+        elif op['operationState'] in ('FAILED', 'FAILED_TEMP'):
             detail = op.get('errorMessage','-')
         date = datetime.fromtimestamp(op['startTime']).strftime("%Y-%m-%dT%H:%M:%S")
         last_update = datetime.fromtimestamp(op['statusEnteredTime']).strftime("%Y-%m-%dT%H:%M:%S")
@@ -1971,6 +1971,9 @@ def nfpkg_delete(ctx, name, force):
 @cli_osm.command(name='ns-delete', short_help='deletes a NS instance')
 @click.argument('name')
 @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
+@click.option('--config', default=None,
+              help="specific yaml configuration for the termination, e.g. '{autoremove: False, timeout_ns_terminate: "
+                   "600, skip_terminate_primitives: True}'")
 @click.option('--wait',
               required=False,
               default=False,
@@ -1978,7 +1981,7 @@ def nfpkg_delete(ctx, name, force):
               help='do not return the control immediately, but keep it '
                    'until the operation is completed, or timeout')
 @click.pass_context
-def ns_delete(ctx, name, force, wait):
+def ns_delete(ctx, name, force, config, wait):
     """deletes a NS instance
 
     NAME: name or ID of the NS instance to be deleted
@@ -1986,10 +1989,10 @@ def ns_delete(ctx, name, force, wait):
     logger.debug("")
     # try:
     if not force:
-        ctx.obj.ns.delete(name, wait=wait)
+        ctx.obj.ns.delete(name, config=config, wait=wait)
     else:
         check_client_version(ctx.obj, '--force')
-        ctx.obj.ns.delete(name, force, wait=wait)
+        ctx.obj.ns.delete(name, force, config=config, wait=wait)
     # except ClientException as e:
     #     print(str(e))
     #     exit(1)
index 7fd1859..2fce5ab 100644 (file)
@@ -100,14 +100,23 @@ class Ns(object):
             raise NotFound("ns '{}' not found".format(name))
         raise NotFound("ns '{}' not found".format(name))
 
-    def delete(self, name, force=False, wait=False):
+    def delete(self, name, force=False, config=None, wait=False):
         self._logger.debug("")
         ns = self.get(name)
+        querystring_list = []
         querystring = ''
+        if config:
+            ns_config = yaml.safe_load(config)
+            querystring_list += ["{}={}".format(k, v) for k, v in ns_config.items()]
         if force:
-            querystring = '?FORCE=True'
+            querystring_list.append('FORCE=True')
+        if querystring_list:
+            querystring = "?" + "&".join(querystring_list)
         http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
                                                  ns['_id'], querystring))
+        # TODO change to use a POST self._http.post_cmd('{}/{}/terminate{}'.format(_apiBase, ns['_id'], querystring),
+        #                                               postfields_dict=ns_config)
+        # seting autoremove as True by default
         # print('HTTP CODE: {}'.format(http_code))
         # print('RESP: {}'.format(resp))
         if http_code == 202: