summaryrefslogtreecommitdiff
path: root/src/op_mode/route.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2023-01-16 18:00:54 +0000
committerGitHub <noreply@github.com>2023-01-16 18:00:54 +0000
commitfc1c93a141bd095884088a8fa6f935d642bf6528 (patch)
tree826a05efef343aa5dd9f160a1d6ba659cbe29afe /src/op_mode/route.py
parent6c9c4144df327d6c27d559c8a0c14317da3a2588 (diff)
parent45d0193ad16f69f64685576ba8190a5b1c35ce04 (diff)
downloadvyos-1x-fc1c93a141bd095884088a8fa6f935d642bf6528.tar.gz
vyos-1x-fc1c93a141bd095884088a8fa6f935d642bf6528.zip
Merge pull request #1760 from dmbaturin/vrf-route-summary
T4837: add VRF option for route summary
Diffstat (limited to 'src/op_mode/route.py')
-rwxr-xr-xsrc/op_mode/route.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/op_mode/route.py b/src/op_mode/route.py
index 6942fba89..7f0f9cbac 100755
--- a/src/op_mode/route.py
+++ b/src/op_mode/route.py
@@ -54,7 +54,7 @@ frr_command_template = Template("""
{% endif %}
""")
-def show_summary(raw: bool, family: str, table: typing.Optional[int]):
+def show_summary(raw: bool, family: str, table: typing.Optional[int], vrf: typing.Optional[str]):
from vyos.util import cmd
if family == 'inet':
@@ -62,18 +62,26 @@ def show_summary(raw: bool, family: str, table: typing.Optional[int]):
elif family == 'inet6':
family_cmd = 'ipv6'
else:
- raise ValueError(f"Usupported address family {family}")
+ raise ValueError(f"Unsupported address family {family}")
+
+ if (table is not None) and (vrf is not None):
+ raise ValueError("table and vrf options are mutually exclusive")
# Replace with Jinja if it ever starts growing
if table:
- table_command = f"table {table}"
+ table_cmd = f"table {table}"
+ else:
+ table_cmd = ""
+
+ if vrf:
+ vrf_cmd = f"vrf {vrf}"
else:
- table_command = ""
+ vrf_cmd = ""
if raw:
from json import loads
- output = cmd(f"vtysh -c 'show {family_cmd} route summary {table_command} json'").strip()
+ output = cmd(f"vtysh -c 'show {family_cmd} route {vrf_cmd} summary {table_cmd} json'").strip()
# If there are no routes in a table, its "JSON" output is an empty string,
# as of FRR 8.4.1
@@ -82,7 +90,7 @@ def show_summary(raw: bool, family: str, table: typing.Optional[int]):
else:
return {}
else:
- output = cmd(f"vtysh -c 'show {family_cmd} route summary {table_command}'")
+ output = cmd(f"vtysh -c 'show {family_cmd} route {vrf_cmd} summary {table_cmd}'")
return output
def show(raw: bool,