Skip to content

Commit

Permalink
[CLI][show][platform] Added ASIC count in the output. (sonic-net#1185)
Browse files Browse the repository at this point in the history
* [CLI][show][platform] Added ASIC count in the output. Also added option for JSON output.
  • Loading branch information
smaheshm committed Oct 26, 2020
1 parent 00a2570 commit f14bbe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 13 additions & 6 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import vlan
import system_health

from sonic_py_common import device_info
from sonic_py_common import device_info, multi_asic
from swsssdk import ConfigDBConnector, SonicV2Connector
from tabulate import tabulate
from utilities_common.db import Db
import utilities_common.multi_asic as multi_asic_util
import utilities_common.multi_asic as multi_asic_util


# Global Variables
Expand Down Expand Up @@ -991,6 +991,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'] = multi_asic.get_num_asics()

return hw_info_dict

Expand All @@ -1005,12 +1006,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()
Expand Down
17 changes: 14 additions & 3 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import re
import sys
import netaddr
import subprocess
import sys

import click
import json
import netaddr

from natsort import natsorted

from utilities_common.db import Db
Expand Down Expand Up @@ -126,7 +128,7 @@ def __init__(self, db=None):
self.config_db = db.cfgdb
self.port_dict = self.config_db.get_table('PORT')
self.alias_max_length = 0


if not self.port_dict:
click.echo(message="Warning: failed to retrieve PORT table from ConfigDB!", err=True)
Expand Down Expand Up @@ -509,3 +511,12 @@ def do_exit(msg):
m = "FATAL failure: {}. Exiting...".format(msg)
_log_msg(syslog.LOG_ERR, True, inspect.stack()[1][1], inspect.stack()[1][2], m)
raise SystemExit(m)


def json_dump(data):
"""
Dump data in JSON format
"""
return json.dumps(
data, sort_keys=True, indent=2, ensure_ascii=False
)

0 comments on commit f14bbe5

Please sign in to comment.