Skip to content

Commit 24fe1ac

Browse files
authored
[show][config] support for interface alias for muxcable commands (#1699)
Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com What I did this PR adds support for interface alias support for muxcable commands. Basically for other OS's there could be a different scheme of interface naming which will be now be supported by muxcable commands as well. How I did it Added the changes in muxcable.py in show and config . How to verify it run on a Arista-7050cx3 switch. Previous command output (if the output of a command-line utility has changed) New command output (if the output of a command-line utility has changed) admin@str2-7050cx3-acs-04:/usr$ show mux cableinfo Ethernet15/1 Vendor Model -------- ---------------- Credo CACL2X321P2PA1MS admin@str2-7050cx3-acs-04:/usr$ show mux hwmode muxdirection Ethernet13/1 Port Direction ---------- ----------- Ethernet48 standby Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
1 parent 186d851 commit 24fe1ac

File tree

3 files changed

+68
-17
lines changed

3 files changed

+68
-17
lines changed

config/muxcable.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# Helper functions
2424

25-
2625
def get_value_for_key_in_dict(mdict, port, key, table_name):
2726
value = mdict.get(key, None)
2827
if value is None:
@@ -90,9 +89,12 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
9089
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
9190
@click.argument('port', metavar='<port_name>', required=True, default=None)
9291
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
93-
def mode(state, port, json_output):
92+
@clicommon.pass_db
93+
def mode(db, state, port, json_output):
9494
"""Config muxcable mode"""
9595

96+
port = platform_sfputil_helper.get_interface_alias(port, db)
97+
9698
port_table_keys = {}
9799
y_cable_asic_table_keys = {}
98100
per_npu_configdb = {}
@@ -258,9 +260,12 @@ def hwmode():
258260
@hwmode.command()
259261
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "standby"]))
260262
@click.argument('port', metavar='<port_name>', required=True, default=None)
261-
def state(state, port):
263+
@clicommon.pass_db
264+
def state(db, state, port):
262265
"""Configure the muxcable mux state {active/standby}"""
263266

267+
port = platform_sfputil_helper.get_interface_alias(port, db)
268+
264269
per_npu_statedb = {}
265270
transceiver_table_keys = {}
266271
transceiver_dict = {}
@@ -457,9 +462,12 @@ def state(state, port):
457462
@hwmode.command()
458463
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["auto", "manual"]))
459464
@click.argument('port', metavar='<port_name>', required=True, default=None)
460-
def setswitchmode(state, port):
465+
@clicommon.pass_db
466+
def setswitchmode(db, state, port):
461467
"""Configure the muxcable mux switching mode {auto/manual}"""
462468

469+
port = platform_sfputil_helper.get_interface_alias(port, db)
470+
463471
per_npu_statedb = {}
464472
transceiver_dict = {}
465473

@@ -701,9 +709,12 @@ def firmware():
701709
@firmware.command()
702710
@click.argument('fwfile', metavar='<firmware_file>', required=True)
703711
@click.argument('port', metavar='<port_name>', required=True, default=None)
704-
def download(fwfile, port):
712+
@clicommon.pass_db
713+
def download(db, fwfile, port):
705714
"""Config muxcable firmware download"""
706715

716+
port = platform_sfputil_helper.get_interface_alias(port, db)
717+
707718
per_npu_statedb = {}
708719
y_cable_asic_table_keys = {}
709720
port_table_keys = {}
@@ -751,9 +762,12 @@ def download(fwfile, port):
751762

752763
@firmware.command()
753764
@click.argument('port', metavar='<port_name>', required=True, default=None)
754-
def activate(port):
765+
@clicommon.pass_db
766+
def activate(db, port):
755767
"""Config muxcable firmware activate"""
756768

769+
port = platform_sfputil_helper.get_interface_alias(port, db)
770+
757771
per_npu_statedb = {}
758772
y_cable_asic_table_keys = {}
759773
port_table_keys = {}
@@ -800,9 +814,12 @@ def activate(port):
800814

801815
@firmware.command()
802816
@click.argument('port', metavar='<port_name>', required=True, default=None)
803-
def rollback(port):
817+
@clicommon.pass_db
818+
def rollback(db, port):
804819
"""Config muxcable firmware rollback"""
805820

821+
port = platform_sfputil_helper.get_interface_alias(port, db)
822+
806823
port_table_keys = {}
807824
y_cable_asic_table_keys = {}
808825
per_npu_statedb = {}

show/muxcable.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
VENDOR_NAME = "Credo"
2727
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")
2828

29-
30-
#
3129
# 'muxcable' command ("show muxcable")
3230
#
3331

