diff --git a/scripts/sfpshow b/scripts/sfpshow index 1875e832c5..dcfb23586f 100755 --- a/scripts/sfpshow +++ b/scripts/sfpshow @@ -357,6 +357,43 @@ class SFPShow(object): def display_eeprom(self): click.echo(self.output) + + @multi_asic_util.run_on_multi_asic + def display_summary(self, interfacename): + out_put = '' + info_table = [] + header = ['Interface' ,'Media Name', 'Max Power(W)', 'Vendor Name','Serial Num.','Part Num.', 'QSA Adapter','Qualified' ] + + if interfacename is not None: + if not interfacename.startswith('Ethernet'): + if interfacename.isnumeric(): + interfacename = 'Ethernet'+interfacename + + sfp_info_dict = self.sdb.get_all(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interfacename)) + if sfp_info_dict is None: + sfp_info_dict = dict() + sub = \ + [interfacename, sfp_info_dict.get('display_name', 'N/A'), sfp_info_dict.get('power_rating_max', 'N/A'), + sfp_info_dict.get('vendor_name', 'N/A'), sfp_info_dict.get('vendor_serial_number', 'N/A'), + sfp_info_dict.get('vendor_part_number', 'N/A'), sfp_info_dict.get('qsa_adapter', 'N/A'), sfp_info_dict.get('qualified', 'N/A')] + info_table.append(sub) + else: + port_table_keys = self.db.keys(self.db.APPL_DB, "PORT_TABLE:*") + sorted_table_keys = natsorted(port_table_keys) + for i in sorted_table_keys: + interface = re.split(':', i, maxsplit=1)[-1].strip() + if interface and interface.startswith('Ethernet'): + sfp_info_dict = self.db.get_all(self.db.STATE_DB, 'TRANSCEIVER_INFO|{}'.format(interface)) + if sfp_info_dict is None: + sfp_info_dict = dict() + sub = \ + [interface, sfp_info_dict.get('display_name', 'N/A'), sfp_info_dict.get('power_rating_max', 'N/A'), + sfp_info_dict.get('vendor_name', 'N/A'), sfp_info_dict.get('vendor_serial_number', 'N/A'), + sfp_info_dict.get('vendor_part_number', 'N/A'), sfp_info_dict.get('qsa_adapter', 'N/A'), sfp_info_dict.get('qualified', 'N/A')] + info_table.append(sub) + click.echo("\n") + click.echo(tabulate(info_table, header)) + click.echo("\n") def display_presence(self): header = ['Port', 'Presence'] @@ -369,6 +406,22 @@ def cli(): """sfpshow - Command line utility for display SFP transceivers information""" pass +# 'summary' subcommand +@cli.command() +@click.option('-p', '--port', metavar='', help="Display SFP summary data for port only") +@click.option('-n', '--namespace', default=None, help="Display interfaces for specific namespace") +def summary(port, namespace): + if port and multi_asic.is_multi_asic() and namespace is None: + try: + ns = multi_asic.get_namespace_for_port(port) + namespace=ns + except Exception: + display_invalid_intf_eeprom(port) + sys.exit(1) + + sfp = SFPShow(port, namespace) + sfp.display_summary(port) + # 'eeprom' subcommand @cli.command() @click.option('-p', '--port', metavar='', help="Display SFP EEPROM data for port only") diff --git a/show/interfaces/__init__.py b/show/interfaces/__init__.py index c80f4de723..ea5810a5b2 100644 --- a/show/interfaces/__init__.py +++ b/show/interfaces/__init__.py @@ -281,6 +281,22 @@ def transceiver(): """Show SFP Transceiver information""" pass +@transceiver.command() +@click.argument('interfacename', required=False) +@click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data") +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def summary(interfacename, dump_dom, verbose): + """Show interface transceiver summary information""" + cmd = "sfpshow summary" + if dump_dom: + cmd += " --dom" + if interfacename is not None: + if get_interface_mode() == "alias": + interfacename = iface_alias_converter.alias_to_name(interfacename) + + cmd += " -p {}".format(interfacename) + clicommon.run_command(cmd, display_cmd=verbose) + @transceiver.command() @click.argument('interfacename', required=False) @click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data")