Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2019 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 # WARNING #
9 #############################################
10 #
11 # This file is auto generated by the resource
12 # module builder playbook.
13 #
14 # Do not edit this file manually.
15 #
16 # Changes to this file will be over written
17 # by the resource module builder.
18 #
19 # Changes should be made in the model used to
20 # generate this file or in the resource module
21 # builder template.
22 #
23 #############################################
24
25 """
26 The module file for iosxr_acl_interfaces
27 """
28
29 from __future__ import absolute_import, division, print_function
30
31
32 __metaclass__ = type
33
34
35 DOCUMENTATION = """
36 module: iosxr_acl_interfaces
37 short_description: Resource module to configure ACL interfaces.
38 description:
39 - This module manages adding and removing Access Control Lists (ACLs) from interfaces
40 on devices running IOS-XR software.
41 version_added: 1.0.0
42 author: Nilashish Chakraborty (@NilashishC)
43 options:
44 config:
45 description: A dictionary of ACL options for interfaces.
46 type: list
47 elements: dict
48 suboptions:
49 name:
50 description:
51 - Name/Identifier for the interface
52 type: str
53 required: true
54 access_groups:
55 type: list
56 elements: dict
57 description:
58 - Specifies ACLs attached to the interfaces.
59 suboptions:
60 afi:
61 description:
62 - Specifies the AFI for the ACL(s) to be configured on this interface.
63 type: str
64 choices:
65 - ipv4
66 - ipv6
67 required: true
68 acls:
69 type: list
70 description:
71 - Specifies the ACLs for the provided AFI.
72 elements: dict
73 suboptions:
74 name:
75 description:
76 - Specifies the name of the IPv4/IPv6 ACL for the interface.
77 type: str
78 required: true
79 direction:
80 description:
81 - Specifies the direction of packets that the ACL will be applied
82 on.
83 type: str
84 choices:
85 - in
86 - out
87 required: true
88 running_config:
89 description:
90 - This option is used only with state I(parsed).
91 - The value of this option should be the output received from the IOS-XR device
92 by executing the command B(show running-config interface).
93 - The state I(parsed) reads the configuration from C(running_config) option and
94 transforms it into Ansible structured data as per the resource module's argspec
95 and the value is then returned in the I(parsed) key within the result.
96 type: str
97 state:
98 description:
99 - The state the configuration should be left in.
100 type: str
101 choices:
102 - merged
103 - replaced
104 - overridden
105 - deleted
106 - gathered
107 - parsed
108 - rendered
109 default: merged
110
111 """
112 EXAMPLES = """
113 # Using merged
114
115 # Before state:
116 # -------------
117 #
118 # RP/0/RP0/CPU0:ios#sh running-config interface
119 # Wed Jan 15 12:22:32.911 UTC
120 # interface MgmtEth0/RP0/CPU0/0
121 # ipv4 address dhcp
122 # !
123 # interface GigabitEthernet0/0/0/0
124 # shutdown
125 # !
126 # interface GigabitEthernet0/0/0/1
127 # shutdown
128 # !
129
130 - name: Merge the provided configuration with the existing running configuration
131 cisco.iosxr.iosxr_acl_interfaces:
132 config:
133 - name: GigabitEthernet0/0/0/0
134 access_groups:
135 - afi: ipv4
136 acls:
137 - name: acl_1
138 direction: in
139 - name: acl_2
140 direction: out
141 - afi: ipv6
142 acls:
143 - name: acl6_1
144 direction: in
145 - name: acl6_2
146 direction: out
147 - name: GigabitEthernet0/0/0/1
148 access_groups:
149 - afi: ipv4
150 acls:
151 - name: acl_1
152 direction: out
153 state: merged
154
155 # After state:
156 # -------------
157 #
158 # RP/0/RP0/CPU0:ios#sh running-config interface
159 # Wed Jan 15 12:27:49.378 UTC
160 # interface MgmtEth0/RP0/CPU0/0
161 # ipv4 address dhcp
162 # !
163 # interface GigabitEthernet0/0/0/0
164 # shutdown
165 # ipv4 access-group acl_1 ingress
166 # ipv4 access-group acl_2 egress
167 # ipv6 access-group acl6_1 ingress
168 # ipv6 access-group acl6_2 egress
169 # !
170 # interface GigabitEthernet0/0/0/1
171 # shutdown
172 # ipv4 access-group acl_1 egress
173 # !
174
175 # Using merged to update interface ACL configuration
176
177 # Before state:
178 # -------------
179 #
180 # RP/0/RP0/CPU0:ios#sh running-config interface
181 # Wed Jan 15 12:27:49.378 UTC
182 # interface MgmtEth0/RP0/CPU0/0
183 # ipv4 address dhcp
184 # !
185 # interface GigabitEthernet0/0/0/0
186 # shutdown
187 # ipv4 access-group acl_1 ingress
188 # ipv4 access-group acl_2 egress
189 # ipv6 access-group acl6_1 ingress
190 # ipv6 access-group acl6_2 egress
191 # !
192 # interface GigabitEthernet0/0/0/1
193 # shutdown
194 # ipv4 access-group acl_1 egress
195 # !
196 #
197
198 - name: Update acl_interfaces configuration using merged
199 cisco.iosxr.iosxr_acl_interfaces:
200 config:
201 - name: GigabitEthernet0/0/0/1
202 access_groups:
203 - afi: ipv4
204 acls:
205 - name: acl_2
206 direction: out
207 - name: acl_1
208 direction: in
209 state: merged
210
211 # After state:
212 # -------------
213 #
214 # RP/0/RP0/CPU0:ios#sh running-config interface
215 # Wed Jan 15 12:27:49.378 UTC
216 # interface MgmtEth0/RP0/CPU0/0
217 # ipv4 address dhcp
218 # !
219 # interface GigabitEthernet0/0/0/0
220 # shutdown
221 # ipv4 access-group acl_1 ingress
222 # ipv4 access-group acl_2 egress
223 # ipv6 access-group acl6_1 ingress
224 # ipv6 access-group acl6_2 egress
225 # !
226 # interface GigabitEthernet0/0/0/1
227 # shutdown
228 # ipv4 access-group acl_1 ingress
229 # ipv4 access-group acl_2 egress
230 # !
231 #
232
233 # Using replaced
234
235 # Before state:
236 # -------------
237 #
238 # RP/0/RP0/CPU0:ios#sh running-config interface
239 # Wed Jan 15 12:34:56.689 UTC
240 # interface MgmtEth0/RP0/CPU0/0
241 # ipv4 address dhcp
242 # !
243 # interface GigabitEthernet0/0/0/0
244 # shutdown
245 # ipv4 access-group acl_1 ingress
246 # ipv4 access-group acl_2 egress
247 # ipv6 access-group acl6_1 ingress
248 # ipv6 access-group acl6_2 egress
249 # !
250 # interface GigabitEthernet0/0/0/1
251 # shutdown
252 # ipv4 access-group acl_1 egress
253 # !
254
255 - name: >-
256 Replace device configurations of listed interface with provided
257 configurations
258 cisco.iosxr.iosxr_acl_interfaces:
259 config:
260 - name: GigabitEthernet0/0/0/0
261 access_groups:
262 - afi: ipv6
263 acls:
264 - name: acl6_3
265 direction: in
266 state: replaced
267
268 # After state:
269 # -------------
270 #
271 # RP/0/RP0/CPU0:ios#sh running-config interface
272 # Wed Jan 15 12:34:56.689 UTC
273 # interface MgmtEth0/RP0/CPU0/0
274 # ipv4 address dhcp
275 # !
276 # interface GigabitEthernet0/0/0/0
277 # shutdown
278 # ipv6 access-group acl6_3 ingress
279 # !
280 # interface GigabitEthernet0/0/0/1
281 # shutdown
282 # ipv4 access-group acl_1 egress
283 # !
284 #
285
286 # Using overridden
287
288 # Before state:
289 # -------------
290 #
291 # RP/0/RP0/CPU0:ios#sh running-config interface
292 # Wed Jan 15 12:34:56.689 UTC
293 # interface MgmtEth0/RP0/CPU0/0
294 # ipv4 address dhcp
295 # !
296 # interface GigabitEthernet0/0/0/0
297 # shutdown
298 # ipv4 access-group acl_1 ingress
299 # ipv4 access-group acl_2 egress
300 # ipv6 access-group acl6_1 ingress
301 # ipv6 access-group acl6_2 egress
302 # !
303 # interface GigabitEthernet0/0/0/1
304 # shutdown
305 # ipv4 access-group acl_1 egress
306 # !
307 #
308
309 - name: Overridde all interface ACL configuration with provided configuration
310 cisco.iosxr.iosxr_acl_interfaces:
311 config:
312 - name: GigabitEthernet0/0/0/1
313 access_groups:
314 - afi: ipv4
315 acls:
316 - name: acl_2
317 direction: in
318 - afi: ipv6
319 acls:
320 - name: acl6_3
321 direction: out
322 state: overridden
323
324 # After state:
325 # -------------
326 #
327 # RP/0/RP0/CPU0:ios#sh running-config interface
328 # Wed Jan 15 12:34:56.689 UTC
329 # interface MgmtEth0/RP0/CPU0/0
330 # ipv4 address dhcp
331 # !
332 # interface GigabitEthernet0/0/0/0
333 # shutdown
334 # !
335 # interface GigabitEthernet0/0/0/1
336 # shutdown
337 # ipv4 access-group acl_2 ingress
338 # ipv6 access-group acl6_3 egress
339 # !
340 #
341
342 # Using 'deleted' to delete all ACL attributes of a single interface
343
344 # Before state:
345 # -------------
346 #
347 # RP/0/RP0/CPU0:ios#sh running-config interface
348 # Wed Jan 15 12:34:56.689 UTC
349 # interface MgmtEth0/RP0/CPU0/0
350 # ipv4 address dhcp
351 # !
352 # interface GigabitEthernet0/0/0/0
353 # shutdown
354 # ipv4 access-group acl_1 ingress
355 # ipv4 access-group acl_2 egress
356 # ipv6 access-group acl6_1 ingress
357 # ipv6 access-group acl6_2 egress
358 # !
359 # interface GigabitEthernet0/0/0/1
360 # shutdown
361 # ipv4 access-group acl_1 egress
362 # !
363 #
364
365 - name: Delete all ACL attributes of GigabitEthernet0/0/0/1
366 cisco.iosxr.iosxr_acl_interfaces:
367 config:
368 - name: GigabitEthernet0/0/0/1
369 state: deleted
370
371 # After state:
372 # -------------
373 #
374 # RP/0/RP0/CPU0:ios#sh running-config interface
375 # Wed Jan 15 12:34:56.689 UTC
376 # interface MgmtEth0/RP0/CPU0/0
377 # ipv4 address dhcp
378 # !
379 # interface GigabitEthernet0/0/0/0
380 # shutdown
381 # ipv4 access-group acl_1 ingress
382 # ipv4 access-group acl_2 egress
383 # ipv6 access-group acl6_1 ingress
384 # ipv6 access-group acl6_2 egress
385 # !
386 # interface GigabitEthernet0/0/0/1
387 # shutdown
388 # !
389 #
390
391 # Using 'deleted' to remove all ACLs attached to all the interfaces in the device
392
393 # Before state:
394 # -------------
395 #
396 # RP/0/RP0/CPU0:ios#sh running-config interface
397 # Wed Jan 15 12:34:56.689 UTC
398 # interface MgmtEth0/RP0/CPU0/0
399 # ipv4 address dhcp
400 # !
401 # interface GigabitEthernet0/0/0/0
402 # shutdown
403 # ipv4 access-group acl_1 ingress
404 # ipv4 access-group acl_2 egress
405 # ipv6 access-group acl6_1 ingress
406 # ipv6 access-group acl6_2 egress
407 # !
408 # interface GigabitEthernet0/0/0/1
409 # shutdown
410 # ipv4 access-group acl_1 egress
411 # !
412 #
413
414 - name: Delete all ACL interfaces configuration from the device
415 cisco.iosxr.iosxr_acl_interfaces:
416 state: deleted
417
418 # After state:
419 # -------------
420 #
421 # RP/0/RP0/CPU0:ios#sh running-config interface
422 # Wed Jan 15 12:34:56.689 UTC
423 # interface MgmtEth0/RP0/CPU0/0
424 # ipv4 address dhcp
425 # !
426 # interface GigabitEthernet0/0/0/0
427 # shutdown
428 # !
429 # interface GigabitEthernet0/0/0/1
430 # shutdown
431 # !
432 #
433
434 # Using parsed
435
436 # parsed.cfg
437 # ------------
438 #
439 # interface MgmtEth0/RP0/CPU0/0
440 # ipv4 address dhcp
441 # !
442 # interface GigabitEthernet0/0/0/0
443 # shutdown
444 # ipv4 access-group acl_1 ingress
445 # ipv4 access-group acl_2 egress
446 # ipv6 access-group acl6_1 ingress
447 # ipv6 access-group acl6_2 egress
448 # !
449 # interface GigabitEthernet0/0/0/1
450 # shutdown
451 # ipv4 access-group acl_1 egress
452 # !
453
454 # - name: Convert ACL interfaces config to argspec without connecting to the appliance
455 # cisco.iosxr.iosxr_acl_interfaces:
456 # running_config: "{{ lookup('file', './parsed.cfg') }}"
457 # state: parsed
458
459
460 # Task Output (redacted)
461 # -----------------------
462
463 # "parsed": [
464 # {
465 # "name": "MgmtEth0/RP0/CPU0/0"
466 # },
467 # {
468 # "access_groups": [
469 # {
470 # "acls": [
471 # {
472 # "direction": "in",
473 # "name": "acl_1"
474 # },
475 # {
476 # "direction": "out",
477 # "name": "acl_2"
478 # }
479 # ],
480 # "afi": "ipv4"
481 # },
482 # {
483 # "acls": [
484 # {
485 # "direction": "in",
486 # "name": "acl6_1"
487 # },
488 # {
489 # "direction": "out",
490 # "name": "acl6_2"
491 # }
492 # ],
493 # "afi": "ipv6"
494 # }
495 # ],
496 # "name": "GigabitEthernet0/0/0/0"
497 # },
498 # {
499 # "access_groups": [
500 # {
501 # "acls": [
502 # {
503 # "direction": "out",
504 # "name": "acl_1"
505 # }
506 # ],
507 # "afi": "ipv4"
508 # }
509 # ],
510 # "name": "GigabitEthernet0/0/0/1"
511 # }
512 # ]
513 # }
514
515
516 # Using gathered
517
518 - name: Gather ACL interfaces facts using gathered state
519 cisco.iosxr.iosxr_acl_interfaces:
520 state: gathered
521
522
523 # Task Output (redacted)
524 # -----------------------
525 #
526 # "gathered": [
527 # {
528 # "name": "MgmtEth0/RP0/CPU0/0"
529 # },
530 # {
531 # "access_groups": [
532 # {
533 # "acls": [
534 # {
535 # "direction": "in",
536 # "name": "acl_1"
537 # },
538 # {
539 # "direction": "out",
540 # "name": "acl_2"
541 # }
542 # ],
543 # "afi": "ipv4"
544 # }
545 # "name": "GigabitEthernet0/0/0/0"
546 # },
547 # {
548 # "access_groups": [
549 # {
550 # "acls": [
551 # {
552 # "direction": "in",
553 # "name": "acl6_1"
554 # }
555 # ],
556 # "afi": "ipv6"
557 # }
558 # "name": "GigabitEthernet0/0/0/1"
559 # }
560 # ]
561
562
563 # Using rendered
564
565 - name: Render platform specific commands from task input using rendered state
566 cisco.iosxr.iosxr_acl_interfaces:
567 config:
568 - name: GigabitEthernet0/0/0/0
569 access_groups:
570 - afi: ipv4
571 acls:
572 - name: acl_1
573 direction: in
574 - name: acl_2
575 direction: out
576 state: rendered
577
578 # Task Output (redacted)
579 # -----------------------
580
581 # "rendered": [
582 # "interface GigabitEthernet0/0/0/0",
583 # "ipv4 access-group acl_1 ingress",
584 # "ipv4 access-group acl_2 egress"
585 # ]
586 """
587 RETURN = """
588 before:
589 description: The configuration prior to the model invocation.
590 returned: always
591 type: list
592 sample: >
593 The configuration returned will always be in the same format
594 of the parameters above.
595 after:
596 description: The resulting configuration model invocation.
597 returned: when changed
598 type: list
599 sample: >
600 The configuration returned will always be in the same format
601 of the parameters above.
602 commands:
603 description: The set of commands pushed to the remote device.
604 returned: always
605 type: list
606 sample:
607 - "interface GigabitEthernet0/0/0/1"
608 - "ipv4 access-group acl_1 ingress"
609 - "ipv4 access-group acl_2 egress"
610 - "ipv6 access-group acl6_1 ingress"
611 - "interface GigabitEthernet0/0/0/2"
612 - "no ipv4 access-group acl_3 ingress"
613 - "ipv4 access-group acl_4 egress"
614 """
615
616
617 from ansible.module_utils.basic import AnsibleModule
618
619 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.acl_interfaces.acl_interfaces import (
620 Acl_interfacesArgs,
621 )
622 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.acl_interfaces.acl_interfaces import (
623 Acl_interfaces,
624 )
625
626
627 def main():
628 """
629 Main entry point for module execution
630
631 :returns: the result form module invocation
632 """
633 required_if = [
634 ("state", "merged", ("config",)),
635 ("state", "replaced", ("config",)),
636 ("state", "overridden", ("config",)),
637 ("state", "rendered", ("config",)),
638 ("state", "parsed", ("running_config",)),
639 ]
640 mutually_exclusive = [("config", "running_config")]
641
642 module = AnsibleModule(
643 argument_spec=Acl_interfacesArgs.argument_spec,
644 required_if=required_if,
645 mutually_exclusive=mutually_exclusive,
646 supports_check_mode=True,
647 )
648
649 result = Acl_interfaces(module).execute_module()
650 module.exit_json(**result)
651
652
653 if __name__ == "__main__":
654 main()