Skip to content

Commit 6ee0aea

Browse files
Shuotian Chengyxieca
Shuotian Cheng
authored andcommitted
[config]: Change the order of interface commands (#504)
before: config interface <interface_name> COMMANDS ... after: config interface COMMANDS <interface_name> ... To make backwards compatible with 201803 branch and older, change the order of the command arguments. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent 5ae30d2 commit 6ee0aea

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

config/main.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -832,34 +832,31 @@ def neighbor(ipaddr_or_hostname, verbose):
832832
#
833833

834834
@config.group()
835-
@click.argument('interface_name', metavar='<interface_name>', required=True)
836835
@click.pass_context
837-
def interface(ctx, interface_name):
836+
def interface(ctx):
838837
"""Interface-related configuration tasks"""
839838
config_db = ConfigDBConnector()
840839
config_db.connect()
841840
ctx.obj = {}
842841
ctx.obj['config_db'] = config_db
843-
if get_interface_naming_mode() == "alias":
844-
ctx.obj['interface_name'] = interface_alias_to_name(interface_name)
845-
if ctx.obj['interface_name'] is None:
846-
ctx.fail("'interface_name' is None!")
847-
else:
848-
ctx.obj['interface_name'] = interface_name
849842

850843
#
851844
# 'startup' subcommand
852845
#
853846

854847
@interface.command()
848+
@click.argument('interface_name', metavar='<interface_name>', required=True)
855849
@click.pass_context
856-
def startup(ctx):
850+
def startup(ctx, interface_name):
857851
"""Start up interface"""
858852
config_db = ctx.obj['config_db']
859-
interface_name = ctx.obj['interface_name']
853+
if get_interface_naming_mode() == "alias":
854+
interface_name = interface_alias_to_name(interface_name)
855+
if interface_name is None:
856+
ctx.fail("'interface_name' is None!")
860857

861858
if interface_name_is_valid(interface_name) is False:
862-
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
859+
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
863860

864861
if interface_name.startswith("Ethernet"):
865862
config_db.mod_entry("PORT", interface_name, {"admin_status": "up"})
@@ -870,14 +867,18 @@ def startup(ctx):
870867
#
871868

872869
@interface.command()
870+
@click.argument('interface_name', metavar='<interface_name>', required=True)
873871
@click.pass_context
874-
def shutdown(ctx):
872+
def shutdown(ctx, interface_name):
875873
"""Shut down interface"""
876874
config_db = ctx.obj['config_db']
877-
interface_name = ctx.obj['interface_name']
875+
if get_interface_naming_mode() == "alias":
876+
interface_name = interface_alias_to_name(interface_name)
877+
if interface_name is None:
878+
ctx.fail("'interface_name' is None!")
878879

879880
if interface_name_is_valid(interface_name) is False:
880-
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
881+
ctx.fail("Interface name is invalid. Please enter a valid interface name!!")
881882

882883
if interface_name.startswith("Ethernet"):
883884
config_db.mod_entry("PORT", interface_name, {"admin_status": "down"})
@@ -890,11 +891,15 @@ def shutdown(ctx):
890891

891892
@interface.command()
892893
@click.pass_context
894+
@click.argument('interface_name', metavar='<interface_name>', required=True)
893895
@click.argument('interface_speed', metavar='<interface_speed>', required=True)
894896
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
895-
def speed(ctx, interface_speed, verbose):
897+
def speed(ctx, interface_name, interface_speed, verbose):
896898
"""Set interface speed"""
897-
interface_name = ctx.obj['interface_name']
899+
if get_interface_naming_mode() == "alias":
900+
interface_name = interface_alias_to_name(interface_name)
901+
if interface_name is None:
902+
ctx.fail("'interface_name' is None!")
898903

899904
command = "portconfig -p {} -s {}".format(interface_name, interface_speed)
900905
if verbose:
@@ -916,12 +921,16 @@ def ip(ctx):
916921
#
917922

918923
@ip.command()
924+
@click.argument('interface_name', metavar='<interface_name>', required=True)
919925
@click.argument("ip_addr", metavar="<ip_addr>", required=True)
920926
@click.pass_context
921-
def add(ctx, ip_addr):
927+
def add(ctx, interface_name, ip_addr):
922928
"""Add an IP address towards the interface"""
923929
config_db = ctx.obj["config_db"]
924-
interface_name = ctx.obj["interface_name"]
930+
if get_interface_naming_mode() == "alias":
931+
interface_name = interface_alias_to_name(interface_name)
932+
if interface_name is None:
933+
ctx.fail("'interface_name' is None!")
925934

926935
if interface_name.startswith("Ethernet"):
927936
config_db.set_entry("INTERFACE", (interface_name, ip_addr), {"NULL": "NULL"})
@@ -935,12 +944,16 @@ def add(ctx, ip_addr):
935944
#
936945

937946
@ip.command()
947+
@click.argument('interface_name', metavar='<interface_name>', required=True)
938948
@click.argument("ip_addr", metavar="<ip_addr>", required=True)
939949
@click.pass_context
940-
def remove(ctx, ip_addr):
950+
def remove(ctx, interface_name, ip_addr):
941951
"""Remove an IP address from the interface"""
942952
config_db = ctx.obj["config_db"]
943-
interface_name = ctx.obj["interface_name"]
953+
if get_interface_naming_mode() == "alias":
954+
interface_name = interface_alias_to_name(interface_name)
955+
if interface_name is None:
956+
ctx.fail("'interface_name' is None!")
944957

945958
if interface_name.startswith("Ethernet"):
946959
config_db.set_entry("INTERFACE", (interface_name, ip_addr), None)

0 commit comments

Comments
 (0)