Skip to content

Commit 635dc88

Browse files
author
Shuotian Cheng
authored
[config]: Add config acl add/remove table command (#541)
Add below two commands: config acl add table <table_name> <table_type> config acl remove table <table_name> note: add table supports description and ports Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent dcdc922 commit 635dc88

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

config/main.py

+86
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,92 @@ def acl():
10051005
"""ACL-related configuration tasks"""
10061006
pass
10071007

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+
10081094

10091095
#
10101096
# 'acl update' group

0 commit comments

Comments
 (0)