diff options
author | l0crian1 <143656816+l0crian1@users.noreply.github.com> | 2024-04-05 08:48:15 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 08:48:15 -0400 |
commit | 4dba82c7517f4a93b9727d22104e4a339bad127a (patch) | |
tree | d1434b346cbef22423ed2872292ac70ca75883b8 /src/op_mode | |
parent | a7c5205ab12e767c6c60887033694c597e01f21b (diff) | |
download | vyos-1x-4dba82c7517f4a93b9727d22104e4a339bad127a.tar.gz vyos-1x-4dba82c7517f4a93b9727d22104e4a339bad127a.zip |
T6188: Add description to detail view only
For readability in console sessions, moved the description column to only be shown in the detail view.
Changed wrapping in the detail view for description to 65 characters to prevent full line wrapping in console sessions.
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/firewall.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/op_mode/firewall.py b/src/op_mode/firewall.py index aba6f2598..d4d7f9db5 100755 --- a/src/op_mode/firewall.py +++ b/src/op_mode/firewall.py @@ -93,7 +93,7 @@ def get_nftables_details(family, hook, priority): def output_firewall_vertical(rules, headers): for rule in rules: adjusted_rule = rule + [""] * (len(headers) - len(rule)) # account for different header length, like default-action - transformed_rule = [[header, textwrap.fill(adjusted_rule[i].replace('\n', ' '), 100)] for i, header in enumerate(headers)] # create key-pair list from headers and rules lists; wrap at 100 char + transformed_rule = [[header, textwrap.fill(adjusted_rule[i].replace('\n', ' '), 65)] for i, header in enumerate(headers)] # create key-pair list from headers and rules lists; wrap at 100 char print(tabulate.tabulate(transformed_rule, tablefmt="presto")) print() @@ -135,10 +135,13 @@ def output_firewall_name(family, hook, priority, firewall_conf, single_rule_id=N if args.rule: rows.pop() - header = ['Rule', 'Description', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] if args.detail: + header = ['Rule', 'Description', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] output_firewall_vertical(rows, header) else: + header = ['Rule', 'Action', 'Protocol', 'Packets', 'Bytes', 'Conditions'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header) + '\n') def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule_id=None): @@ -255,10 +258,13 @@ def output_firewall_name_statistics(family, hook, prior, prior_conf, single_rule rows.append(row) if rows: - header = ['Rule', 'Description', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] if args.detail: + header = ['Rule', 'Description', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] output_firewall_vertical(rows, header) else: + header = ['Rule', 'Packets', 'Bytes', 'Action', 'Source', 'Destination', 'Inbound-Interface', 'Outbound-interface'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header) + '\n') def show_firewall(): @@ -447,7 +453,6 @@ def show_firewall_group(name=None): return out - header = ['Name', 'Description','Type', 'References', 'Members'] rows = [] for group_type, group_type_conf in firewall['group'].items(): @@ -486,8 +491,12 @@ def show_firewall_group(name=None): if rows: print('Firewall Groups\n') if args.detail: + header = ['Name', 'Description','Type', 'References', 'Members'] output_firewall_vertical(rows, header) else: + header = ['Name', 'Type', 'References', 'Members'] + for i in rows: + rows[rows.index(i)].pop(1) print(tabulate.tabulate(rows, header)) def show_summary(): |