@@ -1005,6 +1005,92 @@ def acl():
1005
1005
"""ACL-related configuration tasks"""
1006
1006
pass
1007
1007
1008
+ #
1009
+ # 'add' subgroup ('config acl add ...')
1010
+ #
1011
+
1012
+ @acl .group ()
1013
+ def add ():
1014
+ """
1015
+ Add ACL configuration.
1016
+ """
1017
+ pass
1018
+
1019
+
1020
+ def get_acl_bound_ports ():
1021
+ config_db = ConfigDBConnector ()
1022
+ config_db .connect ()
1023
+
1024
+ ports = set ()
1025
+ portchannel_members = set ()
1026
+
1027
+ portchannel_member_dict = config_db .get_table ("PORTCHANNEL_MEMBER" )
1028
+ for key in portchannel_member_dict :
1029
+ ports .add (key [0 ])
1030
+ portchannel_members .add (key [1 ])
1031
+
1032
+ port_dict = config_db .get_table ("PORT" )
1033
+ for key in port_dict :
1034
+ if key not in portchannel_members :
1035
+ ports .add (key )
1036
+
1037
+ return list (ports )
1038
+
1039
+ #
1040
+ # 'table' subcommand ('config acl add table ...')
1041
+ #
1042
+
1043
+ @add .command ()
1044
+ @click .argument ("table_name" , metavar = "<table_name>" )
1045
+ @click .argument ("table_type" , metavar = "<table_type>" )
1046
+ @click .option ("-d" , "--description" )
1047
+ @click .option ("-p" , "--ports" )
1048
+ def table (table_name , table_type , description , ports ):
1049
+ """
1050
+ Add ACL table
1051
+ """
1052
+ config_db = ConfigDBConnector ()
1053
+ config_db .connect ()
1054
+
1055
+ table_info = {"type" : table_type }
1056
+
1057
+ if description :
1058
+ table_info ["policy_desc" ] = description
1059
+ else :
1060
+ table_info ["policy_desc" ] = table_name
1061
+
1062
+ if ports :
1063
+ table_info ["ports@" ] = ports
1064
+ else :
1065
+ table_info ["ports@" ] = "," .join (get_acl_bound_ports ())
1066
+
1067
+ config_db .set_entry ("ACL_TABLE" , table_name , table_info )
1068
+
1069
+ #
1070
+ # 'remove' subgroup ('config acl remove ...')
1071
+ #
1072
+
1073
+ @acl .group ()
1074
+ def remove ():
1075
+ """
1076
+ Remove ACL configuration.
1077
+ """
1078
+ pass
1079
+
1080
+ #
1081
+ # 'table' subcommand ('config acl remove table ...')
1082
+ #
1083
+
1084
+ @remove .command ()
1085
+ @click .argument ("table_name" , metavar = "<table_name>" )
1086
+ def table (table_name ):
1087
+ """
1088
+ Remove ACL table
1089
+ """
1090
+ config_db = ConfigDBConnector ()
1091
+ config_db .connect ()
1092
+ config_db .set_entry ("ACL_TABLE" , table_name , None )
1093
+
1008
1094
1009
1095
#
1010
1096
# 'acl update' group
0 commit comments