cli: always sort lo first in 'show interfaces'

This fixes #545

Signed-off-by: Mattias Walström <lazzer@gmail.com>
This commit is contained in:
Mattias Walström
2024-08-16 16:32:22 +02:00
parent 8d6bf14937
commit c9ef775012
+14 -6
View File
@@ -438,10 +438,15 @@ def find_iface(_ifaces, name):
return False
def version_sort(iface):
return [int(x) if x.isdigit() else x for x in re.split(r'(\d+)', iface['name'])]
def print_interface(iface):
iface.pr_name()
iface.pr_proto_eth()
iface.pr_proto_ipv4()
iface.pr_proto_ipv6()
def pr_interface_list(json):
hdr = (f"{'INTERFACE':<{Pad.iface}}"
f"{'PROTOCOL':<{Pad.proto}}"
@@ -452,7 +457,14 @@ def pr_interface_list(json):
ifaces = sorted(json["ietf-interfaces:interfaces"]["interface"], key=version_sort)
iface = find_iface(ifaces, "lo")
if iface:
print_interface(iface)
for iface in [Iface(data) for data in ifaces]:
if iface.name == "lo":
continue
if iface.is_bridge():
iface.pr_bridge(ifaces)
continue
@@ -470,11 +482,7 @@ def pr_interface_list(json):
continue
if iface.bridge:
continue
iface.pr_name()
iface.pr_proto_eth()
iface.pr_proto_ipv4()
iface.pr_proto_ipv6()
print_interface(iface)
def show_interfaces(json, name):
if name: