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")
@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,
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
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)
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: