Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[show][config] support for interface alias for muxcable commands #1699

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions config/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@

# Helper functions

def get_interface_alias(port, db):

if port is not "all" and port is not None:
alias = port
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
port = iface_alias_converter.alias_to_name(alias)
if port is None:
click.echo("cannot find port name for alias {}".format(alias))
sys.exit(CONFIG_FAIL)

return port
jleveque marked this conversation as resolved.
Show resolved Hide resolved

def get_value_for_key_in_dict(mdict, port, key, table_name):
value = mdict.get(key, None)
Expand Down Expand Up @@ -90,9 +101,12 @@ def lookup_statedb_and_update_configdb(per_npu_statedb, config_db, port, state_c
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "auto", "manual"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL)
def mode(state, port, json_output):
@clicommon.pass_db
def mode(db, state, port, json_output):
"""Config muxcable mode"""

port = get_interface_alias(port, db)

port_table_keys = {}
y_cable_asic_table_keys = {}
per_npu_configdb = {}
Expand Down Expand Up @@ -258,9 +272,12 @@ def hwmode():
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["active", "standby"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
def state(state, port):
@clicommon.pass_db
def state(db, state, port):
"""Configure the muxcable mux state {active/standby}"""

port = get_interface_alias(port, db)

per_npu_statedb = {}
transceiver_table_keys = {}
transceiver_dict = {}
Expand Down Expand Up @@ -457,9 +474,12 @@ def state(state, port):
@hwmode.command()
@click.argument('state', metavar='<operation_status>', required=True, type=click.Choice(["auto", "manual"]))
@click.argument('port', metavar='<port_name>', required=True, default=None)
def setswitchmode(state, port):
@clicommon.pass_db
def setswitchmode(db, state, port):
"""Configure the muxcable mux switching mode {auto/manual}"""

port = get_interface_alias(port, db)

per_npu_statedb = {}
transceiver_dict = {}

Expand Down Expand Up @@ -701,9 +721,12 @@ def firmware():
@firmware.command()
@click.argument('fwfile', metavar='<firmware_file>', required=True)
@click.argument('port', metavar='<port_name>', required=True, default=None)
def download(fwfile, port):
@clicommon.pass_db
def download(db, fwfile, port):
"""Config muxcable firmware download"""

port = get_interface_alias(port, db)

per_npu_statedb = {}
y_cable_asic_table_keys = {}
port_table_keys = {}
Expand Down Expand Up @@ -751,9 +774,12 @@ def download(fwfile, port):

@firmware.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
def activate(port):
@clicommon.pass_db
def activate(db, port):
"""Config muxcable firmware activate"""

port = get_interface_alias(port, db)

per_npu_statedb = {}
y_cable_asic_table_keys = {}
port_table_keys = {}
Expand Down Expand Up @@ -800,9 +826,12 @@ def activate(port):

@firmware.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
def rollback(port):
@clicommon.pass_db
def rollback(db, port):
"""Config muxcable firmware rollback"""

port = get_interface_alias(port, db)

port_table_keys = {}
y_cable_asic_table_keys = {}
per_npu_statedb = {}
Expand Down
48 changes: 40 additions & 8 deletions show/muxcable.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
VENDOR_MODEL_REGEX = re.compile(r"CAC\w{3}321P2P\w{2}MS")


def get_interface_alias(port, db):

if port is not "all" and port is not None:
alias = port
iface_alias_converter = clicommon.InterfaceAliasConverter(db)
port = iface_alias_converter.alias_to_name(alias)
if port is None:
click.echo("cannot find port name for alias {}".format(alias))
sys.exit(STATUS_FAIL)

return port
jleveque marked this conversation as resolved.
Show resolved Hide resolved

#
# 'muxcable' command ("show muxcable")
#
Expand Down Expand Up @@ -129,9 +141,12 @@ def create_json_dump_per_port_config(port_status_dict, per_npu_configdb, asic_id
@muxcable.command()
@click.argument('port', required=False, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
def status(port, json_output):
@clicommon.pass_db
def status(db, port, json_output):
"""Show muxcable status information"""

port = get_interface_alias(port, db)

port_table_keys = {}
port_health_table_keys = {}
per_npu_statedb = {}
Expand Down Expand Up @@ -239,9 +254,12 @@ def status(port, json_output):
@muxcable.command()
@click.argument('port', required=False, default=None)
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL, help="display the output in json format")
def config(port, json_output):
@clicommon.pass_db
def config(db, port, json_output):
"""Show muxcable config information"""

port = get_interface_alias(port, db)

port_mux_tbl_keys = {}
asic_start_idx = None
per_npu_configdb = {}
Expand Down Expand Up @@ -407,9 +425,12 @@ def eyeinfo(port, target):

@muxcable.command()
@click.argument('port', required=True, default=None)
def cableinfo(port):
@clicommon.pass_db
def cableinfo(db, port):
"""Show muxcable cable information"""

port = get_interface_alias(port, db)

if platform_sfputil is not None:
physical_port_list = platform_sfputil_helper.logical_port_name_to_physical_port_list(port)

Expand Down Expand Up @@ -444,9 +465,12 @@ def hwmode():

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

port = get_interface_alias(port, db)

per_npu_statedb = {}
transceiver_table_keys = {}
transceiver_dict = {}
Expand Down Expand Up @@ -649,9 +673,11 @@ def muxdirection(port):

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

port = get_interface_alias(port, db)

per_npu_statedb = {}
transceiver_dict = {}

Expand Down Expand Up @@ -848,9 +874,12 @@ def firmware():
@firmware.command()
@click.argument('port', metavar='<port_name>', required=True, default=None)
@click.option('--active', 'active', required=False, is_flag=True, type=click.BOOL, help="display the firmware version of only active bank within MCU's")
def version(port, active):
@clicommon.pass_db
def version(db, port, active):
"""Show muxcable firmware version"""

port = get_interface_alias(port, db)

port_table_keys = {}
y_cable_asic_table_keys = {}
per_npu_statedb = {}
Expand Down Expand Up @@ -940,12 +969,16 @@ def version(port, active):
else:
click.echo("there is not a valid asic table for this asic_index".format(asic_index))


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

port = get_interface_alias(port, db)

metrics_table_keys = {}
per_npu_statedb = {}
metrics_dict = {}
Expand Down Expand Up @@ -981,7 +1014,6 @@ def metrics(port, json_output):
if asic_index is None:
click.echo("Got invalid asic index for port {}, cant retreive mux status".format(port))


metrics_dict[asic_index] = per_npu_statedb[asic_index].get_all(
per_npu_statedb[asic_index].STATE_DB, 'MUX_METRICS_TABLE|{}'.format(port))

Expand Down