Skip to content

Commit cd2f41d

Browse files
authored
T6883 route-map extras support (#402)
* t6883 as_prepend_path fix * chaneglog * draft for rm community handling * rm updates * unit and integration tests for route maps * rm unit tests fixed * 1.4+ rm integration tests draft * rm set_community parser * large-community 1.4+ * unit tests fix for rm * extcommunity config * pre-commit * cleanup * RM bandwidth clauses * fixing parsers index for 1.3 RM * updated dic * fix unit tests * unit tests for RM * RM unit tests * dict literal for reserved keywords in unit tests * set_src ipv6 replaced unit test * unit test case for RM call * RM action type unit tests * rm match protocol code and unit test * doc update * set_table RM * set_table RM unit test * unit tests refactor * copilot recommendations
1 parent 098f31c commit cd2f41d

File tree

12 files changed

+2564
-13
lines changed

12 files changed

+2564
-13
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- vyos_route_maps - add support for as-path-prepend policy option

docs/vyos.vyos.vyos_route_maps_module.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,38 @@ Parameters
661661
<div>Peer IP address &lt;x.x.x.x&gt;.</div>
662662
</td>
663663
</tr>
664+
<tr>
665+
<td class="elbow-placeholder"></td>
666+
<td class="elbow-placeholder"></td>
667+
<td class="elbow-placeholder"></td>
668+
<td colspan="3">
669+
<div class="ansibleOptionAnchor" id="parameter-"></div>
670+
<b>protocol</b>
671+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
672+
<div style="font-size: small">
673+
<span style="color: purple">string</span>
674+
</div>
675+
</td>
676+
<td>
677+
<ul style="margin: 0; padding: 0"><b>Choices:</b>
678+
<li>babel</li>
679+
<li>bgp</li>
680+
<li>connected</li>
681+
<li>isis</li>
682+
<li>kernel</li>
683+
<li>ospf</li>
684+
<li>ospfv3</li>
685+
<li>rip</li>
686+
<li>ripng</li>
687+
<li>static</li>
688+
<li>table</li>
689+
<li>vnc</li>
690+
</ul>
691+
</td>
692+
<td>
693+
<div>Source protocol to match.</div>
694+
</td>
695+
</tr>
664696
<tr>
665697
<td class="elbow-placeholder"></td>
666698
<td class="elbow-placeholder"></td>
@@ -1009,6 +1041,46 @@ Parameters
10091041
</td>
10101042
</tr>
10111043

1044+
<tr>
1045+
<td class="elbow-placeholder"></td>
1046+
<td class="elbow-placeholder"></td>
1047+
<td class="elbow-placeholder"></td>
1048+
<td colspan="3">
1049+
<div class="ansibleOptionAnchor" id="parameter-"></div>
1050+
<b>extcommunity_bandwidth</b>
1051+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
1052+
<div style="font-size: small">
1053+
<span style="color: purple">string</span>
1054+
</div>
1055+
</td>
1056+
<td>
1057+
</td>
1058+
<td>
1059+
<div>Set Bandwidth of Origin value. 1-25600|cumulative|num-multipaths VPN extended community</div>
1060+
</td>
1061+
</tr>
1062+
<tr>
1063+
<td class="elbow-placeholder"></td>
1064+
<td class="elbow-placeholder"></td>
1065+
<td class="elbow-placeholder"></td>
1066+
<td colspan="3">
1067+
<div class="ansibleOptionAnchor" id="parameter-"></div>
1068+
<b>extcommunity_bandwidth_non_transitive</b>
1069+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
1070+
<div style="font-size: small">
1071+
<span style="color: purple">boolean</span>
1072+
</div>
1073+
</td>
1074+
<td>
1075+
<ul style="margin: 0; padding: 0"><b>Choices:</b>
1076+
<li>no</li>
1077+
<li>yes</li>
1078+
</ul>
1079+
</td>
1080+
<td>
1081+
<div>Set the bandwidth extended community encoded as non-transitive True/False VPN extended community</div>
1082+
</td>
1083+
</tr>
10121084
<tr>
10131085
<td class="elbow-placeholder"></td>
10141086
<td class="elbow-placeholder"></td>
@@ -1259,6 +1331,24 @@ Parameters
12591331
<div>Source address for route. Example &lt;x.x.x.x&gt; IP address.</div>
12601332
</td>
12611333
</tr>
1334+
<tr>
1335+
<td class="elbow-placeholder"></td>
1336+
<td class="elbow-placeholder"></td>
1337+
<td class="elbow-placeholder"></td>
1338+
<td colspan="3">
1339+
<div class="ansibleOptionAnchor" id="parameter-"></div>
1340+
<b>table</b>
1341+
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
1342+
<div style="font-size: small">
1343+
<span style="color: purple">string</span>
1344+
</div>
1345+
</td>
1346+
<td>
1347+
</td>
1348+
<td>
1349+
<div>Set prefixes to table. Example &lt;1-200&gt;</div>
1350+
</td>
1351+
</tr>
12621352
<tr>
12631353
<td class="elbow-placeholder"></td>
12641354
<td class="elbow-placeholder"></td>

plugins/module_utils/network/vyos/argspec/route_maps/route_maps.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class Route_mapsArgs(object): # pylint: disable=R0903
7474
},
7575
"extcommunity_rt": {"type": "str"},
7676
"extcommunity_soo": {"type": "str"},
77+
"extcommunity_bandwidth": {"type": "str"},
78+
"extcommunity_bandwidth_non_transitive": {"type": "bool"},
7779
"ip_next_hop": {"type": "str"},
7880
"ipv6_next_hop": {
7981
"type": "dict",
@@ -100,6 +102,7 @@ class Route_mapsArgs(object): # pylint: disable=R0903
100102
"src": {"type": "str"},
101103
"tag": {"type": "str"},
102104
"weight": {"type": "str"},
105+
"table": {"type": "str"},
103106
},
104107
},
105108
"match": {
@@ -178,6 +181,23 @@ class Route_mapsArgs(object): # pylint: disable=R0903
178181
"next_hop": {"type": "str"},
179182
},
180183
},
184+
"protocol": {
185+
"type": "str",
186+
"choices": [
187+
"babel",
188+
"bgp",
189+
"connected",
190+
"isis",
191+
"kernel",
192+
"ospf",
193+
"ospfv3",
194+
"rip",
195+
"ripng",
196+
"static",
197+
"table",
198+
"vnc",
199+
],
200+
},
181201
"large_community_large_community_list": {
182202
"type": "str",
183203
},

