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'