Skip to content

Commit

Permalink
Move common code to a function
Browse files Browse the repository at this point in the history
Signed-off-by: Neetha John <[email protected]>
  • Loading branch information
neethajohn committed Aug 28, 2021
1 parent 4bb413f commit 991126c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions scripts/ecnconfig
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ class EcnQ(object):
key = lambda k: int(k[8:]) if "BP" not in k else int(k[11:]) + 1024
)

def dump_table_info(self):
if self.filename is not None:
q_table = self.config_db.get_table(QUEUE_TABLE_NAME)
with open(self.filename, "w") as fd:
json.dump({repr(x):y for x, y in q_table.items()}, fd)

def set(self, enable):
chk_exec_privilege()

Expand All @@ -240,10 +246,7 @@ class EcnQ(object):
for port_key in self.ports_key:
key = '|'.join([port_key, queue])
self.config_db.mod_entry(QUEUE_TABLE_NAME, key, {FIELD: ON if enable else OFF})
if self.filename is not None:
q_table = self.config_db.get_table(QUEUE_TABLE_NAME)
with open(self.filename, "w") as fd:
json.dump({repr(x):y for x, y in q_table.items()}, fd)
self.dump_table_info()

def get(self):
print("ECN status:")
Expand All @@ -261,11 +264,7 @@ class EcnQ(object):
print("%s: on" % (out))
else:
print("%s: off" % (out))

if self.filename is not None:
q_table = self.config_db.get_table(QUEUE_TABLE_NAME)
with open(self.filename, "w") as fd:
json.dump({repr(x):y for x, y in q_table.items()}, fd)
self.dump_table_info()

def main():
parser = argparse.ArgumentParser(description='Show and change:\n'
Expand Down

0 comments on commit 991126c

Please sign in to comment.