Skip to content

Commit

Permalink
[config] Add checking of speed to "config interface speed" command
Browse files Browse the repository at this point in the history
* Checking whether the desired speed is one of standard Ethernet speed
  to reject setting unsupportable port speeds.

Signed-off-by: d-dashkov <[email protected]>
Signed-off-by: Maksym Belei <[email protected]>
  • Loading branch information
d-dashkov authored and Maksym Belei committed Jan 29, 2021
1 parent 8a1109e commit 26a7743
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 26a7743

Please sign in to comment.