From 16af2fbd4d6995d9842a3281be0b36e67fea2cca Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 5 May 2020 04:41:57 +0000 Subject: [PATCH 1/4] [config] Add 'interface transceiver' subgroup with 'lpmode' and 'reset' subcommands --- config/main.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/config/main.py b/config/main.py index 617d155d95..dbc54bc43b 100755 --- a/config/main.py +++ b/config/main.py @@ -1947,6 +1947,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', type=click.Choice(['enable', 'disable'])) +@click.pass_context +def lpmode(ctx, interface_name, state): + """Enable/disable low-power mode for transceiver""" + 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 transceiver""" + 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 ...') # From 2dc8ab3de7fdbdc542d9eaea1dd2367372227fad Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 5 May 2020 06:43:25 +0000 Subject: [PATCH 2/4] Add metavar to display options for lpmode state --- config/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index dbc54bc43b..86a2d3b3bb 100755 --- a/config/main.py +++ b/config/main.py @@ -1963,7 +1963,7 @@ def transceiver(ctx): @transceiver.command() @click.argument('interface_name', metavar='', required=True) -@click.argument('state', type=click.Choice(['enable', 'disable'])) +@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 transceiver""" From dbcb1376174c4b5740db42a64b2b03f35f65aad2 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 5 May 2020 06:43:47 +0000 Subject: [PATCH 3/4] Add documentation for new commands --- doc/Command-Reference.md | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 612158d8b1..785eab0af6 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -2501,7 +2501,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 @@ -2667,6 +2667,7 @@ This command is used to administratively shut down either the Physical interface *Versions <= 201811* ``` config interface shutdown (for 201811- version) + ``` - Example: @@ -2694,6 +2695,7 @@ This command is used for administratively bringing up the Physical interface or *Versions <= 201811* ``` config interface startup (for 201811- version) + ``` - Example: @@ -2732,6 +2734,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 ``` **config interface mtu (Versions >= 201904)** From 3319a38c44ec92668c7dac5a316b3cf6e5306056 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 5 May 2020 06:46:59 +0000 Subject: [PATCH 4/4] Add detail to docstrings --- config/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/main.py b/config/main.py index 86a2d3b3bb..2d6705ea25 100755 --- a/config/main.py +++ b/config/main.py @@ -1966,7 +1966,7 @@ def transceiver(ctx): @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 transceiver""" + """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: @@ -1986,7 +1986,7 @@ def lpmode(ctx, interface_name, state): @click.argument('interface_name', metavar='', required=True) @click.pass_context def reset(ctx, interface_name): - """Reset transceiver""" + """Reset SFP transceiver module""" if get_interface_naming_mode() == "alias": interface_name = interface_alias_to_name(interface_name) if interface_name is None: