Skip to content

Commit

Permalink
[acl-loader]: Add --table_name option to update full operation (#249)
Browse files Browse the repository at this point in the history
This option enables the ability to only do the full update within
this table, which means that only this table will be cleared and
reinstalled with the new rules from the JSON file.

Signed-off-by: Shu0T1an ChenG <[email protected]>
  • Loading branch information
Shuotian Cheng authored and lguohan committed May 10, 2018
1 parent a8aadee commit 557248d
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AclLoader(object):
def __init__(self):
self.yang_acl = None
self.requested_session = None
self.current_table = None
self.tables_db_info = {}
self.rules_db_info = {}
self.rules_info = {}
Expand Down Expand Up @@ -146,10 +147,19 @@ def get_session_name(self):

return None

def set_table_name(self, table_name):
"""
Set table name to restrict the table to be modified
:param table_name: Table name
:return:
"""
self.current_table = table_name

def set_session_name(self, session_name):
"""
Set session name to se used in ACL rule action.
Set session name to be used in ACL rule action
:param session_name: Mirror session name
:return:
"""
if session_name not in self.get_sessions_db_info():
raise AclLoaderException("Session %s does not exist" % session_name)
Expand Down Expand Up @@ -356,6 +366,9 @@ def convert_rules(self):
warning("%s table does not exist" % (table_name))
continue

if self.current_table is not None and self.current_table != table_name
continue

for acl_entry_name in acl_set.acl_entries.acl_entry:
acl_entry = acl_set.acl_entries.acl_entry[acl_entry_name]
try:
Expand All @@ -370,11 +383,14 @@ def convert_rules(self):
def full_update(self):
"""
Perform full update of ACL rules configuration. All existing rules
will be removed. New rules loaded from file will be installed.
will be removed. New rules loaded from file will be installed. If
the current_table is not empty, only rules within that table will
be removed and new rules in that table will be installed.
:return:
"""
for key in self.rules_db_info.keys():
self.configdb.mod_entry(self.ACL_RULE, key, None)
if self.current_table is None or self.current_table == key[0]:
self.configdb.mod_entry(self.ACL_RULE, key, None)

self.configdb.mod_config({self.ACL_RULE: self.rules_info})

Expand Down Expand Up @@ -593,15 +609,20 @@ def update(ctx):

@update.command()
@click.argument('filename', type=click.Path(exists=True))
@click.option('--table_name', type=click.STRING, required=False)
@click.option('--session_name', type=click.STRING, required=False)
@click.option('--max_priority', type=click.INT, required=False)
@click.pass_context
def full(ctx, filename, session_name, max_priority):
def full(ctx, filename, table_name, session_name, max_priority):
"""
Full update of ACL rules configuration.
If a table_name is provided, the operation will be restricted in the specified table.
"""
acl_loader = ctx.obj["acl_loader"]

if table_name:
acl_loader.set_table_name(table_name)

if session_name:
acl_loader.set_session_name(session_name)

Expand Down

0 comments on commit 557248d

Please sign in to comment.