From d6928b933c7eb4772bb8afc08324c939e5bccc52 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Wed, 15 Nov 2023 12:47:09 +0100 Subject: [PATCH] statd: add speed to op data store and cli Signed-off-by: Richard Alpe --- board/netconf/rootfs/lib/infix/cli-pretty | 5 +++++ board/netconf/rootfs/lib/infix/yanger | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/board/netconf/rootfs/lib/infix/cli-pretty b/board/netconf/rootfs/lib/infix/cli-pretty index 5804b1c0..79d4fbe8 100755 --- a/board/netconf/rootfs/lib/infix/cli-pretty +++ b/board/netconf/rootfs/lib/infix/cli-pretty @@ -51,6 +51,7 @@ class Iface: self.autoneg = self.get_json_data('unknown', 'ieee802-ethernet-interface:ethernet', 'auto-negotiation', 'enable') self.duplex = self.get_json_data('', 'ieee802-ethernet-interface:ethernet', 'duplex') + self.speed = self.get_json_data('', 'ieee802-ethernet-interface:ethernet', 'speed') self.phys_address = data.get('phys-address', '') if data.get('statistics'): @@ -193,6 +194,10 @@ class Iface: if self.duplex: print(f"{'duplex':<{20}}: {self.duplex}") + if self.speed: + mbs = float(self.speed) * 1000 + print(f"{'speed':<{20}}: {int(mbs)}") + if self.phys_address: print(f"{'physical address':<{20}}: {self.phys_address}") diff --git a/board/netconf/rootfs/lib/infix/yanger b/board/netconf/rootfs/lib/infix/yanger index ac32547b..2edec772 100755 --- a/board/netconf/rootfs/lib/infix/yanger +++ b/board/netconf/rootfs/lib/infix/yanger @@ -290,7 +290,7 @@ def add_ethtool_groups(ifname, iface_out): def add_ethtool_std(ifname, iface_out): cmd = ['ethtool', ifname] - keys = ['Duplex', 'Auto-negotiation'] + keys = ['Speed', 'Duplex', 'Auto-negotiation'] result = {} lines = run_cmd(cmd) @@ -315,6 +315,13 @@ def add_ethtool_std(ifname, iface_out): else: insert(iface_out, "ieee802-ethernet-interface:ethernet", "duplex", "unknown") + if "Speed" in result and result['Speed'] != "Unknown!": + # Avoid importing re (performance) + num = ''.join(filter(str.isdigit, result['Speed'])) + if num: + num = round((int(num) / 1000), 3) + insert(iface_out, "ieee802-ethernet-interface:ethernet", "speed", str(num)) + if __name__ == "__main__": yang_data = { "ietf-interfaces:interfaces": {