Skip to content

Commit 45eb491

Browse files
authored
[config] Add 'interface transceiver' subgroup with 'lpmode' and 'reset' subcommands (sonic-net#904)
1 parent a53bcf1 commit 45eb491

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

config/main.py

+51
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,57 @@ def remove(ctx, interface_name, ip_addr):
19701970
except ValueError:
19711971
ctx.fail("'ip_addr' is not valid.")
19721972

1973+
#
1974+
# 'transceiver' subgroup ('config interface transceiver ...')
1975+
#
1976+
1977+
@interface.group(cls=AbbreviationGroup)
1978+
@click.pass_context
1979+
def transceiver(ctx):
1980+
"""SFP transceiver configuration"""
1981+
pass
1982+
1983+
#
1984+
# 'lpmode' subcommand ('config interface transceiver lpmode ...')
1985+
#
1986+
1987+
@transceiver.command()
1988+
@click.argument('interface_name', metavar='<interface_name>', required=True)
1989+
@click.argument('state', metavar='(enable|disable)', type=click.Choice(['enable', 'disable']))
1990+
@click.pass_context
1991+
def lpmode(ctx, interface_name, state):
1992+
"""Enable/disable low-power mode for SFP transceiver module"""
1993+
if get_interface_naming_mode() == "alias":
1994+
interface_name = interface_alias_to_name(interface_name)
1995+
if interface_name is None:
1996+
ctx.fail("'interface_name' is None!")
1997+
1998+
if interface_name_is_valid(interface_name) is False:
1999+
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
2000+
2001+
cmd = "sudo sfputil lpmode {} {}".format("on" if state == "enable" else "off", interface_name)
2002+
run_command(cmd)
2003+
2004+
#
2005+
# 'reset' subcommand ('config interface reset ...')
2006+
#
2007+
2008+
@transceiver.command()
2009+
@click.argument('interface_name', metavar='<interface_name>', required=True)
2010+
@click.pass_context
2011+
def reset(ctx, interface_name):
2012+
"""Reset SFP transceiver module"""
2013+
if get_interface_naming_mode() == "alias":
2014+
interface_name = interface_alias_to_name(interface_name)
2015+
if interface_name is None:
2016+
ctx.fail("'interface_name' is None!")
2017+
2018+
if interface_name_is_valid(interface_name) is False:
2019+
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
2020+
2021+
cmd = "sudo sfputil reset {}".format(interface_name)
2022+
run_command(cmd)
2023+
19732024
#
19742025
# 'vrf' subgroup ('config interface vrf ...')
19752026
#

doc/Command-Reference.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ This sub-section explains the following list of configuration on the interfaces.
25302530
25312531
From 201904 release onwards, the “config interface” command syntax is changed and the format is as follows:
25322532
2533-
- config interface interface_subcommand <interface_name>
2533+
- config interface interface_subcommand <interface_name>
25342534
i.e Interface name comes after the subcommand
25352535
- Ex: config interface startup Ethernet63
25362536
@@ -2696,6 +2696,7 @@ This command is used to administratively shut down either the Physical interface
26962696
*Versions <= 201811*
26972697
```
26982698
config interface <interface_name> shutdown (for 201811- version)
2699+
```
26992700
27002701
- Example:
27012702
@@ -2723,6 +2724,7 @@ This command is used for administratively bringing up the Physical interface or
27232724
*Versions <= 201811*
27242725
```
27252726
config interface <interface_name> startup (for 201811- version)
2727+
```
27262728
27272729
- Example:
27282730
@@ -2761,6 +2763,44 @@ Dynamic breakout feature is yet to be supported in SONiC and hence uses cannot c
27612763
- Example (Versions <= 201811):
27622764
```
27632765
admin@sonic:~$ sudo config interface Ethernet63 speed 40000
2766+
2767+
```
2768+
2769+
**config interface transceiver lpmode**
2770+
2771+
This command is used to enable or disable low-power mode for an SFP transceiver
2772+
2773+
- Usage:
2774+
2775+
```
2776+
config interface transceiver lpmode <interface_name> (enable | disable)
2777+
```
2778+
2779+
- Examples:
2780+
2781+
```
2782+
user@sonic~$ sudo config interface transceiver lpmode Ethernet0 enable
2783+
Enabling low-power mode for port Ethernet0... OK
2784+
2785+
user@sonic~$ sudo config interface transceiver lpmode Ethernet0 disable
2786+
Disabling low-power mode for port Ethernet0... OK
2787+
```
2788+
2789+
**config interface transceiver reset**
2790+
2791+
This command is used to reset an SFP transceiver
2792+
2793+
- Usage:
2794+
2795+
```
2796+
config interface transceiver reset <interface_name>
2797+
```
2798+
2799+
- Examples:
2800+
2801+
```
2802+
user@sonic~$ sudo config interface transceiver reset Ethernet0
2803+
Resetting port Ethernet0... OK
27642804
```
27652805
27662806
**config interface mtu <interface_name> (Versions >= 201904)**

0 commit comments

Comments
 (0)