Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_evpn_evi.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2023 Red Hat
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for ios_evpn_evi
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_evpn_evi
18 short_description: Resource module to configure L2VPN EVPN EVI.
19 description: This module provides declarative management of L2VPN EVPN EVI on Cisco IOS network
20 devices.
21 version_added: 5.3.0
22 author: Padmini Priyadarshini Sivaraj (@PadminiSivaraj)
23 notes:
24 - Tested against Cisco IOS-XE device with Version 17.13.01 on Cat9k on CML.
25 - This module works with connection C(network_cli).
26 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
27 options:
28 config:
29 description: A dictionary of L2VPN Ethernet Virtual Private Network (EVPN) EVI configuration
30 type: list
31 elements: dict
32 suboptions:
33 evi:
34 description: EVPN instance value
35 type: int
36 required: True
37 default_gateway:
38 description: Default Gateway parameters
39 type: dict
40 suboptions:
41 advertise:
42 description: Advertise Default Gateway MAC/IP routes
43 type: dict
44 suboptions:
45 enable:
46 description: Enable advertisement of Default Gateway MAC/IP routes
47 type: bool
48 disable:
49 description: Disable advertisement of Default Gateway MAC/IP routes
50 type: bool
51 ip:
52 description: IP parameters
53 type: dict
54 suboptions:
55 local_learning:
56 description: IP local learning
57 type: dict
58 suboptions:
59 enable:
60 description: Enable IP local learning
61 type: bool
62 disable:
63 description: Disable IP local learning
64 type: bool
65 encapsulation:
66 description: EVPN encapsulation type
67 type: str
68 choices:
69 - vxlan
70 default: vxlan
71 replication_type:
72 description: Method for replicating BUM traffic
73 type: str
74 choices:
75 - ingress
76 - static
77 route_distinguisher:
78 description: EVPN Route Distinguisher
79 type: str
80 running_config:
81 description:
82 - This option is used only with state I(parsed).
83 - The value of this option should be the output received from the IOS
84 device by executing the command B(sh running-config nve | section ^l2vpn evpn$).
85 - The state I(parsed) reads the configuration from C(running_config)
86 option and transforms it into Ansible structured data as per the
87 resource module's argspec and the value is then returned in the
88 I(parsed) key within the result.
89 type: str
90 state:
91 description:
92 - The state the configuration should be left in
93 type: str
94 choices:
95 - merged
96 - replaced
97 - overridden
98 - deleted
99 - gathered
100 - rendered
101 - parsed
102 default: merged
103 """
104
105 EXAMPLES = """
106
107 # Using state merged
108
109 # Before state:
110 # -------------
111 # l2vpn evpn instance 101 vlan-based
112 # encapsulation vxlan
113 # replication-type static
114 # !
115 # l2vpn evpn instance 102 vlan-based
116 # encapsulation vxlan
117 # replication-type ingress
118 # !
119 # l2vpn evpn instance 201 vlan-based
120 # encapsulation vxlan
121 # replication-type static
122 # !
123 # l2vpn evpn instance 202 vlan-based
124 # encapsulation vxlan
125 # replication-type ingress
126
127 # - name: Merge provided configuration with device configuration
128 # cisco.ios.ios_evpn_evi:
129 # config:
130 # - evi: 101
131 # replication_type: ingress
132 # route_distinguisher: '1:1'
133 # default_gateway:
134 # advertise:
135 # enable: False
136 # ip:
137 # local_learning:
138 # enable: True
139 #
140 # - evi: 202
141 # replication_type: static
142 # default_gateway:
143 # advertise:
144 # enable: True
145 # ip:
146 # local_learning:
147 # disable: True
148 # state: merged
149
150 # Commands Fired:
151 # ---------------
152 # "commands": [
153 # "l2vpn evpn instance 101 vlan-based",
154 # "ip local-learning enable",
155 # "replication-type ingress",
156 # "rd 1:1",
157 # "l2vpn evpn instance 202 vlan-based",
158 # "default-gateway advertise enable",
159 # "ip local-learning disable",
160 # "replication-type static"
161 # ],
162
163 # After state:
164 # ------------
165 # l2vpn evpn instance 101 vlan-based
166 # encapsulation vxlan
167 # rd 1:1
168 # replication-type ingress
169 # ip local-learning enable
170 # !
171 # l2vpn evpn instance 102 vlan-based
172 # encapsulation vxlan
173 # replication-type ingress
174 # !
175 # l2vpn evpn instance 201 vlan-based
176 # encapsulation vxlan
177 # replication-type static
178 # !
179 # l2vpn evpn instance 202 vlan-based
180 # encapsulation vxlan
181 # replication-type static
182 # ip local-learning disable
183 # default-gateway advertise enable
184
185
186 # Using state replaced
187
188 # Before state:
189 # -------------
190 # l2vpn evpn instance 101 vlan-based
191 # encapsulation vxlan
192 # rd 1:1
193 # replication-type ingress
194 # ip local-learning enable
195 # !
196 # l2vpn evpn instance 102 vlan-based
197 # encapsulation vxlan
198 # replication-type ingress
199 # !
200 # l2vpn evpn instance 201 vlan-based
201 # encapsulation vxlan
202 # replication-type static
203 # !
204 # l2vpn evpn instance 202 vlan-based
205 # encapsulation vxlan
206 # replication-type static
207 # ip local-learning disable
208 # default-gateway advertise enable
209
210 # - name: Replaces the device configuration with the provided configuration
211 # cisco.ios.ios_evpn_evi:
212 # config:
213 # - evi: 101
214 # replication_type: ingress
215 # default_gateway:
216 # advertise:
217 # enable: True
218 # - evi: 202
219 # replication_type: ingress
220 # state: replaced
221
222 # Commands Fired:
223 # ---------------
224 # "commands": [
225 # "l2vpn evpn instance 101 vlan-based",
226 # "default-gateway advertise enable",
227 # "no ip local-learning enable",
228 # "no rd 1:1",
229 # "l2vpn evpn instance 202 vlan-based",
230 # "no default-gateway advertise enable",
231 # "no ip local-learning disable",
232 # "replication-type ingress"
233 # ],
234
235 # After state:
236 # ------------
237 # l2vpn evpn instance 101 vlan-based
238 # encapsulation vxlan
239 # replication-type ingress
240 # default-gateway advertise enable
241 # !
242 # l2vpn evpn instance 102 vlan-based
243 # encapsulation vxlan
244 # replication-type ingress
245 # !
246 # l2vpn evpn instance 201 vlan-based
247 # encapsulation vxlan
248 # replication-type static
249 # !
250 # l2vpn evpn instance 202 vlan-based
251 # encapsulation vxlan
252 # replication-type ingress
253
254 # Using state overridden
255
256 # Before state:
257 # -------------
258 # l2vpn evpn instance 101 vlan-based
259 # encapsulation vxlan
260 # replication-type ingress
261 # default-gateway advertise enable
262 # !
263 # l2vpn evpn instance 102 vlan-based
264 # encapsulation vxlan
265 # replication-type ingress
266 # !
267 # l2vpn evpn instance 201 vlan-based
268 # encapsulation vxlan
269 # replication-type static
270 # !
271 # l2vpn evpn instance 202 vlan-based
272 # encapsulation vxlan
273 # replication-type ingress
274
275 # - name: Override the device configuration with provided configuration
276 # cisco.ios.ios_evpn_evi:
277 # config:
278 # - evi: 101
279 # replication_type: ingress
280 # default_gateway:
281 # advertise:
282 # enable: True
283 # - evi: 202
284 # replication_type: static
285 # default_gateway:
286 # advertise:
287 # enable: True
288 # state: overridden
289
290 # Commands Fired:
291 # ---------------
292 # "commands": [
293 # "no l2vpn evpn instance 102 vlan-based",
294 # "no l2vpn evpn instance 201 vlan-based",
295 # "l2vpn evpn instance 202 vlan-based",
296 # "default-gateway advertise enable",
297 # "replication-type static"
298 # ],
299
300 # After state:
301 # ------------
302 # l2vpn evpn instance 101 vlan-based
303 # encapsulation vxlan
304 # replication-type ingress
305 # default-gateway advertise enable
306 # !
307 # l2vpn evpn instance 202 vlan-based
308 # encapsulation vxlan
309 # replication-type static
310 # default-gateway advertise enable
311
312
313 # Using state Deleted
314
315 # Before state:
316 # -------------
317 # l2vpn evpn instance 101 vlan-based
318 # encapsulation vxlan
319 # replication-type ingress
320 # default-gateway advertise enable
321 # l2vpn evpn instance 102 vlan-based
322 # encapsulation vxlan
323 # replication-type ingress
324 # l2vpn evpn instance 202 vlan-based
325 # encapsulation vxlan
326 # replication-type static
327 # default-gateway advertise enable
328
329 # - name: "Delete the given EVI(s)"
330 # cisco.ios.ios_evpn_evi:
331 # config:
332 # - evi: 101
333 # state: deleted
334
335 # Commands Fired:
336 # ---------------
337 # "commands": [
338 # "no l2vpn evpn instance 101 vlan-based"
339 # ],
340
341 # After state:
342 # -------------
343 # l2vpn evpn instance 102 vlan-based
344 # encapsulation vxlan
345 # replication-type ingress
346 # l2vpn evpn instance 202 vlan-based
347 # encapsulation vxlan
348 # replication-type static
349 # default-gateway advertise enable
350
351 # Using state Deleted without any config passed
352
353 # Before state:
354 # -------------
355 # l2vpn evpn instance 102 vlan-based
356 # encapsulation vxlan
357 # replication-type ingress
358 # l2vpn evpn instance 202 vlan-based
359 # encapsulation vxlan
360 # replication-type static
361 # default-gateway advertise enable
362
363 # - name: "Delete ALL EVIs"
364 # cisco.ios.ios_evpn_evi:
365 # state: deleted
366
367 # Commands Fired:
368 # ---------------
369 # "commands": [
370 # "no l2vpn evpn instance 102 vlan-based",
371 # "no l2vpn evpn instance 202 vlan-based"
372 # ],
373
374 # After state:
375 # -------------
376 # !
377
378 # Using gathered
379
380 # Before state:
381 # -------------
382 #
383 # l2vpn evpn instance 101 vlan-based
384 # encapsulation vxlan
385 # replication-type static
386 # !
387 # l2vpn evpn instance 102 vlan-based
388 # encapsulation vxlan
389 # replication-type ingress
390 # !
391 # l2vpn evpn instance 201 vlan-based
392 # encapsulation vxlan
393 # replication-type static
394 # !
395 # l2vpn evpn instance 202 vlan-based
396 # encapsulation vxlan
397 # replication-type ingress
398
399 # - name: Gather facts for evpn_evi
400 # cisco.ios.ios_evpn_evi:
401 # config:
402 # state: gathered
403
404 # Task Output:
405 # ------------
406 #
407 # gathered:
408 # - evi: 101
409 # encapsulation: vxlan
410 # replication_type: static
411 # - evi: 102
412 # encapsulation: vxlan
413 # replication_type: ingress
414 # - evi: 201
415 # encapsulation: vxlan
416 # replication_type: static
417 # - evi: 202
418 # encapsulation: vxlan
419 # replication_type: ingress
420
421 # Using Rendered
422
423 # - name: Rendered the provided configuration with the existing running configuration
424 # cisco.ios.ios_evpn_evi:
425 # config:
426 # - evi: 101
427 # replication_type: ingress
428 # default_gateway:
429 # advertise:
430 # enable: True
431 # - evi: 202
432 # replication_type: ingress
433 # state: rendered
434
435 # Task Output:
436 # ------------
437 #
438 # rendered:
439 # - l2vpn evpn instance 101 vlan-based
440 # - default-gateway advertise enable
441 # - replication-type ingress
442 # - l2vpn evpn instance 202 vlan-based
443 # - replication-type ingress
444
445
446 # Using parsed
447
448 # File: parsed.cfg
449 # ----------------
450 #
451 # l2vpn evpn instance 101 vlan-based
452 # encapsulation vxlan
453 # replication-type ingress
454 # default-gateway advertise enable
455 # !
456 # l2vpn evpn instance 102 vlan-based
457 # encapsulation vxlan
458 # replication-type ingress
459 # !
460
461 # - name: Parse the commands for provided configuration
462 # cisco.ios.ios_evpn_evi:
463 # running_config: "{{ lookup('file', 'parsed.cfg') }}"
464 # state: parsed
465
466 # Task Output:
467 # ------------
468 #
469 # parsed:
470 # - evi: 101
471 # encapsulation: vxlan
472 # replication_type: ingress
473 # default_gateway:
474 # advertise:
475 # enable: true
476 # - evi: 102
477 # encapsulation: vxlan
478 # replication_type: ingress
479 """
480
481 RETURN = """
482 before:
483 description: The configuration prior to the module execution.
484 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
485 type: dict
486 sample: >
487 This output will always be in the same format as the
488 module argspec.
489 after:
490 description: The resulting configuration after module execution.
491 returned: when changed
492 type: dict
493 sample: >
494 This output will always be in the same format as the
495 module argspec.
496 commands:
497 description: The set of commands pushed to the remote device.
498 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
499 type: list
500 sample:
501 - "l2vpn evpn instance 101 vlan-based"
502 - "encapsulation vxlan"
503 - "replication-type ingress"
504 """
505
506 from ansible.module_utils.basic import AnsibleModule
507
508 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.evpn_evi.evpn_evi import (
509 Evpn_eviArgs,
510 )
511 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.evpn_evi.evpn_evi import (
512 Evpn_evi,
513 )
514
515
516 def main():
517 """
518 Main entry point for module execution
519
520 :returns: the result form module invocation
521 """
522 module = AnsibleModule(
523 argument_spec=Evpn_eviArgs.argument_spec,
524 mutually_exclusive=[["config", "running_config"]],
525 required_if=[
526 ["state", "merged", ["config"]],
527 ["state", "replaced", ["config"]],
528 ["state", "overridden", ["config"]],
529 ["state", "rendered", ["config"]],
530 ["state", "parsed", ["running_config"]],
531 ],
532 supports_check_mode=True,
533 )
534
535 result = Evpn_evi(module).execute_module()
536 module.exit_json(**result)
537
538
539 if __name__ == "__main__":
540 main()