diff options
author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2025-03-03 08:15:25 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-03 08:15:25 +1000 |
commit | 241de488727ba60af9b883ef8ed31571a119b856 (patch) | |
tree | df7f5a6fbd733fdaaa68e42b70cfc3fa94347a7e /plugins | |
parent | ad249c39c3259df8c2536dd80f62723eb9c364ef (diff) | |
download | vyos.vyos-241de488727ba60af9b883ef8ed31571a119b856.tar.gz vyos.vyos-241de488727ba60af9b883ef8ed31571a119b856.zip |
T6834 static_route module to support interface_route (#398)
* t6834 init
* facts fixes, WIP
* T6834 - facts updates
* static_routes 1.3- config, facts, args and sanit and unit tests
* changelog
* changelog updates
* static_routes 1.4+
* static_routes v1.4 unit tests
* comment removed
Diffstat (limited to 'plugins')
4 files changed, 44 insertions, 11 deletions
diff --git a/plugins/module_utils/network/vyos/argspec/static_routes/static_routes.py b/plugins/module_utils/network/vyos/argspec/static_routes/static_routes.py index 2849b8b7..365df48a 100644 --- a/plugins/module_utils/network/vyos/argspec/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/argspec/static_routes/static_routes.py @@ -73,7 +73,6 @@ class Static_routesArgs(object): # pylint: disable=R0903 "admin_distance": {"type": "int"}, "enabled": {"type": "bool"}, "forward_router_address": { - "required": True, "type": "str", }, "interface": {"type": "str"}, diff --git a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py index 9230bdd9..8451e7da 100644 --- a/plugins/module_utils/network/vyos/config/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/config/static_routes/static_routes.py @@ -34,6 +34,10 @@ from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.utils get_lst_same_for_dicts, get_route_type, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import ( + LooseVersion, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version class Static_routes(ConfigBase): @@ -346,12 +350,24 @@ class Static_routes(ConfigBase): opr=opr, ), ) - elif element == "interface": + elif element == "interface" and LooseVersion( + get_os_version(self._module), + ) < LooseVersion("1.4"): commands.append( self._compute_command( dest=want["dest"], - key="next-hop", - attrib=hop["forward_router_address"] + " " + "next-hop-interface", + key="next-hop-interface", + value=hop[element], + opr=opr, + ).replace("route", "interface-route"), + ) + elif element == "interface" and LooseVersion( + get_os_version(self._module), + ) >= LooseVersion("1.4"): + commands.append( + self._compute_command( + dest=want["dest"], + key="interface", value=hop[element], opr=opr, ), @@ -442,12 +458,24 @@ class Static_routes(ConfigBase): remove=True, ), ) - elif element == "interface": + elif element == "interface" and LooseVersion( + get_os_version(self._module), + ) < LooseVersion("1.4"): commands.append( self._compute_command( dest=want["dest"], - key="next-hop", - attrib=hop["forward_router_address"] + " " + "next-hop-interface", + key="next-hop-interface", + value=hop[element], + remove=True, + ).replace("route", "interface-route"), + ) + elif element == "interface" and LooseVersion( + get_os_version(self._module), + ) >= LooseVersion("1.4"): + commands.append( + self._compute_command( + dest=want["dest"], + key="interface", value=hop[element], remove=True, ), diff --git a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py index b8ffa30d..99b3917b 100644 --- a/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py +++ b/plugins/module_utils/network/vyos/facts/static_routes/static_routes.py @@ -107,7 +107,8 @@ class Static_routesFacts(object): :rtype: dictionary :returns: The generated config """ - next_hops_conf = "\n".join(filter(lambda x: ("next-hop" in x), conf)) + + next_hops_conf = "\n".join(filter(lambda x: ("next-hop" in x or "interface" in x), conf)) blackhole_conf = "\n".join(filter(lambda x: ("blackhole" in x), conf)) routes_dict = { "blackhole_config": self.parse_blackhole(blackhole_conf), @@ -138,9 +139,13 @@ class Static_routesFacts(object): def parse_next_hop(self, conf): nh_list = None + nh_info = {} if conf: nh_list = [] - hop_list = findall(r"^.*next-hop (.+)", conf, M) + hop_list = [ + match[0] if match[0] else match[1] + for match in findall(r"^.*next-hop(.+)|(\s+interface.+)$", conf, M) + ] if hop_list: for hop in hop_list: distance = search(r"^.*distance (.\S+)", hop, M) @@ -148,9 +153,11 @@ class Static_routesFacts(object): dis = hop.find("disable") hop_info = hop.split(" ") - nh_info = {"forward_router_address": hop_info[0].strip("'")} + if interface: nh_info["interface"] = interface.group(1).strip("'") + else: + nh_info = {"forward_router_address": hop_info[1].strip("'")} if distance: value = distance.group(1).strip("'") nh_info["admin_distance"] = int(value) diff --git a/plugins/modules/vyos_static_routes.py b/plugins/modules/vyos_static_routes.py index 76fccaf9..0629a8bd 100644 --- a/plugins/modules/vyos_static_routes.py +++ b/plugins/modules/vyos_static_routes.py @@ -104,7 +104,6 @@ options: - The IP address of the next hop that can be used to reach the destination network. type: str - required: true enabled: description: - Disable IPv4/v6 next-hop static route. |