From d683bb48604220942b9f6bdea90c0ea4ff4f72ef Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala <10645050+smaheshm@users.noreply.github.com> Date: Fri, 13 Nov 2020 10:07:11 -0800 Subject: [PATCH] [CLI][show][platform] Added ASIC count in the output. (#1185) (#1227) --- show/main.py | 16 ++++++++++++---- utilities_common/cli.py | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 utilities_common/cli.py diff --git a/show/main.py b/show/main.py index c9ac23d712..ffa317cb82 100755 --- a/show/main.py +++ b/show/main.py @@ -17,6 +17,7 @@ from swsssdk import SonicV2Connector from tabulate import tabulate import mlnx +import utilities_common.cli as clicommon import utilities_common.multi_asic as multi_asic_util SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' @@ -1533,6 +1534,7 @@ def get_hw_info_dict(): hw_info_dict['platform'] = device_info.get_platform() hw_info_dict['hwsku'] = device_info.get_hwsku() hw_info_dict['asic_type'] = version_info['asic_type'] + hw_info_dict['asic_count'] = device_info.get_num_npus() return hw_info_dict @@ -1547,12 +1549,18 @@ def platform(): # 'summary' subcommand ("show platform summary") @platform.command() -def summary(): +@click.option('--json', is_flag=True, help="JSON output") +def summary(json): """Show hardware platform information""" + hw_info_dict = get_hw_info_dict() - click.echo("Platform: {}".format(hw_info_dict['platform'])) - click.echo("HwSKU: {}".format(hw_info_dict['hwsku'])) - click.echo("ASIC: {}".format(hw_info_dict['asic_type'])) + if json: + click.echo(clicommon.json_dump(hw_info_dict)) + else: + click.echo("Platform: {}".format(hw_info_dict['platform'])) + click.echo("HwSKU: {}".format(hw_info_dict['hwsku'])) + click.echo("ASIC: {}".format(hw_info_dict['asic_type'])) + click.echo("ASIC Count: {}".format(hw_info_dict['asic_count'])) # 'syseeprom' subcommand ("show platform syseeprom") @platform.command() diff --git a/utilities_common/cli.py b/utilities_common/cli.py new file mode 100644 index 0000000000..6a8e5de92b --- /dev/null +++ b/utilities_common/cli.py @@ -0,0 +1,9 @@ +import json + +def json_dump(data): + """ + Dump data in JSON format + """ + return json.dumps( + data, sort_keys=True, indent=2, ensure_ascii=False + )