summaryrefslogtreecommitdiff
path: root/src/op_mode/route.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2023-01-15 20:31:13 +0000
committerGitHub <noreply@github.com>2023-01-15 20:31:13 +0000
commit6c9c4144df327d6c27d559c8a0c14317da3a2588 (patch)
treec81dc2c6036e893cc5a19bb24d144821dda60a91 /src/op_mode/route.py
parentc9a92b01fab00d656ce3be5702634e76bcab6a23 (diff)
parent65fa4e55074652ec65b21eff457faa8f4adc9a1a (diff)
downloadvyos-1x-6c9c4144df327d6c27d559c8a0c14317da3a2588.tar.gz
vyos-1x-6c9c4144df327d6c27d559c8a0c14317da3a2588.zip
Merge pull request #1753 from dmbaturin/ipv6-route-summary
opmode: T4837: add family and table arguments for ShowRoute
Diffstat (limited to 'src/op_mode/route.py')
-rwxr-xr-xsrc/op_mode/route.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/op_mode/route.py b/src/op_mode/route.py
index d07a34180..6942fba89 100755
--- a/src/op_mode/route.py
+++ b/src/op_mode/route.py
@@ -54,16 +54,35 @@ frr_command_template = Template("""
{% endif %}
""")
-def show_summary(raw: bool):
+def show_summary(raw: bool, family: str, table: typing.Optional[int]):
from vyos.util import cmd
+ if family == 'inet':
+ family_cmd = 'ip'
+ elif family == 'inet6':
+ family_cmd = 'ipv6'
+ else:
+ raise ValueError(f"Usupported address family {family}")
+
+ # Replace with Jinja if it ever starts growing
+ if table:
+ table_command = f"table {table}"
+ else:
+ table_command = ""
+
if raw:
from json import loads
- output = cmd(f"vtysh -c 'show ip route summary json'")
- return loads(output)
+ output = cmd(f"vtysh -c 'show {family_cmd} route summary {table_command} json'").strip()
+
+ # If there are no routes in a table, its "JSON" output is an empty string,
+ # as of FRR 8.4.1
+ if output:
+ return loads(output)
+ else:
+ return {}
else:
- output = cmd(f"vtysh -c 'show ip route summary'")
+ output = cmd(f"vtysh -c 'show {family_cmd} route summary {table_command}'")
return output
def show(raw: bool,