Skip to content

Commit

Permalink
[config]: Add config acl add/remove table command (#541)
Browse files Browse the repository at this point in the history
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 <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng committed Jun 3, 2019
1 parent dcdc922 commit 635dc88
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,92 @@ def acl():
"""ACL-related configuration tasks"""
pass

#
# 'add' subgroup ('config acl add ...')
#

@acl.group()
def add():
"""
Add ACL configuration.
"""
pass


def get_acl_bound_ports():
config_db = ConfigDBConnector()
config_db.connect()

ports = set()
portchannel_members = set()

portchannel_member_dict = config_db.get_table("PORTCHANNEL_MEMBER")
for key in portchannel_member_dict:
ports.add(key[0])
portchannel_members.add(key[1])

port_dict = config_db.get_table("PORT")
for key in port_dict:
if key not in portchannel_members:
ports.add(key)

return list(ports)

#
# 'table' subcommand ('config acl add table ...')
#

@add.command()
@click.argument("table_name", metavar="<table_name>")
@click.argument("table_type", metavar="<table_type>")
@click.option("-d", "--description")
@click.option("-p", "--ports")
def table(table_name, table_type, description, ports):
"""
Add ACL table
"""
config_db = ConfigDBConnector()
config_db.connect()

table_info = {"type": table_type}

if description:
table_info["policy_desc"] = description
else:
table_info["policy_desc"] = table_name

if ports:
table_info["ports@"] = ports
else:
table_info["ports@"] = ",".join(get_acl_bound_ports())

config_db.set_entry("ACL_TABLE", table_name, table_info)

#
# 'remove' subgroup ('config acl remove ...')
#

@acl.group()
def remove():
"""
Remove ACL configuration.
"""
pass

#
# 'table' subcommand ('config acl remove table ...')
#

@remove.command()
@click.argument("table_name", metavar="<table_name>")
def table(table_name):
"""
Remove ACL table
"""
config_db = ConfigDBConnector()
config_db.connect()
config_db.set_entry("ACL_TABLE", table_name, None)


#
# 'acl update' group
Expand Down

0 comments on commit 635dc88

Please sign in to comment.