X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fcli_commands%2Fns.py;h=80961d5d35d4669024f9093c6550b5e5f2459f02;hb=23cc10b85ee953de2a1f5c6d84cffcc816a421d0;hp=441ae051b9fa042c468099b5878f0b1fccfcaae0;hpb=9ba58bde6883dee6e6e6034232af0ff57772b70b;p=osm%2Fosmclient.git diff --git a/osmclient/cli_commands/ns.py b/osmclient/cli_commands/ns.py index 441ae05..80961d5 100755 --- a/osmclient/cli_commands/ns.py +++ b/osmclient/cli_commands/ns.py @@ -38,15 +38,9 @@ logger = logging.getLogger("osmclient") is_flag=True, help="get more details of the NS (project, vim, deployment status, configuration status.", ) -@click.option( - "-o", - default="table", - is_eager=True, - callback=print_output.validate_command_output, - help="adapt the output as table, yaml, csv, json, jsonpath", -) +@print_output.output_option @click.pass_context -def ns_list(ctx, filter, long, o): +def ns_list(ctx, filter, long, output): """list all NS instances \b @@ -216,65 +210,41 @@ def ns_list(ctx, filter, long, o): ] ) for ns in resp: - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": - nsr = ns - logger.debug("NS info: {}".format(nsr)) - nsr_name = nsr["name"] - nsr_id = nsr["_id"] - date = datetime.fromtimestamp(nsr["create-time"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - ns_state = nsr.get("nsState", nsr["_admin"]["nsState"]) - if long: - deployment_status = summarize_deployment_status( - nsr.get("deploymentStatus") - ) - config_status = summarize_config_status(nsr.get("configurationStatus")) - project_id, project_name = utils.get_project(project_list, nsr) - # project = '{} ({})'.format(project_name, project_id) - project = project_name - vim_id = nsr.get("datacenter") - vim_name = utils.get_vim_name(vim_list, vim_id) + nsr = ns + logger.debug("NS info: {}".format(nsr)) + nsr_name = nsr["name"] + nsr_id = nsr["_id"] + date = datetime.fromtimestamp(nsr["create-time"]).strftime("%Y-%m-%dT%H:%M:%S") + ns_state = nsr.get("nsState", nsr["_admin"]["nsState"]) + if long: + deployment_status = summarize_deployment_status(nsr.get("deploymentStatus")) + config_status = summarize_config_status(nsr.get("configurationStatus")) + project_id, project_name = utils.get_project(project_list, nsr) + # project = '{} ({})'.format(project_name, project_id) + project = project_name + vim_id = nsr.get("datacenter") + vim_name = utils.get_vim_name(vim_list, vim_id) - # vim = '{} ({})'.format(vim_name, vim_id) - vim = vim_name - if "currentOperation" in nsr: - current_operation = "{} ({})".format( - nsr["currentOperation"], nsr["currentOperationID"] - ) - else: - current_operation = "{} ({})".format( - nsr["_admin"].get("current-operation", "-"), - nsr["_admin"]["nslcmop"], - ) - error_details = "N/A" - if ( - ns_state == "BROKEN" - or ns_state == "DEGRADED" - or ("currentOperation" not in nsr and nsr.get("errorDescription")) - ): - error_details = "{}\nDetail: {}".format( - nsr["errorDescription"], nsr["errorDetail"] - ) + # vim = '{} ({})'.format(vim_name, vim_id) + vim = vim_name + if "currentOperation" in nsr: + current_operation = "{} ({})".format( + nsr["currentOperation"], nsr["currentOperationID"] + ) else: - nsopdata = ctx.obj.ns.get_opdata(ns["id"]) - nsr = nsopdata["nsr:nsr"] - nsr_name = nsr["name-ref"] - nsr_id = nsr["ns-instance-config-ref"] - date = "-" - project = "-" - deployment_status = ( - nsr["operational-status"] - if "operational-status" in nsr - else "Not found" + current_operation = "{} ({})".format( + nsr["_admin"].get("current-operation", "-"), + nsr["_admin"]["nslcmop"], + ) + error_details = "N/A" + if ( + ns_state == "BROKEN" + or ns_state == "DEGRADED" + or ("currentOperation" not in nsr and nsr.get("errorDescription")) + ): + error_details = "{}\nDetail: {}".format( + nsr["errorDescription"], nsr["errorDetail"] ) - ns_state = deployment_status - config_status = nsr.get("config-status", "Not found") - current_operation = "Unknown" - error_details = nsr.get("detailed-status", "Not found") - if config_status == "config_not_needed": - config_status = "configured (no charms)" if long: table.add_row( @@ -302,9 +272,7 @@ def ns_list(ctx, filter, long, o): utils.wrap_text(text=error_details, width=40), ] ) - table.align = "l" - # print(table) - print_output.print_output(o, table.field_names, table._rows) + print_output.print_output(output, table.field_names, table._rows) print('To get the history of all operations over a NS, run "osm ns-op-list NS_ID"') print( 'For more details on the current operation, run "osm ns-op-show OPERATION_ID"' @@ -319,15 +287,9 @@ def ns_list(ctx, filter, long, o): multiple=True, help="restricts the information to the fields in the filter", ) -@click.option( - "-o", - default="table", - is_eager=True, - callback=print_output.validate_command_output, - help="adapt the output as table, yaml, csv, json, jsonpath", -) +@print_output.output_option @click.pass_context -def ns_show(ctx, name, literal, filter, o): +def ns_show(ctx, name, literal, filter, output): """shows the info of a NS instance NAME: name or ID of the NS instance @@ -345,16 +307,12 @@ def ns_show(ctx, name, literal, filter, o): if not filter or k in filter: table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)]) - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname != "osmclient.sol005.client.Client": - nsopdata = ctx.obj.ns.get_opdata(ns["id"]) - nsr_optdata = nsopdata["nsr:nsr"] - for k, v in list(nsr_optdata.items()): - if not filter or k in filter: - table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), width=100)]) - table.align = "l" - print_output.print_output(o, table.field_names, table._rows) - # print(table) + nsopdata = ctx.obj.ns.get_opdata(ns["id"]) + nsr_optdata = nsopdata["nsr:nsr"] + for k, v in list(nsr_optdata.items()): + if not filter or k in filter: + table.add_row([k, utils.wrap_text(json.dumps(v, indent=2), width=100)]) + print_output.print_output(output, table.field_names, table._rows) @click.command(name="ns-create", short_help="creates a new Network Service instance")