plugins/module_utils/network/vyos/config/route_maps/route_maps.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import (
3232
Route_mapsTemplate,
3333
)
34+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps_14 import (
35+
Route_mapsTemplate14,
36+
)
37+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import (
38+
LooseVersion,
39+
)
40+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
3441

3542

3643
class Route_maps(ResourceModule):
@@ -59,6 +66,8 @@ def __init__(self, module):
5966
"set_bgp_extcommunity_rt",
6067
"set_extcommunity_rt",
6168
"set_extcommunity_soo",
69+
"set_extcommunity_bandwidth",
70+
"set_extcommunity_bandwidth_non_transitive",
6271
"set_ip_next_hop",
6372
"set_ipv6_next_hop",
6473
"set_large_community",
@@ -70,6 +79,7 @@ def __init__(self, module):
7079
"set_src",
7180
"set_tag",
7281
"set_weight",
82+
"set_table",
7383
"set_comm_list",
7484
"set_comm_list_delete",
7585
"set_community",
@@ -89,15 +99,34 @@ def __init__(self, module):
8999
"on_match_next",
90100
"match_ipv6_address",
91101
"match_ipv6_nexthop",
102+
"match_protocol",
92103
"match_rpki",
93104
]
94105

106+
def _validate_template(self):
107+
version = get_os_version(self._module)
108+
if LooseVersion(version) >= LooseVersion("1.4"):
109+
self._tmplt = Route_mapsTemplate14()
110+
else:
111+
self._tmplt = Route_mapsTemplate()
112+
113+
def parse(self):
114+
"""override parse to check template"""
115+
self._validate_template()
116+
return super().parse()
117+
118+
def get_parser(self, name):
119+
"""get_parsers"""
120+
self._validate_template()
121+
return super().get_parser(name)
122+
95123
def execute_module(self):
96124
"""Execute the module
97125
98126
:rtype: A dictionary
99127
:returns: The result from module execution
100128
"""
129+
self._validate_template()
101130
if self.state not in ["parsed", "gathered"]:
102131
self.generate_commands()
103132
self.run_commands()

plugins/module_utils/network/vyos/facts/route_maps/route_maps.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps import (
2626
Route_mapsTemplate,
2727
)
28+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.route_maps_14 import (
29+
Route_mapsTemplate14,
30+
)
31+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import (
32+
LooseVersion,
33+
)
34+
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version
2835

2936

3037
class Route_mapsFacts(object):
@@ -59,11 +66,18 @@ def populate_facts(self, connection, ansible_facts, data=None):
5966
"""
6067
facts = {}
6168
objs = []
69+
70+
if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"):
71+
route_maps_class = Route_mapsTemplate14
72+
else:
73+
route_maps_class = Route_mapsTemplate
74+
6275
if not data:
6376
data = self.get_config(connection)
6477

6578
# parse native config using the Route_maps template
66-
route_maps_parser = Route_mapsTemplate(lines=data.splitlines())
79+
route_maps_parser = route_maps_class(lines=data.splitlines())
80+
6781
if route_maps_parser.parse().get("route_maps"):
6882
objs = list(route_maps_parser.parse().get("route_maps").values())
6983
for item in objs:

0 commit comments

Comments
 (0)