Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/modules/iosxr_vrf_interfaces.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2024 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 iosxr_vrf_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: iosxr_vrf_interfaces
18 short_description: Resource module to configure VRF interfaces.
19 description: This module configures and manages the VRF configuration in interface on IOS XR platforms.
20 version_added: 10.3.0
21 author: Sagar Paul (@KB-perByte)
22 notes:
23 - Tested against Cisco IOS-XR 7.2.2.
24 - This module works with connection C(network_cli).
25 options:
26 config:
27 description: A list of VRF interfaces options.
28 type: list
29 elements: dict
30 suboptions:
31 name:
32 description:
33 - Full name of the interface excluding any logical unit number,
34 i.e. GigabitEthernet0/0/0/1.
35 type: str
36 required: true
37 vrf_name:
38 description:
39 - Vrf that is to be added to the interface.
40 type: str
41 running_config:
42 description:
43 - This option is used only with state I(parsed).
44 - The value of this option should be the output received from the IOS
45 device by executing the command B(sh running-config interface).
46 - The state I(parsed) reads the configuration from C(running_config)
47 option and transforms it into Ansible structured data as per the
48 resource module's argspec and the value is then returned in the
49 I(parsed) key within the result.
50 type: str
51 state:
52 description:
53 - The state the configuration should be left in
54 - The states I(rendered), I(gathered) and I(parsed) does not perform any
55 change on the device.
56 - The state I(rendered) will transform the configuration in C(config)
57 option to platform specific CLI commands which will be returned in the
58 I(rendered) key within the result. For state I(rendered) active
59 connection to remote host is not required.
60 - The state I(gathered) will fetch the running configuration from device
61 and transform it into structured data in the format as per the resource
62 module argspec and the value is returned in the I(gathered) key within
63 the result.
64 - The state I(parsed) reads the configuration from C(running_config)
65 option and transforms it into JSON format as per the resource module
66 parameters and the value is returned in the I(parsed) key within the
67 result. The value of C(running_config) option should be the same format
68 as the output of command I(show running-config | include ip route|ipv6
69 route) executed on device. For state I(parsed) active connection to
70 remote host is not required.
71 type: str
72 choices:
73 - merged
74 - replaced
75 - overridden
76 - deleted
77 - gathered
78 - rendered
79 - parsed
80 default: merged
81 """
82
83 EXAMPLES = """
84 # Using merged
85
86 # Before state:
87 # -------------
88 #
89 # viosxr#show running-config interfaces
90 # interface MgmtEth0/RP0/CPU0/0
91 # ipv4 address dhcp
92 # !
93 # interface GigabitEthernet0/0/0/0
94 # description this is interface0
95 # cdp
96 # !
97 # interface GigabitEthernet0/0/0/1
98 # shutdown
99 # !
100 # interface GigabitEthernet0/0/0/2
101 # shutdown
102 # !
103
104 - name: Simple merge selective
105 cisco.iosxr.iosxr_vrf_interfaces:
106 state: merged
107 config:
108 - name: MgmtEth0/RP0/CPU0/0
109 - name: GigabitEthernet0/0/0/0
110 - name: GigabitEthernet0/0/0/1
111 vrf_name: vrf_C
112 - name: GigabitEthernet0/0/0/2
113 vrf_name: vrf_D
114
115 # Task Output
116 # -----------
117 #
118 # before:
119 # - name: MgmtEth0/RP0/CPU0/0
120 # - name: GigabitEthernet0/0/0/0
121 # - name: GigabitEthernet0/0/0/1
122 # - name: GigabitEthernet0/0/0/2
123 # commands:
124 # - interface GigabitEthernet0/0/0/1
125 # - vrf vrf_C
126 # - interface GigabitEthernet0/0/0/2
127 # - vrf vrf_D
128 # after:
129 # - name: MgmtEth0/RP0/CPU0/0
130 # - name: GigabitEthernet0/0/0/0
131 # - name: GigabitEthernet0/0/0/1
132 # vrf_name: vrf_C
133 # - name: GigabitEthernet0/0/0/2
134 # vrf_name: vrf_D
135
136 # After state:
137 # -------------
138 #
139 # viosxr#show running-config interfaces
140 # interface MgmtEth0/RP0/CPU0/0
141 # ipv4 address dhcp
142 # !
143 # interface GigabitEthernet0/0/0/0
144 # description this is interface0
145 # cdp
146 # !
147 # interface GigabitEthernet0/0/0/1
148 # vrf vrf_C
149 # shutdown
150 # !
151 # interface GigabitEthernet0/0/0/2
152 # vrf vrf_D
153 # shutdown
154 # !
155
156 # Using replaced
157
158 # Before state:
159 # -------------
160 #
161 # viosxr#show running-config interfaces
162 # interface MgmtEth0/RP0/CPU0/0
163 # ipv4 address dhcp
164 # !
165 # interface GigabitEthernet0/0/0/0
166 # description this is interface0
167 # cdp
168 # !
169 # interface GigabitEthernet0/0/0/1
170 # vrf vrf_C
171 # shutdown
172 # !
173 # interface GigabitEthernet0/0/0/2
174 # vrf vrf_D
175 # shutdown
176 # !
177
178 - name: Simple replaced selective
179 cisco.iosxr.iosxr_vrf_interfaces:
180 state: replaced
181 config:
182 - name: MgmtEth0/RP0/CPU0/0
183 - name: GigabitEthernet0/0/0/0
184 - name: GigabitEthernet0/0/0/1
185 vrf_name: vrf_E
186 - name: GigabitEthernet0/0/0/2
187 vrf_name: vrf_D
188
189 # Task Output
190 # -----------
191 #
192 # before:
193 # - name: MgmtEth0/RP0/CPU0/0
194 # - name: GigabitEthernet0/0/0/0
195 # - name: GigabitEthernet0/0/0/1
196 # vrf_name: vrf_C
197 # - name: GigabitEthernet0/0/0/2
198 # vrf_name: vrf_D
199 # commands:
200 # - interface GigabitEthernet0/0/0/1
201 # - vrf vrf_E
202 # after:
203 # - name: MgmtEth0/RP0/CPU0/0
204 # - name: GigabitEthernet0/0/0/0
205 # - name: GigabitEthernet0/0/0/1
206 # vrf_name: vrf_E
207 # - name: GigabitEthernet0/0/0/2
208 # vrf_name: vrf_D
209
210 # After state:
211 # -------------
212 #
213 # viosxr#show running-config interfaces
214 # interface MgmtEth0/RP0/CPU0/0
215 # ipv4 address dhcp
216 # !
217 # interface GigabitEthernet0/0/0/0
218 # description this is interface0
219 # cdp
220 # !
221 # interface GigabitEthernet0/0/0/1
222 # vrf vrf_E
223 # shutdown
224 # !
225 # interface GigabitEthernet0/0/0/2
226 # vrf vrf_D
227 # shutdown
228 # !
229
230 # Using overridden
231
232 # Before state:
233 # -------------
234 #
235 # viosxr#show running-config interfaces
236 # interface MgmtEth0/RP0/CPU0/0
237 # ipv4 address dhcp
238 # !
239 # interface GigabitEthernet0/0/0/0
240 # description this is interface0
241 # cdp
242 # !
243 # interface GigabitEthernet0/0/0/1
244 # vrf vrf_C
245 # shutdown
246 # !
247 # interface GigabitEthernet0/0/0/2
248 # vrf vrf_D
249 # shutdown
250 # !
251
252 - name: Simple overridden selective
253 cisco.iosxr.iosxr_vrf_interfaces:
254 state: overridden
255 config:
256 - name: MgmtEth0/RP0/CPU0/0
257 - name: GigabitEthernet0/0/0/0
258 - name: GigabitEthernet0/0/0/1
259 vrf_name: vrf_E
260
261 # Task Output
262 # -----------
263 #
264 # before:
265 # - name: MgmtEth0/RP0/CPU0/0
266 # - name: GigabitEthernet0/0/0/0
267 # - name: GigabitEthernet0/0/0/1
268 # vrf_name: vrf_C
269 # - name: GigabitEthernet0/0/0/2
270 # vrf_name: vrf_D
271 # commands:
272 # - interface GigabitEthernet0/0/0/1
273 # - vrf vrf_E
274 # - interface GigabitEthernet0/0/0/2
275 # - no vrf vrf_E
276 # after:
277 # - name: MgmtEth0/RP0/CPU0/0
278 # - name: GigabitEthernet0/0/0/0
279 # - name: GigabitEthernet0/0/0/1
280 # vrf_name: vrf_E
281 # - name: GigabitEthernet0/0/0/2
282
283 # After state:
284 # -------------
285 #
286 # viosxr#show running-config interfaces
287 # interface MgmtEth0/RP0/CPU0/0
288 # ipv4 address dhcp
289 # !
290 # interface GigabitEthernet0/0/0/0
291 # description this is interface0
292 # cdp
293 # !
294 # interface GigabitEthernet0/0/0/1
295 # vrf vrf_E
296 # shutdown
297 # !
298 # interface GigabitEthernet0/0/0/2
299 # shutdown
300 # !
301
302 # Using deleted
303
304 # Before state:
305 # -------------
306 #
307 # viosxr#show running-config interfaces
308 # interface MgmtEth0/RP0/CPU0/0
309 # ipv4 address dhcp
310 # !
311 # interface GigabitEthernet0/0/0/0
312 # description this is interface0
313 # cdp
314 # !
315 # interface GigabitEthernet0/0/0/1
316 # vrf vrf_E
317 # shutdown
318 # !
319 # interface GigabitEthernet0/0/0/2
320 # vrf vrf_D
321 # shutdown
322 # !
323
324 - name: Simple deleted selective
325 cisco.iosxr.iosxr_vrf_interfaces:
326 state: deleted
327 config:
328 - name: GigabitEthernet0/0/0/1
329 vrf_name: vrf_E
330
331 # Task Output
332 # -----------
333 #
334 # before:
335 # - name: MgmtEth0/RP0/CPU0/0
336 # - name: GigabitEthernet0/0/0/0
337 # - name: GigabitEthernet0/0/0/1
338 # vrf_name: vrf_E
339 # - name: GigabitEthernet0/0/0/2
340 # vrf_name: vrf_D
341 # commands:
342 # - interface GigabitEthernet0/0/0/1
343 # - no vrf vrf_E
344 # after:
345 # - name: MgmtEth0/RP0/CPU0/0
346 # - name: GigabitEthernet0/0/0/0
347 # - name: GigabitEthernet0/0/0/1
348 # - name: GigabitEthernet0/0/0/2
349 # vrf_name: vrf_D
350
351 # After state:
352 # -------------
353 #
354 # viosxr#show running-config interfaces
355 # interface MgmtEth0/RP0/CPU0/0
356 # ipv4 address dhcp
357 # !
358 # interface GigabitEthernet0/0/0/0
359 # description this is interface0
360 # cdp
361 # !
362 # interface GigabitEthernet0/0/0/1
363 # shutdown
364 # !
365 # interface GigabitEthernet0/0/0/2
366 # vrf vrf_D
367 # shutdown
368 # !
369
370 # Using gathered
371
372 # Before state:
373 # -------------
374 #
375 # viosxr#show running-config interfaces
376 # interface MgmtEth0/RP0/CPU0/0
377 # ipv4 address dhcp
378 # !
379 # interface GigabitEthernet0/0/0/0
380 # description this is interface0
381 # cdp
382 # !
383 # interface GigabitEthernet0/0/0/1
384 # vrf vrf_C
385 # shutdown
386 # !
387 # interface GigabitEthernet0/0/0/2
388 # vrf vrf_D
389 # shutdown
390 # !
391
392 - name: Simple gathered selective
393 cisco.iosxr.iosxr_vrf_interfaces:
394 state: gathered
395
396 # Task Output
397 # -----------
398 #
399 # gathered:
400 # - name: MgmtEth0/RP0/CPU0/0
401 # - name: GigabitEthernet0/0/0/0
402 # - name: GigabitEthernet0/0/0/1
403 # vrf_name: vrf_C
404 # - name: GigabitEthernet0/0/0/2
405 # vrf_name: vrf_D
406
407 # Using rendered
408
409 # Before state:
410 # -------------
411 #
412 # viosxr#show running-config interfaces
413 # interface MgmtEth0/RP0/CPU0/0
414 # ipv4 address dhcp
415 # !
416 # interface GigabitEthernet0/0/0/0
417 # description this is interface0
418 # cdp
419 # !
420 # interface GigabitEthernet0/0/0/1
421 # vrf vrf_C
422 # shutdown
423 # !
424 # interface GigabitEthernet0/0/0/2
425 # vrf vrf_D
426 # shutdown
427 # !
428
429 - name: Simple rendered selective
430 cisco.iosxr.iosxr_vrf_interfaces:
431 state: rendered
432
433 # Task Output
434 # -----------
435 #
436 # commands:
437 # - interface GigabitEthernet0/0/0/1
438 # - vrf vrf_C
439 # - interface GigabitEthernet0/0/0/2
440 # - vrf vrf_D
441 """
442
443 RETURN = """
444 before:
445 description: The configuration prior to the module execution.
446 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
447 type: dict
448 sample: >
449 This output will always be in the same format as the
450 module argspec.
451 after:
452 description: The resulting configuration after module execution.
453 returned: when changed
454 type: dict
455 sample: >
456 This output will always be in the same format as the
457 module argspec.
458 commands:
459 description: The set of commands pushed to the remote device.
460 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
461 type: list
462 sample:
463 - interface GigabitEthernet0/0/0/1
464 - no vrf test_vrf1
465 - vrf test_vrf2
466 rendered:
467 description: The provided configuration in the task rendered in device-native format (offline).
468 returned: when I(state) is C(rendered)
469 type: list
470 sample:
471 - interface GigabitEthernet0/0/0/1
472 - no vrf test_vrf1
473 - vrf test_vrf2
474 gathered:
475 description: Facts about the network resource gathered from the remote device as structured data.
476 returned: when I(state) is C(gathered)
477 type: list
478 sample: >
479 This output will always be in the same format as the
480 module argspec.
481 parsed:
482 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
483 returned: when I(state) is C(parsed)
484 type: list
485 sample: >
486 This output will always be in the same format as the
487 module argspec.
488 """
489
490 from ansible.module_utils.basic import AnsibleModule
491
492 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.vrf_interfaces.vrf_interfaces import (
493 Vrf_interfacesArgs,
494 )
495 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.vrf_interfaces.vrf_interfaces import (
496 Vrf_interfaces,
497 )
498
499
500 def main():
501 """
502 Main entry point for module execution
503
504 :returns: the result form module invocation
505 """
506 module = AnsibleModule(
507 argument_spec=Vrf_interfacesArgs.argument_spec,
508 mutually_exclusive=[["config", "running_config"]],
509 required_if=[
510 ["state", "merged", ["config"]],
511 ["state", "replaced", ["config"]],
512 ["state", "overridden", ["config"]],
513 ["state", "rendered", ["config"]],
514 ["state", "parsed", ["running_config"]],
515 ],
516 supports_check_mode=True,
517 )
518
519 result = Vrf_interfaces(module).execute_module()
520 module.exit_json(**result)
521
522
523 if __name__ == "__main__":
524 main()