From 558070cfde5157b3538b42085b9d0f775b3eb39d Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Fri, 29 Oct 2021 09:05:17 +0000 Subject: bgp: T3745: Sorting output show vpn ipsec sa --- src/op_mode/show_ipsec_sa.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/op_mode/show_ipsec_sa.py b/src/op_mode/show_ipsec_sa.py index 4e65daf1e..9955dead9 100755 --- a/src/op_mode/show_ipsec_sa.py +++ b/src/op_mode/show_ipsec_sa.py @@ -7,6 +7,13 @@ import subprocess import tabulate import hurry.filesize + +def convert(text): + return int(text) if text.isdigit() else text.lower() + +def alphanum_key(key): + return [convert(c) for c in re.split('([0-9]+)', str(key))] + def parse_conn_spec(s): try: # Example: ESTABLISHED 14 seconds ago, 10.0.0.2[foo]...10.0.0.1[10.0.0.1] @@ -85,6 +92,7 @@ for conn in connections: status_line = list(map(lambda x: "N/A" if x is None else x, status_line)) status_data.append(status_line) +status_data = sorted(status_data, key=alphanum_key) headers = ["Connection", "State", "Up", "Bytes In/Out", "Remote address", "Remote ID", "Proposal"] output = tabulate.tabulate(status_data, headers) print(output) -- cgit v1.2.3