@@ -1024,6 +1024,19 @@ def validate_ipv4_address(ctx, param, ip_addr):
1024
1024
except ValueError as e :
1025
1025
raise click .UsageError (str (e ))
1026
1026
1027
+ def validate_gre_type (ctx , _ , value ):
1028
+ """A validator for validating input gre_type
1029
+ """
1030
+ try :
1031
+ base = 10
1032
+ if value .lower ().startswith ('0x' ):
1033
+ base = 16
1034
+ gre_type_value = int (value , base )
1035
+ if gre_type_value < GRE_TYPE_RANGE .min or gre_type_value > GRE_TYPE_RANGE .max :
1036
+ raise click .UsageError ("{} is not a valid GRE type" .format (value ))
1037
+ return gre_type_value
1038
+ except ValueError :
1039
+ raise click .UsageError ("{} is not a valid GRE type" .format (value ))
1027
1040
1028
1041
# This is our main entrypoint - the main 'config' command
1029
1042
@click .group (cls = clicommon .AbbreviationGroup , context_settings = CONTEXT_SETTINGS )
@@ -1790,11 +1803,11 @@ def add_portchannel_member(ctx, portchannel_name, port_name):
1790
1803
ctx .fail ("{} is not present." .format (portchannel_name ))
1791
1804
1792
1805
# Dont allow a port to be member of port channel if it is configured with an IP address
1793
- for key in db .get_table ('INTERFACE' ).keys ():
1794
- if type (key ) ! = tuple :
1806
+ for key , value in db .get_table ('INTERFACE' ).items ():
1807
+ if type (key ) = = tuple :
1795
1808
continue
1796
- if key [ 0 ] == port_name :
1797
- ctx .fail (" {} has ip address {} configured" .format (port_name , key [ 1 ] ))
1809
+ if key == port_name :
1810
+ ctx .fail (" {} has ip address configured" .format (port_name ))
1798
1811
return
1799
1812
1800
1813
# Dont allow a port to be member of port channel if it is configured as a VLAN member
@@ -1893,7 +1906,7 @@ def mirror_session():
1893
1906
@click .argument ('dst_ip' , metavar = '<dst_ip>' , callback = validate_ipv4_address , required = True )
1894
1907
@click .argument ('dscp' , metavar = '<dscp>' , type = DSCP_RANGE , required = True )
1895
1908
@click .argument ('ttl' , metavar = '<ttl>' , type = TTL_RANGE , required = True )
1896
- @click .argument ('gre_type' , metavar = '[gre_type]' , type = GRE_TYPE_RANGE , required = False )
1909
+ @click .argument ('gre_type' , metavar = '[gre_type]' , callback = validate_gre_type , required = False )
1897
1910
@click .argument ('queue' , metavar = '[queue]' , type = QUEUE_RANGE , required = False )
1898
1911
@click .option ('--policer' )
1899
1912
def add (session_name , src_ip , dst_ip , dscp , ttl , gre_type , queue , policer ):
@@ -1917,7 +1930,7 @@ def erspan(ctx):
1917
1930
@click .argument ('dst_ip' , metavar = '<dst_ip>' , callback = validate_ipv4_address ,required = True )
1918
1931
@click .argument ('dscp' , metavar = '<dscp>' , type = DSCP_RANGE , required = True )
1919
1932
@click .argument ('ttl' , metavar = '<ttl>' , type = TTL_RANGE , required = True )
1920
- @click .argument ('gre_type' , metavar = '[gre_type]' , type = GRE_TYPE_RANGE , required = False )
1933
+ @click .argument ('gre_type' , metavar = '[gre_type]' , callback = validate_gre_type , required = False )
1921
1934
@click .argument ('queue' , metavar = '[queue]' , type = QUEUE_RANGE , required = False )
1922
1935
@click .argument ('src_port' , metavar = '[src_port]' , required = False )
1923
1936
@click .argument ('direction' , metavar = '[direction]' , required = False )
0 commit comments