Skip to content

Commit d683bb4

Browse files
authored
[CLI][show][platform] Added ASIC count in the output. (#1185) (#1227)
1 parent 4585be1 commit d683bb4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

show/main.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from swsssdk import SonicV2Connector
1818
from tabulate import tabulate
1919
import mlnx
20+
import utilities_common.cli as clicommon
2021
import utilities_common.multi_asic as multi_asic_util
2122

2223
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
@@ -1533,6 +1534,7 @@ def get_hw_info_dict():
15331534
hw_info_dict['platform'] = device_info.get_platform()
15341535
hw_info_dict['hwsku'] = device_info.get_hwsku()
15351536
hw_info_dict['asic_type'] = version_info['asic_type']
1537+
hw_info_dict['asic_count'] = device_info.get_num_npus()
15361538

15371539
return hw_info_dict
15381540

@@ -1547,12 +1549,18 @@ def platform():
15471549

15481550
# 'summary' subcommand ("show platform summary")
15491551
@platform.command()
1550-
def summary():
1552+
@click.option('--json', is_flag=True, help="JSON output")
1553+
def summary(json):
15511554
"""Show hardware platform information"""
1555+
15521556
hw_info_dict = get_hw_info_dict()
1553-
click.echo("Platform: {}".format(hw_info_dict['platform']))
1554-
click.echo("HwSKU: {}".format(hw_info_dict['hwsku']))
1555-
click.echo("ASIC: {}".format(hw_info_dict['asic_type']))
1557+
if json:
1558+
click.echo(clicommon.json_dump(hw_info_dict))
1559+
else:
1560+
click.echo("Platform: {}".format(hw_info_dict['platform']))
1561+
click.echo("HwSKU: {}".format(hw_info_dict['hwsku']))
1562+
click.echo("ASIC: {}".format(hw_info_dict['asic_type']))
1563+
click.echo("ASIC Count: {}".format(hw_info_dict['asic_count']))
15561564

15571565
# 'syseeprom' subcommand ("show platform syseeprom")
15581566
@platform.command()

utilities_common/cli.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
3+
def json_dump(data):
4+
"""
5+
Dump data in JSON format
6+
"""
7+
return json.dumps(
8+
data, sort_keys=True, indent=2, ensure_ascii=False
9+
)

0 commit comments

Comments
 (0)