From f2919a2e44e69a160035c998d36762c9d2b225ec Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Tue, 7 Nov 2023 16:16:38 +0100 Subject: [PATCH] cli: handle missing type and phys-address gracefully Avoid crashing if they are missing from the input data. Signed-off-by: Richard Alpe --- board/netconf/rootfs/lib/infix/cli-pretty | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/board/netconf/rootfs/lib/infix/cli-pretty b/board/netconf/rootfs/lib/infix/cli-pretty index 5fb56b1c..84b6f15c 100755 --- a/board/netconf/rootfs/lib/infix/cli-pretty +++ b/board/netconf/rootfs/lib/infix/cli-pretty @@ -45,6 +45,7 @@ class Iface: def __init__(self, data): self.data = data self.name = data.get('name', '') + self.type = data.get('type', '') self.index = data.get('if-index', '') self.oper_status = data.get('oper-status', '') self.autoneg = self.get_json_data('unknown', 'ieee802-ethernet-interface:ethernet', @@ -81,10 +82,10 @@ class Iface: self.lower_if = '' def is_vlan(self): - return self.data['type'] == "infix-if-type:vlan" + return self.type == "infix-if-type:vlan" def is_bridge(self): - return self.data['type'] == "infix-if-type:bridge" + return self.type == "infix-if-type:bridge" def is_veth(self): return self.data['type'] == "infix-if-type:veth" @@ -115,7 +116,7 @@ class Iface: row = f"{'ethernet':<{Pad.proto}}" dec = Decore.green if self.oper_status == "up" else Decore.red row += dec(f"{self.oper_status.upper():<{Pad.state}}") - row += f"{self.data['phys-address']:<{Pad.data}}" + row += f"{self.phys_address:<{Pad.data}}" print(row) def pr_bridge(self, _ifaces):