Skip to content

[config] Add checking of speed to "config interface speed" command #1391

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
17 changes: 16 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@
PORT_MTU = "mtu"
PORT_SPEED = "speed"

ALLOWED_PORT_SPEED_LIST = [1000, # 1G
2500, # 2.5G
5000, # 5G
10000, # 10G
25000, # 25G
40000, # 40G
50000, # 50G
100000, # 100G
200000, # 200G
400000] # 400G


asic_type = None

#
Expand Down Expand Up @@ -2389,13 +2401,16 @@ def shutdown(ctx, interface_name):
@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_speed', metavar='<interface_speed>', required=True)
@click.argument('interface_speed', metavar='<interface_speed>', required=True, type=click.IntRange(1000, 400000))
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def speed(ctx, interface_name, interface_speed, verbose):
"""Set interface speed"""
# Get the config_db connector
config_db = ctx.obj['config_db']

if interface_speed not in ALLOWED_PORT_SPEED_LIST:
ctx.fail(f"The speed {interface_speed} is not allowed. Allowed values: {ALLOWED_PORT_SPEED_LIST}")

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
Expand Down