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 <richard@bit42.se>
This commit is contained in:
Richard Alpe
2023-11-06 20:12:16 +01:00
committed by Joachim Wiberg
parent 5b58c60919
commit ff7b8ec9bf
2 changed files with 16 additions and 13 deletions
+14 -12
View File
@@ -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:
+2 -1
View File
@@ -240,7 +240,8 @@
</SWITCH>
<ACTION sym="script" interactive="false">
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 | \