@@ -129,9 +127,12 @@ def create_json_dump_per_port_config(port_status_dict, per_npu_configdb, asic_id
129127
@muxcable.command()
130128
@click.argument('port', required=False, default=None)
131129
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
132-
def status(port, json_output):
130+
@clicommon.pass_db
131+
def status(db, port, json_output):
133132
"""Show muxcable status information"""
134133

134+
port = platform_sfputil_helper.get_interface_alias(port, db)
135+
135136
port_table_keys = {}
136137
port_health_table_keys = {}
137138
per_npu_statedb = {}
@@ -239,9 +240,12 @@ def status(port, json_output):
239240
@muxcable.command()
240241
@click.argument('port', required=False, default=None)
241242
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
242-
def config(port, json_output):
243+
@clicommon.pass_db
244+
def config(db, port, json_output):
243245
"""Show muxcable config information"""
244246

247+
port = platform_sfputil_helper.get_interface_alias(port, db)
248+
245249
port_mux_tbl_keys = {}
246250
asic_start_idx = None
247251
per_npu_configdb = {}
@@ -407,9 +411,12 @@ def eyeinfo(port, target):
407411

408412
@muxcable.command()
409413
@click.argument('port', required=True, default=None)
410-
def cableinfo(port):
414+
@clicommon.pass_db
415+
def cableinfo(db, port):
411416
"""Show muxcable cable information"""
412417

418+
port = platform_sfputil_helper.get_interface_alias(port, db)
419+
413420
if platform_sfputil is not None:
414421
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)
415422

@@ -444,9 +451,12 @@ def hwmode():
444451

445452
@hwmode.command()
446453
@click.argument('port', metavar='<port_name>', required=False, default=None)
447-
def muxdirection(port):
454+
@clicommon.pass_db
455+
def muxdirection(db, port):
448456
"""Shows the current direction of the muxcable {active/standy}"""
449457

458+
port = platform_sfputil_helper.get_interface_alias(port, db)
459+
450460
per_npu_statedb = {}
451461
transceiver_table_keys = {}
452462
transceiver_dict = {}
@@ -649,9 +659,11 @@ def muxdirection(port):
649659

650660
@hwmode.command()
651661
@click.argument('port', metavar='<port_name>', required=False, default=None)
652-
def switchmode(port):
662+
def switchmode(db, port):
653663
"""Shows the current switching mode of the muxcable {auto/manual}"""
654664

665+
port = platform_sfputil_helper.get_interface_alias(port, db)
666+
655667
per_npu_statedb = {}
656668
transceiver_dict = {}
657669

@@ -848,9 +860,12 @@ def firmware():
848860
@firmware.command()
849861
@click.argument('port', metavar='<port_name>', required=True, default=None)
850862
@click.option('--active', 'active', required=False, is_flag=True, type=click.BOOL, help="display the firmware version of only active bank within MCU's")
851-
def version(port, active):
863+
@clicommon.pass_db
864+
def version(db, port, active):
852865
"""Show muxcable firmware version"""
853866

867+
port = platform_sfputil_helper.get_interface_alias(port, db)
868+
854869
port_table_keys = {}
855870
y_cable_asic_table_keys = {}
856871
per_npu_statedb = {}
@@ -940,12 +955,16 @@ def version(port, active):
940955
else:
941956
click.echo("there is not a valid asic table for this asic_index".format(asic_index))
942957

958+
943959
@muxcable.command()
944960
@click.argument('port', metavar='<port_name>', required=True, default=None)
945961
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
946-
def metrics(port, json_output):
962+
@clicommon.pass_db
963+
def metrics(db, port, json_output):
947964
"""Show muxcable metrics <port>"""
948965

966+
port = platform_sfputil_helper.get_interface_alias(port, db)
967+
949968
metrics_table_keys = {}
950969
per_npu_statedb = {}
951970
metrics_dict = {}
@@ -981,7 +1000,6 @@ def metrics(port, json_output):
9811000
if asic_index is None:
9821001
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))
9831002

984-
9851003
metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
9861004
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))
9871005

utilities_common/platform_sfputil_helper.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22

33
import click
4+
5+
from . import cli as clicommon
46
from sonic_py_common import multi_asic, device_info
57

68
platform_sfputil = None
@@ -64,3 +66,17 @@ def get_asic_id_for_logical_port(port):
6466
def get_physical_to_logical():
6567

6668
return platform_sfputil.physical_to_logical
69+
70+
71+
def get_interface_alias(port, db):
72+
73+
if port is not "all" and port is not None:
74+
alias = port
75+
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
76+
port = iface_alias_converter.alias_to_name(alias)
77+
if port is None:
78+
click.echo("cannot find port name for alias {}".format(alias))
79+
sys.exit(1)
80+
81+
return port
82+

0 commit comments

Comments
 (0)