From 991126c5083f46e533f890e8a9c2edf2b32edba9 Mon Sep 17 00:00:00 2001 From: Neetha John Date: Fri, 27 Aug 2021 17:35:27 -0700 Subject: [PATCH] Move common code to a function Signed-off-by: Neetha John --- scripts/ecnconfig | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/ecnconfig b/scripts/ecnconfig index 29be963396..7a59bc7d65 100755 --- a/scripts/ecnconfig +++ b/scripts/ecnconfig @@ -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() @@ -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:") @@ -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'