@@ -832,34 +832,31 @@ def neighbor(ipaddr_or_hostname, verbose):
832
832
#
833
833
834
834
@config .group ()
835
- @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
836
835
@click .pass_context
837
- def interface (ctx , interface_name ):
836
+ def interface (ctx ):
838
837
"""Interface-related configuration tasks"""
839
838
config_db = ConfigDBConnector ()
840
839
config_db .connect ()
841
840
ctx .obj = {}
842
841
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
849
842
850
843
#
851
844
# 'startup' subcommand
852
845
#
853
846
854
847
@interface .command ()
848
+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
855
849
@click .pass_context
856
- def startup (ctx ):
850
+ def startup (ctx , interface_name ):
857
851
"""Start up interface"""
858
852
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!" )
860
857
861
858
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!!" )
863
860
864
861
if interface_name .startswith ("Ethernet" ):
865
862
config_db .mod_entry ("PORT" , interface_name , {"admin_status" : "up" })
@@ -870,14 +867,18 @@ def startup(ctx):
870
867
#
871
868
872
869
@interface .command ()
870
+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
873
871
@click .pass_context
874
- def shutdown (ctx ):
872
+ def shutdown (ctx , interface_name ):
875
873
"""Shut down interface"""
876
874
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!" )
878
879
879
880
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!!" )
881
882
882
883
if interface_name .startswith ("Ethernet" ):
883
884
config_db .mod_entry ("PORT" , interface_name , {"admin_status" : "down" })
@@ -890,11 +891,15 @@ def shutdown(ctx):
890
891
891
892
@interface .command ()
892
893
@click .pass_context
894
+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
893
895
@click .argument ('interface_speed' , metavar = '<interface_speed>' , required = True )
894
896
@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 ):
896
898
"""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!" )
898
903
899
904
command = "portconfig -p {} -s {}" .format (interface_name , interface_speed )
900
905
if verbose :
@@ -916,12 +921,16 @@ def ip(ctx):
916
921
#
917
922
918
923
@ip .command ()
924
+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
919
925
@click .argument ("ip_addr" , metavar = "<ip_addr>" , required = True )
920
926
@click .pass_context
921
- def add (ctx , ip_addr ):
927
+ def add (ctx , interface_name , ip_addr ):
922
928
"""Add an IP address towards the interface"""
923
929
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!" )
925
934
926
935
if interface_name .startswith ("Ethernet" ):
927
936
config_db .set_entry ("INTERFACE" , (interface_name , ip_addr ), {"NULL" : "NULL" })
@@ -935,12 +944,16 @@ def add(ctx, ip_addr):
935
944
#
936
945
937
946
@ip .command ()
947
+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
938
948
@click .argument ("ip_addr" , metavar = "<ip_addr>" , required = True )
939
949
@click .pass_context
940
- def remove (ctx , ip_addr ):
950
+ def remove (ctx , interface_name , ip_addr ):
941
951
"""Remove an IP address from the interface"""
942
952
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!" )
944
957
945
958
if interface_name .startswith ("Ethernet" ):
946
959
config_db .set_entry ("INTERFACE" , (interface_name , ip_addr ), None )
0 commit comments