Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_evpn_global.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_global
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_evpn_global
18 short_description: Resource module to configure L2VPN EVPN.
19 description: This module provides declarative management of L2VPN EVPN 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) configuration
30 type: dict
31 suboptions:
32 default_gateway:
33 description: Default gateway parameters
34 type: dict
35 suboptions:
36 advertise:
37 description: Advertise Default Gateway MAC/IP routes
38 type: bool
39 flooding_suppression:
40 description: Suppress flooding of broadcast, multicast, and/or unknown unicast packets
41 type: dict
42 suboptions:
43 address_resolution:
44 description: Suppress flooding of Address Resolution and Neighbor Discovery Protocol packets
45 type: dict
46 suboptions:
47 disable:
48 description: Disable flooding suppression
49 type: bool
50 ip:
51 description: IP parameters
52 type: dict
53 suboptions:
54 local_learning:
55 description: IP local learning
56 type: dict
57 suboptions:
58 disable:
59 description: Disable IP local learning
60 type: bool
61 replication_type:
62 description: Method for replicating BUM traffic
63 type: str
64 choices:
65 - ingress
66 - static
67 route_target:
68 description: Route Target VPN Extended Communities
69 type: dict
70 suboptions:
71 auto:
72 description: Automatically set a route-target
73 type: dict
74 suboptions:
75 vni:
76 description: Set vni-based route-target
77 type: bool
78 router_id:
79 description: EVPN router ID
80 type: str
81 running_config:
82 description:
83 - This option is used only with state I(parsed).
84 - The value of this option should be the output received from the IOS
85 device by executing the command B(sh running-config nve | section ^l2vpn evpn$).
86 - The state I(parsed) reads the configuration from C(running_config)
87 option and transforms it into Ansible structured data as per the
88 resource module's argspec and the value is then returned in the
89 I(parsed) key within the result.
90 type: str
91 state:
92 description:
93 - The state the configuration should be left in
94 type: str
95 choices:
96 - merged
97 - replaced
98 - overridden
99 - deleted
100 - gathered
101 - rendered
102 - parsed
103 default: merged
104 """
105
106
107 EXAMPLES = """
108
109 # Using merged
110
111 # Before state:
112 # -------------
113 #
114 # Leaf-01#show running-config nve | section ^l2vpn evpn$
115 # l2vpn evpn
116 # replication-type static
117 # router-id Loopback1
118 # default-gateway advertise
119
120 - name: Merge provided configuration with device configuration
121 cisco.ios.ios_evpn_global:
122 config:
123 replication_type: ingress
124 route_target:
125 auto:
126 vni: true
127 default_gateway:
128 advertise: false
129 ip:
130 local_learning:
131 disable: true
132 flooding_suppression:
133 address_resolution:
134 disable: false
135 state: merged
136
137 # Task Output
138 # -----------
139 #
140 # before:
141 # - replication_type: static
142 # router_id: Loopback1
143 # default_gateway:
144 # advertise: true
145 # commands:
146 # - l2vpn evpn
147 # no default-gateway advertise
148 # replication-type ingress
149 # route-target auto vni
150 # ip local-learning disable
151 # after:
152 # - replication_type: ingress
153 # router_id: Loopback1
154 # route_target:
155 # auto:
156 # vni: true
157 # ip:
158 # local_learning:
159 # disable: true
160
161 # After state:
162 # ------------
163 #
164 # Leaf-01#show running-config nve | section ^l2vpn evpn$
165 # l2vpn evpn
166 # replication-type ingress
167 # router-id Loopback1
168 # ip local-learning disable
169 # route-target auto vni
170
171 # Using replaced
172
173 # Before state:
174 # -------------
175 #
176 # Leaf-01#show running-config nve | section ^l2vpn evpn$
177 # l2vpn evpn
178 # replication-type ingress
179 # router-id Loopback1
180 # ip local-learning disable
181 # route-target auto vni
182
183 - name: Replaces device configuration for EVPN global with provided configuration
184 cisco.ios.ios_evpn_global:
185 config:
186 replication_type: static
187 router_id: Loopback2
188 default_gateway:
189 advertise: true
190 flooding_suppression:
191 address_resolution:
192 disable: true
193 state: replaced
194
195 # Task Output
196 # -----------
197 #
198 # before:
199 # - replication_type: ingress
200 # router_id: Loopback1
201 # route_target:
202 # auto:
203 # vni: true
204 # ip:
205 # local_learning:
206 # disable: true
207 # commands:
208 # - l2vpn evpn
209 # - default-gateway advertise
210 # - flooding-suppression address-resolution disable
211 # - no ip local-learning disable
212 # - replication-type static
213 # - no route-target auto vni
214 # - router-id Loopback2
215 # after:
216 # - replication_type: ingress
217 # router_id: Loopback2
218 # default_gateway:
219 # advertise: true
220 # flooding_suppression:
221 # address_resolution:
222 # disable: true
223
224 # After state:
225 # ------------
226 #
227 # Leaf-01#show running-config nve | section ^l2vpn evpn$
228 # l2vpn evpn
229 # replication-type static
230 # flooding-suppression address-resolution disable
231 # router-id Loopback2
232 # default-gateway advertise
233
234 # Using Deleted
235
236 # Before state:
237 # -------------
238 #
239 # Leaf-01#show running-config nve | section ^l2vpn evpn$
240 # l2vpn evpn
241 # replication-type static
242 # flooding-suppression address-resolution disable
243 # router-id Loopback2
244 # default-gateway advertise
245
246 - name: Delete EVPN global
247 cisco.ios.ios_evpn_global:
248 config:
249 state: deleted
250
251 # before:
252 # - replication_type: ingress
253 # router_id: Loopback2
254 # default_gateway:
255 # advertise: true
256 # flooding_suppression:
257 # address_resolution:
258 # disable: true
259 # commands:
260 # - no l2vpn evpn
261 # after:
262 #
263
264 # After state:
265 # -------------
266 #
267 # Leaf-01#show running-config nve | section ^l2vpn evpn$
268 #
269
270 # Using gathered
271
272 # Before state:
273 # -------------
274 #
275 # Leaf-01#show running-config nve | section ^l2vpn evpn$
276 # l2vpn evpn
277 # replication-type ingress
278 # router-id Loopback1
279 # ip local-learning disable
280 # route-target auto vni
281
282 - name: Gather facts of l2vpn evpn
283 cisco.ios.ios_evpn_global:
284 config:
285 state: gathered
286
287 # Task Output:
288 # ------------
289 #
290 # gathered:
291 # - replication_type: ingress
292 # route_target:
293 # auto:
294 # vni: true
295 # router_id: Loopback1
296 # ip:
297 # local_learning:
298 # disable: true
299
300 # Using rendered
301
302 - name: Render the commands for provided configuration
303 cisco.ios.ios_evpn_global:
304 config:
305 replication_type: static
306 route_target:
307 auto:
308 vni: true
309 state: rendered
310
311 # Task Output:
312 # ------------
313 #
314 # rendered:
315 # - l2vpn evpn
316 # - replication-type static
317 # - route-target auto vni
318
319 # Using parsed
320
321 # File: parsed.cfg
322 # ----------------
323 #
324 # l2vpn evpn
325 # replication-type ingress
326 # router-id Loopback1
327 # default-gateway advertise
328 # route-target auto vni
329
330 - name: Parse the provided configuration
331 cisco.ios.ios_evpn_global:
332 running_config: "{{ lookup('file', 'parsed.cfg') }}"
333 state: parsed
334
335 # Task Output:
336 # ------------
337 #
338 # parsed:
339 # - replication_type: ingress
340 # route_target:
341 # auto:
342 # vni: true
343 # router_id: Loopback1
344 # default_gateway:
345 # advertise: true
346 """
347
348 RETURN = """
349 before:
350 description: The configuration prior to the module execution.
351 returned: when I(state) is C(merged), C(replaced), C(overridden), or C(deleted)
352 type: dict
353 sample: >
354 This output will always be in the same format as the
355 module argspec.
356 after:
357 description: The resulting configuration after module execution.
358 returned: when changed
359 type: dict
360 sample: >
361 This output will always be in the same format as the
362 module argspec.
363 commands:
364 description: The set of commands pushed to the remote device.
365 returned: when I(state) is C(merged), C(replaced), C(overridden), or C(deleted)
366 type: list
367 sample:
368 - "l2vpn evpn"
369 - "replication-type ingress"
370 - "router_id Loopback1"
371 rendered:
372 description: The provided configuration in the task rendered in device-native format (offline).
373 returned: when I(state) is C(rendered)
374 type: list
375 sample:
376 - l2vpn evpn
377 - replication-type static
378 - route-target auto vni
379 gathered:
380 description: Facts about the network resource gathered from the remote device as structured data.
381 returned: when I(state) is C(gathered)
382 type: list
383 sample: >
384 This output will always be in the same format as the
385 module argspec.
386 parsed:
387 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
388 returned: when I(state) is C(parsed)
389 type: list
390 sample: >
391 This output will always be in the same format as the
392 module argspec.
393 """
394
395 from ansible.module_utils.basic import AnsibleModule
396
397 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.evpn_global.evpn_global import (
398 Evpn_globalArgs,
399 )
400 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.evpn_global.evpn_global import (
401 Evpn_global,
402 )
403
404
405 def main():
406 """
407 Main entry point for module execution
408
409 :returns: the result form module invocation
410 """
411 module = AnsibleModule(
412 argument_spec=Evpn_globalArgs.argument_spec,
413 mutually_exclusive=[["config", "running_config"]],
414 required_if=[
415 ["state", "merged", ["config"]],
416 ["state", "replaced", ["config"]],
417 ["state", "overridden", ["config"]],
418 ["state", "rendered", ["config"]],
419 ["state", "parsed", ["running_config"]],
420 ],
421 supports_check_mode=True,
422 )
423
424 result = Evpn_global(module).execute_module()
425 module.exit_json(**result)
426
427
428 if __name__ == "__main__":
429 main()