diff options
| author | Daniil Baturin <daniil@baturin.org> | 2023-01-12 13:12:25 +0000 | 
|---|---|---|
| committer | Daniil Baturin <daniil@baturin.org> | 2023-01-12 20:03:45 +0000 | 
| commit | 65fa4e55074652ec65b21eff457faa8f4adc9a1a (patch) | |
| tree | 596a6e449c2cab0cdda1882124181ebe35a16794 | |
| parent | 0e5ea5a63ab9db9ae04ab09e3af42a6e8e1c4c55 (diff) | |
| download | vyos-1x-65fa4e55074652ec65b21eff457faa8f4adc9a1a.tar.gz vyos-1x-65fa4e55074652ec65b21eff457faa8f4adc9a1a.zip | |
opmode: T4837: add family and table arguments for ShowRoute
| -rw-r--r-- | op-mode-definitions/include/show-route-summary.xml.i | 8 | ||||
| -rw-r--r-- | op-mode-definitions/show-ip-route.xml.in | 15 | ||||
| -rw-r--r-- | op-mode-definitions/show-ipv6-route.xml.in | 15 | ||||
| -rwxr-xr-x | src/op_mode/route.py | 27 | 
4 files changed, 51 insertions, 14 deletions
| diff --git a/op-mode-definitions/include/show-route-summary.xml.i b/op-mode-definitions/include/show-route-summary.xml.i deleted file mode 100644 index 471124562..000000000 --- a/op-mode-definitions/include/show-route-summary.xml.i +++ /dev/null @@ -1,8 +0,0 @@ -<!-- included start from show-route-summary.xml.i --> -<leafNode name="summary"> -  <properties> -    <help>Summary of all routes</help> -  </properties> -  <command>${vyos_op_scripts_dir}/vtysh_wrapper.sh $@</command> -</leafNode> -<!-- included end --> diff --git a/op-mode-definitions/show-ip-route.xml.in b/op-mode-definitions/show-ip-route.xml.in index 1e906672d..63b04fcd0 100644 --- a/op-mode-definitions/show-ip-route.xml.in +++ b/op-mode-definitions/show-ip-route.xml.in @@ -50,10 +50,23 @@                #include <include/show-route-ospf.xml.i>                #include <include/show-route-rip.xml.i>                #include <include/show-route-static.xml.i> -              #include <include/show-route-summary.xml.i>                #include <include/show-route-supernets-only.xml.i>                #include <include/show-route-table.xml.i>                #include <include/show-route-tag.xml.i> +              <node name="summary"> +                <properties> +                  <help>Summary of all routes</help> +                </properties> +                <command>${vyos_op_scripts_dir}/route.py show_summary --family inet</command> +                <children> +                  <tagNode name="table"> +                    <properties> +                      <help>Summary of routes in a particular table</help> +                    </properties> +                    <command>${vyos_op_scripts_dir}/route.py show_summary --family inet --table $6</command> +                  </tagNode> +                </children> +              </node>                <tagNode name="vrf">                  <properties>                    <help>Show IP routes in VRF</help> diff --git a/op-mode-definitions/show-ipv6-route.xml.in b/op-mode-definitions/show-ipv6-route.xml.in index 2c5024991..30ea208c1 100644 --- a/op-mode-definitions/show-ipv6-route.xml.in +++ b/op-mode-definitions/show-ipv6-route.xml.in @@ -50,9 +50,22 @@                #include <include/show-route-ospfv3.xml.i>                #include <include/show-route-ripng.xml.i>                #include <include/show-route-static.xml.i> -              #include <include/show-route-summary.xml.i>                #include <include/show-route-table.xml.i>                #include <include/show-route-tag.xml.i> +              <node name="summary"> +                <properties> +                  <help>Summary of all routes</help> +                </properties> +                <command>${vyos_op_scripts_dir}/route.py show_summary --family inet6</command> +                <children> +                  <tagNode name="table"> +                    <properties> +                      <help>Summary of routes in a particular table</help> +                    </properties> +                    <command>${vyos_op_scripts_dir}/route.py show_summary --family inet6 --table $6</command> +                  </tagNode> +                </children> +              </node>                <tagNode name="vrf">                  <properties>                    <help>Show IPv6 routes in VRF</help> 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, | 
