From ff7b8ec9bf12e30cac9b19b858bd0d2bb58d21ff Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Mon, 6 Nov 2023 11:30:49 +0100 Subject: [PATCH] cli: speedup detailed interface view This affects CLI command such as: > show interface name p1 Prior to this patch, this took roughly ~1200ms on hardware and with the path it takes roughly 50ms. Signed-off-by: Richard Alpe --- board/netconf/rootfs/lib/infix/cli-pretty | 26 ++++++++++++----------- src/klish-plugin-infix/xml/infix.xml | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/board/netconf/rootfs/lib/infix/cli-pretty b/board/netconf/rootfs/lib/infix/cli-pretty index cca1f729..5fb56b1c 100755 --- a/board/netconf/rootfs/lib/infix/cli-pretty +++ b/board/netconf/rootfs/lib/infix/cli-pretty @@ -272,18 +272,20 @@ def pr_interface_list(json): iface.pr_proto_ipv6() def ietf_interfaces(json, name): - if not json or not json.get("ietf-interfaces:interfaces"): - print(f"Error, top level \"ietf-interfaces:interfaces\" missing") - sys.exit(1) - - if not name: - return pr_interface_list(json) - - iface = find_iface(json["ietf-interfaces:interfaces"]["interface"], name) - if not iface: - print(f"Interface {name} not found") - sys.exit(1) - return iface.pr_iface() + if name: + if not json.get("ietf-interfaces:interfaces"): + print(f"No interface data found for \"{name}\"") + sys.exit(1) + iface = find_iface(json["ietf-interfaces:interfaces"]["interface"], name) + if not iface: + print(f"Interface \"{name}\" not found") + sys.exit(1) + iface.pr_iface() + else: + if not json.get("ietf-interfaces:interfaces"): + print(f"Error, top level \"ietf-interfaces:interfaces\" missing") + sys.exit(1) + pr_interface_list(json) def main(): try: diff --git a/src/klish-plugin-infix/xml/infix.xml b/src/klish-plugin-infix/xml/infix.xml index 536de376..438114f2 100644 --- a/src/klish-plugin-infix/xml/infix.xml +++ b/src/klish-plugin-infix/xml/infix.xml @@ -240,7 +240,8 @@ if [ -n "$KLISH_PARAM_name" ]; then - sysrepocfg -f json -X -d operational -m ietf-interfaces | \ + sysrepocfg -f json -X -d operational -x \ + "/ietf-interfaces:interfaces/interface[name='$KLISH_PARAM_name']" | \ /lib/infix/cli-pretty "ietf-interfaces" -n "$KLISH_PARAM_name" else sysrepocfg -f json -X -d operational -m ietf-interfaces | \