Skip to content

Commit 557248d

Browse files
Shuotian Chenglguohan
Shuotian Cheng
authored andcommitted
[acl-loader]: Add --table_name option to update full operation (sonic-net#249)
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]>
1 parent a8aadee commit 557248d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

acl_loader/main.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class AclLoader(object):
7878
def __init__(self):
7979
self.yang_acl = None
8080
self.requested_session = None
81+
self.current_table = None
8182
self.tables_db_info = {}
8283
self.rules_db_info = {}
8384
self.rules_info = {}
@@ -146,10 +147,19 @@ def get_session_name(self):
146147

147148
return None
148149

150+
def set_table_name(self, table_name):
151+
"""
152+
Set table name to restrict the table to be modified
153+
:param table_name: Table name
154+
:return:
155+
"""
156+
self.current_table = table_name
157+
149158
def set_session_name(self, session_name):
150159
"""
151-
Set session name to se used in ACL rule action.
160+
Set session name to be used in ACL rule action
152161
:param session_name: Mirror session name
162+
:return:
153163
"""
154164
if session_name not in self.get_sessions_db_info():
155165
raise AclLoaderException("Session %s does not exist" % session_name)
@@ -356,6 +366,9 @@ def convert_rules(self):
356366
warning("%s table does not exist" % (table_name))
357367
continue
358368

369+
if self.current_table is not None and self.current_table != table_name
370+
continue
371+
359372
for acl_entry_name in acl_set.acl_entries.acl_entry:
360373
acl_entry = acl_set.acl_entries.acl_entry[acl_entry_name]
361374
try:
@@ -370,11 +383,14 @@ def convert_rules(self):
370383
def full_update(self):
371384
"""
372385
Perform full update of ACL rules configuration. All existing rules
373-
will be removed. New rules loaded from file will be installed.
386+
will be removed. New rules loaded from file will be installed. If
387+
the current_table is not empty, only rules within that table will
388+
be removed and new rules in that table will be installed.
374389
:return:
375390
"""
376391
for key in self.rules_db_info.keys():
377-
self.configdb.mod_entry(self.ACL_RULE, key, None)
392+
if self.current_table is None or self.current_table == key[0]:
393+
self.configdb.mod_entry(self.ACL_RULE, key, None)
378394

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

@@ -593,15 +609,20 @@ def update(ctx):
593609

594610
@update.command()
595611
@click.argument('filename', type=click.Path(exists=True))
612+
@click.option('--table_name', type=click.STRING, required=False)
596613
@click.option('--session_name', type=click.STRING, required=False)
597614
@click.option('--max_priority', type=click.INT, required=False)
598615
@click.pass_context
599-
def full(ctx, filename, session_name, max_priority):
616+
def full(ctx, filename, table_name, session_name, max_priority):
600617
"""
601618
Full update of ACL rules configuration.
619+
If a table_name is provided, the operation will be restricted in the specified table.
602620
"""
603621
acl_loader = ctx.obj["acl_loader"]
604622

623+
if table_name:
624+
acl_loader.set_table_name(table_name)
625+
605626
if session_name:
606627
acl_loader.set_session_name(session_name)
607628

0 commit comments

Comments
 (0)