From 83b88d5e6f44c089020cff2828c804b3aa9c3adf Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sat, 9 May 2020 14:45:51 -0700 Subject: [PATCH] [config] Add 'interface transceiver' subgroup with 'lpmode' and 'reset' subcommands (#904) --- config/main.py | 51 ++++++++++++++++++++++++++++++++++++++++ doc/Command-Reference.md | 42 ++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index bf05dfa3f8..c08794fc90 100755 --- a/config/main.py +++ b/config/main.py @@ -1832,6 +1832,57 @@ def remove(ctx, interface_name, ip_addr): except ValueError: ctx.fail("'ip_addr' is not valid.") +# +# 'transceiver' subgroup ('config interface transceiver ...') +# + +@interface.group(cls=AbbreviationGroup) +@click.pass_context +def transceiver(ctx): + """SFP transceiver configuration""" + pass + +# +# 'lpmode' subcommand ('config interface transceiver lpmode ...') +# + +@transceiver.command() +@click.argument('interface_name', metavar='', required=True) +@click.argument('state', metavar='(enable|disable)', type=click.Choice(['enable', 'disable'])) +@click.pass_context +def lpmode(ctx, interface_name, state): + """Enable/disable low-power mode for SFP transceiver module""" + if get_interface_naming_mode() == "alias": + interface_name = interface_alias_to_name(interface_name) + if interface_name is None: + ctx.fail("'interface_name' is None!") + + if interface_name_is_valid(interface_name) is False: + ctx.fail("Interface name is invalid. Please enter a valid interface name!!") + + cmd = "sudo sfputil lpmode {} {}".format("on" if state == "enable" else "off", interface_name) + run_command(cmd) + +# +# 'reset' subcommand ('config interface reset ...') +# + +@transceiver.command() +@click.argument('interface_name', metavar='', required=True) +@click.pass_context +def reset(ctx, interface_name): + """Reset SFP transceiver module""" + if get_interface_naming_mode() == "alias": + interface_name = interface_alias_to_name(interface_name) + if interface_name is None: + ctx.fail("'interface_name' is None!") + + if interface_name_is_valid(interface_name) is False: + ctx.fail("Interface name is invalid. Please enter a valid interface name!!") + + cmd = "sudo sfputil reset {}".format(interface_name) + run_command(cmd) + # # 'vrf' subgroup ('config interface vrf ...') # diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 0e67456edd..01c15b4233 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -2381,7 +2381,7 @@ This sub-section explains the following list of configuration on the interfaces. From 201904 release onwards, the “config interface” command syntax is changed and the format is as follows: -- config interface interface_subcommand +- config interface interface_subcommand i.e Interface name comes after the subcommand - Ex: config interface startup Ethernet63 @@ -2516,6 +2516,7 @@ This command is used to administratively shut down either the Physical interface *Versions <= 201811* ``` config interface shutdown (for 201811- version) + ``` - Example: @@ -2543,6 +2544,7 @@ This command is used for administratively bringing up the Physical interface or *Versions <= 201811* ``` config interface startup (for 201811- version) + ``` - Example: @@ -2581,6 +2583,44 @@ Dynamic breakout feature is yet to be supported in SONiC and hence uses cannot c - Example (Versions <= 201811): ``` admin@sonic:~$ sudo config interface Ethernet63 speed 40000 + + ``` + +**config interface transceiver lpmode** + +This command is used to enable or disable low-power mode for an SFP transceiver + +- Usage: + + ``` + config interface transceiver lpmode (enable | disable) + ``` + +- Examples: + + ``` + user@sonic~$ sudo config interface transceiver lpmode Ethernet0 enable + Enabling low-power mode for port Ethernet0... OK + + user@sonic~$ sudo config interface transceiver lpmode Ethernet0 disable + Disabling low-power mode for port Ethernet0... OK + ``` + +**config interface transceiver reset** + +This command is used to reset an SFP transceiver + +- Usage: + + ``` + config interface transceiver reset + ``` + +- Examples: + + ``` + user@sonic~$ sudo config interface transceiver reset Ethernet0 + Resetting port Ethernet0... OK ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)