X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fcli_commands%2Fvnf.py;h=59c8df4a06331aac95f9e42b23bda3f2df41806e;hb=refs%2Fheads%2Fv14.0;hp=6c86ff7b60856a8df9479b10e4ba9260d020e755;hpb=9ba58bde6883dee6e6e6034232af0ff57772b70b;p=osm%2Fosmclient.git diff --git a/osmclient/cli_commands/vnf.py b/osmclient/cli_commands/vnf.py index 6c86ff7..59c8df4 100755 --- a/osmclient/cli_commands/vnf.py +++ b/osmclient/cli_commands/vnf.py @@ -27,7 +27,7 @@ import logging logger = logging.getLogger("osmclient") -def vnf_list(ctx, ns, filter, long, o): +def vnf_list(ctx, ns, filter, long, output): logger.debug("") if ns or filter: if ns: @@ -38,8 +38,16 @@ def vnf_list(ctx, ns, filter, long, o): resp = ctx.obj.vnf.list(ns, filter) else: resp = ctx.obj.vnf.list() - fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__ - if fullclassname == "osmclient.sol005.client.Client": + field_names = [ + "vnf id", + "name", + "ns id", + "vnf member index", + "vnfd name", + "vim account id", + "ip address", + ] + if long: field_names = [ "vnf id", "name", @@ -48,57 +56,31 @@ def vnf_list(ctx, ns, filter, long, o): "vnfd name", "vim account id", "ip address", + "date", + "last update", + ] + table = PrettyTable(field_names) + for vnfr in resp: + name = vnfr["name"] if "name" in vnfr else "-" + new_row = [ + vnfr["_id"], + name, + vnfr["nsr-id-ref"], + vnfr["member-vnf-index-ref"], + vnfr["vnfd-ref"], + vnfr["vim-account-id"], + vnfr["ip-address"], ] if long: - field_names = [ - "vnf id", - "name", - "ns id", - "vnf member index", - "vnfd name", - "vim account id", - "ip address", - "date", - "last update", - ] - table = PrettyTable(field_names) - for vnfr in resp: - name = vnfr["name"] if "name" in vnfr else "-" - new_row = [ - vnfr["_id"], - name, - vnfr["nsr-id-ref"], - vnfr["member-vnf-index-ref"], - vnfr["vnfd-ref"], - vnfr["vim-account-id"], - vnfr["ip-address"], - ] - if long: - date = datetime.fromtimestamp(vnfr["_admin"]["created"]).strftime( - "%Y-%m-%dT%H:%M:%S" - ) - last_update = datetime.fromtimestamp( - vnfr["_admin"]["modified"] - ).strftime("%Y-%m-%dT%H:%M:%S") - new_row.extend([date, last_update]) - table.add_row(new_row) - else: - table = PrettyTable(["vnf name", "id", "operational status", "config status"]) - for vnfr in resp: - if "mgmt-interface" not in vnfr: - vnfr["mgmt-interface"] = {} - vnfr["mgmt-interface"]["ip-address"] = None - table.add_row( - [ - vnfr["name"], - vnfr["id"], - vnfr["operational-status"], - vnfr["config-status"], - ] + date = datetime.fromtimestamp(vnfr["_admin"]["created"]).strftime( + "%Y-%m-%dT%H:%M:%S" + ) + last_update = datetime.fromtimestamp(vnfr["_admin"]["modified"]).strftime( + "%Y-%m-%dT%H:%M:%S" ) - table.align = "l" - # print(table) - print_output.print_output(o, table.field_names, table._rows) + new_row.extend([date, last_update]) + table.add_row(new_row) + print_output.print_output(output, table.field_names, table._rows) @click.command(name="vnf-list", short_help="list all NF instances") @@ -112,18 +94,12 @@ def vnf_list(ctx, ns, filter, long, o): help="restricts the list to the NF instances matching the filter.", ) @click.option("--long", is_flag=True, help="get more details") -@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 vnf_list1(ctx, ns, filter, long, o): +def vnf_list1(ctx, ns, filter, long, output): """list all NF instances""" logger.debug("") - vnf_list(ctx, ns, filter, long, o) + vnf_list(ctx, ns, filter, long, output) @click.command(name="nf-list", short_help="list all NF instances") @@ -137,15 +113,9 @@ def vnf_list1(ctx, ns, filter, long, o): help="restricts the list to the NF instances matching the filter.", ) @click.option("--long", is_flag=True, help="get more details") -@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 nf_list(ctx, ns, filter, long, o): +def nf_list(ctx, ns, filter, long, output): """list all NF instances \b @@ -194,7 +164,7 @@ def nf_list(ctx, ns, filter, long, o): --filter vnfd-ref=,vdur.ip-address= """ logger.debug("") - vnf_list(ctx, ns, filter, long, o) + vnf_list(ctx, ns, filter, long, output) @click.command(name="vnf-show", short_help="shows the info of a VNF instance") @@ -206,15 +176,9 @@ def nf_list(ctx, ns, filter, long, o): help="restricts the information to the fields in the filter", ) @click.option("--kdu", default=None, help="KDU name (whose status will be shown)") -@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 vnf_show(ctx, name, literal, filter, kdu, o): +def vnf_show(ctx, name, literal, filter, kdu, output): """shows the info of a VNF instance NAME: name or ID of the VNF instance @@ -294,6 +258,4 @@ def vnf_show(ctx, name, literal, filter, kdu, o): for k, v in list(resp.items()): if not filter or k in filter: table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)]) - 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)