Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/modules/iosxr_lldp_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_lldp_interfaces
27 """
28
29 from __future__ import absolute_import, division, print_function
30
31
32 __metaclass__ = type
33
34
35 DOCUMENTATION = """
36 module: iosxr_lldp_interfaces
37 short_description: Resource module to configure LLDP interfaces.
38 description:
39 - This module manages Link Layer Discovery Protocol (LLDP) attributes of interfaces
40 on IOS-XR devices.
41 version_added: 1.0.0
42 notes:
43 - This module works with connection C(network_cli). See L(the IOS-XR Platform Options,../network/user_guide/platform_iosxr.html).
44 author: Nilashish Chakraborty (@nilashishc)
45 options:
46 config:
47 description: A dictionary of LLDP interfaces options.
48 type: list
49 elements: dict
50 suboptions:
51 name:
52 description:
53 - Name/Identifier of the interface or Ether-Bundle.
54 type: str
55 destination:
56 description:
57 - Specifies LLDP destination configuration on the interface.
58 suboptions:
59 mac_address:
60 description:
61 - Specifies the LLDP destination mac address on the interface.
62 type: str
63 choices:
64 - ieee-nearest-bridge
65 - ieee-nearest-non-tmpr-bridge
66 type: dict
67 receive:
68 description:
69 - Enable/disable LLDP RX on an interface.
70 type: bool
71 transmit:
72 description:
73 - Enable/disable LLDP TX on an interface.
74 type: bool
75 running_config:
76 description:
77 - This option is used only with state I(parsed).
78 - The value of this option should be the output received from the IOS-XR device
79 by executing the command B(show running-config int).
80 - The state I(parsed) reads the configuration from C(running_config) option and
81 transforms it into Ansible structured data as per the resource module's argspec
82 and the value is then returned in the I(parsed) key within the result.
83 type: str
84 state:
85 description:
86 - The state of the configuration after module completion.
87 type: str
88 choices:
89 - merged
90 - replaced
91 - overridden
92 - deleted
93 - parsed
94 - rendered
95 - gathered
96 default: merged
97
98 """
99 EXAMPLES = """
100 # Using merged
101 #
102 #
103 # ------------
104 # Before state
105 # ------------
106 #
107 #
108 # RP/0/RP0/CPU0:ios#sh run int
109 # Mon Aug 12 12:40:23.104 UTC
110 # interface TenGigE0/0/0/0
111 # ipv4 address 192.0.2.11 255.255.255.192
112 # !
113 # interface preconfigure GigabitEthernet0/0/0/1
114 # !
115 # interface preconfigure GigabitEthernet0/0/0/2
116 # !
117 #
118 #
119
120 - name: Merge provided configuration with running configuration
121 cisco.iosxr.iosxr_lldp_interfaces:
122 config:
123 - name: GigabitEthernet0/0/0/1
124 destination:
125 mac_address: ieee-nearest-non-tmpr-bridge
126 transmit: false
127 - name: GigabitEthernet0/0/0/2
128 destination:
129 mac_address: ieee-nearest-bridge
130 receive: false
131 state: merged
132
133
134 #
135 #
136 # ------------------------
137 # Module Execution Result
138 # ------------------------
139 #
140 #
141 # "before": [
142 # {
143 # "name": "TenGigE0/0/0/0"
144 # },
145 # {
146 # "name": "GigabitEthernet0/0/0/1"
147 # },
148 # {
149 # "name": "GigabitEthernet0/0/0/2"
150 # }
151 # ]
152 #
153 # "commands": [
154 # "interface GigabitEthernet0/0/0/2",
155 # "lldp destination mac-address ieee-nearest-non-tmpr-bridge",
156 # "lldp transmit disable",
157 # "interface GigabitEthernet0/0/0/1",
158 # "lldp receive disable",
159 # "lldp destination mac-address ieee-nearest-bridge"
160 # ]
161 #
162 # "after": [
163 # {
164 # "name": "TenGigE0/0/0/0"
165 # },
166 # {
167 # "destination": {
168 # "mac_address": "ieee-nearest-bridge"
169 # },
170 # "name": "GigabitEthernet0/0/0/1",
171 # "receive": false
172 # },
173 # {
174 # "destination": {
175 # "mac_address": "ieee-nearest-non-tmpr-bridge"
176 # },
177 # "name": "GigabitEthernet0/0/0/2",
178 # "transmit": false
179 # }
180 # ]
181 #
182 #
183 # ------------
184 # After state
185 # ------------
186 #
187 #
188 # RP/0/RP0/CPU0:ios#sh run int
189 # Mon Aug 12 12:49:51.517 UTC
190 # interface TenGigE0/0/0/0
191 # ipv4 address 192.0.2.11 255.255.255.192
192 # !
193 # interface preconfigure GigabitEthernet0/0/0/1
194 # lldp
195 # receive disable
196 # destination mac-address
197 # ieee-nearest-bridge
198 # !
199 # !
200 # !
201 # interface preconfigure GigabitEthernet0/0/0/2
202 # lldp
203 # transmit disable
204 # destination mac-address
205 # ieee-nearest-non-tmpr-bridge
206 # !
207 # !
208 # !
209 #
210 #
211
212
213 # Using replaced
214 #
215 #
216 # -------------
217 # Before state
218 # -------------
219 #
220 #
221 # RP/0/RP0/CPU0:ios#sh run int
222 # Mon Aug 12 12:49:51.517 UTC
223 # interface TenGigE0/0/0/0
224 # ipv4 address 192.0.2.11 255.255.255.192
225 # !
226 # interface preconfigure GigabitEthernet0/0/0/1
227 # lldp
228 # receive disable
229 # destination mac-address
230 # ieee-nearest-bridge
231 # !
232 # !
233 # !
234 # interface preconfigure GigabitEthernet0/0/0/2
235 # lldp
236 # transmit disable
237 # destination mac-address
238 # ieee-nearest-non-tmpr-bridge
239 # !
240 # !
241 # !
242 #
243 #
244
245 - name: >-
246 Replace existing LLDP configurations of specified interfaces with provided
247 configuration
248 cisco.iosxr.iosxr_lldp_interfaces:
249 config:
250 - name: GigabitEthernet0/0/0/1
251 destination:
252 mac_address: ieee-nearest-non-tmpr-bridge
253 state: replaced
254
255
256 #
257 #
258 # ------------------------
259 # Module Execution Result
260 # ------------------------
261 #
262 # "before": [
263 # {
264 # "name": "TenGigE0/0/0/0"
265 # },
266 # {
267 # "destination": {
268 # "mac_address": "ieee-nearest-bridge"
269 # },
270 # "name": "GigabitEthernet0/0/0/1",
271 # "receive": false
272 # },
273 # {
274 # "destination": {
275 # "mac_address": "ieee-nearest-non-tmpr-bridge"
276 # },
277 # "name": "GigabitEthernet0/0/0/2",
278 # "transmit": false
279 # }
280 # ]
281 #
282 #
283 # "commands": [
284 # "interface GigabitEthernet0/0/0/1",
285 # "no lldp receive disable",
286 # "lldp destination mac-address ieee-nearest-non-tmpr-bridge"
287 # ]
288 #
289 #
290 # "after": [
291 # {
292 # "name": "TenGigE0/0/0/0"
293 # },
294 # {
295 # "destination": {
296 # "mac_address": "ieee-nearest-non-tmpr-bridge"
297 # },
298 # "name": "GigabitEthernet0/0/0/1"
299 # },
300 # {
301 # "destination": {
302 # "mac_address": "ieee-nearest-non-tmpr-bridge"
303 # },
304 # "name": "GigabitEthernet0/0/0/2",
305 # "transmit": false
306 # }
307 # ]
308 #
309 #
310 # ------------
311 # After state
312 # ------------
313 #
314 #
315 # RP/0/RP0/CPU0:ios#sh run int
316 # Mon Aug 12 13:02:57.062 UTC
317 # interface TenGigE0/0/0/0
318 # ipv4 address 192.0.2.11 255.255.255.192
319 # !
320 # interface preconfigure GigabitEthernet0/0/0/1
321 # lldp
322 # destination mac-address
323 # ieee-nearest-non-tmpr-bridge
324 # !
325 # !
326 # !
327 # interface preconfigure GigabitEthernet0/0/0/2
328 # lldp
329 # transmit disable
330 # destination mac-address
331 # ieee-nearest-non-tmpr-bridge
332 # !
333 # !
334 # !
335 #
336 #
337
338
339 # Using overridden
340 #
341 #
342 # -------------
343 # Before state
344 # -------------
345 #
346 #
347 # RP/0/RP0/CPU0:ios#sh run int
348 # Mon Aug 12 13:15:40.465 UTC
349 # interface TenGigE0/0/0/0
350 # ipv4 address 192.0.2.11 255.255.255.192
351 # !
352 # interface preconfigure GigabitEthernet0/0/0/1
353 # lldp
354 # receive disable
355 # destination mac-address
356 # ieee-nearest-bridge
357 # !
358 # !
359 # !
360 # interface preconfigure GigabitEthernet0/0/0/2
361 # lldp
362 # transmit disable
363 # destination mac-address
364 # ieee-nearest-non-tmpr-bridge
365 # !
366 # !
367 # !
368 #
369 #
370
371 - name: >-
372 Override the LLDP configurations of all the interfaces with provided
373 configurations
374 cisco.iosxr.iosxr_lldp_interfaces:
375 config:
376 - name: GigabitEthernet0/0/0/1
377 transmit: false
378 state: overridden
379
380
381 #
382 #
383 # ------------------------
384 # Module Execution Result
385 # ------------------------
386 #
387 #
388 # "before": [
389 # {
390 # "name": "TenGigE0/0/0/0"
391 # },
392 # {
393 # "destination": {
394 # "mac_address": "ieee-nearest-bridge"
395 # },
396 # "name": "GigabitEthernet0/0/0/1",
397 # "receive": false
398 # },
399 # {
400 # "destination": {
401 # "mac_address": "ieee-nearest-non-tmpr-bridge"
402 # },
403 # "name": "GigabitEthernet0/0/0/2",
404 # "transmit": false
405 # }
406 # ]
407 #
408 # "commands": [
409 # "interface GigabitEthernet0/0/0/2",
410 # "no lldp destination mac-address ieee-nearest-non-tmpr-bridge",
411 # "no lldp transmit disable",
412 # "interface GigabitEthernet0/0/0/1",
413 # "no lldp destination mac-address ieee-nearest-bridge",
414 # "no lldp receive disable",
415 # "lldp transmit disable"
416 # ]
417 #
418 #
419 # "after": [
420 # {
421 # "name": "TenGigE0/0/0/0"
422 # },
423 # {
424 # "name": "GigabitEthernet0/0/0/1",
425 # "transmit": false
426 # },
427 # {
428 # "name": "GigabitEthernet0/0/0/2"
429 # }
430 # ]
431 #
432 #
433 # ------------
434 # After state
435 # ------------
436 #
437 #
438 # RP/0/RP0/CPU0:ios#sh run int
439 # Mon Aug 12 13:22:25.604 UTC
440 # interface TenGigE0/0/0/0
441 # ipv4 address 192.0.2.11 255.255.255.192
442 # !
443 # interface preconfigure GigabitEthernet0/0/0/1
444 # lldp
445 # transmit disable
446 # !
447 # !
448 # interface preconfigure GigabitEthernet0/0/0/2
449 # !
450 #
451 #
452
453
454 # Using deleted
455 #
456 #
457 # -------------
458 # Before state
459 # -------------
460 #
461 #
462 # RP/0/RP0/CPU0:ios#sh run int
463 # Mon Aug 12 13:26:21.498 UTC
464 # interface TenGigE0/0/0/0
465 # ipv4 address 192.0.2.11 255.255.255.192
466 # !
467 # interface preconfigure GigabitEthernet0/0/0/1
468 # lldp
469 # receive disable
470 # destination mac-address
471 # ieee-nearest-bridge
472 # !
473 # !
474 # !
475 # interface preconfigure GigabitEthernet0/0/0/2
476 # lldp
477 # transmit disable
478 # destination mac-address
479 # ieee-nearest-non-tmpr-bridge
480 # !
481 # !
482 # !
483 #
484 #
485
486 - name: Delete LLDP configurations of all interfaces (Note - This won't delete the
487 interfaces themselves)
488 cisco.iosxr.iosxr_lldp_interfaces:
489 state: deleted
490
491 #
492 #
493 #
494 # ------------------------
495 # Module Execution Result
496 # ------------------------
497 #
498 #
499 # "before": [
500 # {
501 # "name": "TenGigE0/0/0/0"
502 # },
503 # {
504 # "destination": {
505 # "mac_address": "ieee-nearest-bridge"
506 # },
507 # "name": "GigabitEthernet0/0/0/1",
508 # "receive": false
509 # },
510 # {
511 # "destination": {
512 # "mac_address": "ieee-nearest-non-tmpr-bridge"
513 # },
514 # "name": "GigabitEthernet0/0/0/2",
515 # "transmit": false
516 # }
517 # ]
518 #
519 #
520 # "commands": [
521 # "interface GigabitEthernet0/0/0/1",
522 # "no lldp destination mac-address ieee-nearest-bridge",
523 # "no lldp receive disable",
524 # "interface GigabitEthernet0/0/0/2",
525 # "no lldp destination mac-address ieee-nearest-non-tmpr-bridge",
526 # "no lldp transmit disable"
527 # ]
528 #
529 #
530 # "after": [
531 # {
532 # "name": "TenGigE0/0/0/0"
533 # },
534 # {
535 # "name": "GigabitEthernet0/0/0/1"
536 # },
537 # {
538 # "name": "GigabitEthernet0/0/0/2"
539 # }
540 # ]
541 #
542 #
543 # ------------
544 # After state
545 # ------------
546 #
547 #
548 # RP/0/RP0/CPU0:ios#sh run int
549 # Mon Aug 12 13:30:14.618 UTC
550 # interface TenGigE0/0/0/0
551 # ipv4 address 192.0.2.11 255.255.255.192
552 # !
553 # interface preconfigure GigabitEthernet0/0/0/1
554 # !
555 # interface preconfigure GigabitEthernet0/0/0/2
556 # !
557 #
558 #
559 # Using parsed:
560 # parsed.cfg
561
562 # interface TenGigE0/0/0/0
563 # ipv4 address 192.0.2.11 255.255.255.192
564 # !
565 # interface preconfigure GigabitEthernet0/0/0/1
566 # lldp
567 # receive disable
568 # destination mac-address
569 # ieee-nearest-bridge
570 # !
571 # !
572 # !
573 # interface preconfigure GigabitEthernet0/0/0/2
574 # lldp
575 # transmit disable
576 # destination mac-address
577 # ieee-nearest-non-tmpr-bridge
578
579 - name: Convert lacp interfaces config to argspec without connecting to the appliance
580 cisco.iosxr.iosxr_lldp_interfaces:
581 running_config: "{{ lookup('file', './parsed.cfg') }}"
582 state: parsed
583
584 # ------------------------
585 # Module Execution Result
586 # ------------------------
587
588 # parsed: [
589 # - name: GigabitEthernet0/0/0/1
590 # destination:
591 # mac_address: ieee-nearest-non-tmpr-bridge
592 # transmit: False
593
594 # - name: GigabitEthernet0/0/0/2
595 # destination:
596 # mac_address: ieee-nearest-bridge
597 # receive: False
598 # ]
599
600 # Using gathered:
601 # Device config:
602
603 # RP/0/RP0/CPU0:ios#sh run int
604 # Mon Aug 12 12:49:51.517 UTC
605 # interface TenGigE0/0/0/0
606 # ipv4 address 192.0.2.11 255.255.255.192
607 # !
608 # interface preconfigure GigabitEthernet0/0/0/1
609 # lldp
610 # receive disable
611 # destination mac-address
612 # ieee-nearest-bridge
613 # !
614 # !
615 # !
616 # interface preconfigure GigabitEthernet0/0/0/2
617 # lldp
618 # transmit disable
619 # destination mac-address
620 # ieee-nearest-non-tmpr-bridge
621
622 - name: Gather IOSXR lldp interfaces configuration
623 cisco.iosxr.iosxr_lldp_interfaces:
624 config:
625 state: gathered
626
627 # ------------------------
628 # Module Execution Result
629 # ------------------------
630
631 # gathered:
632 # - name: GigabitEthernet0/0/0/1
633 # destination:
634 # mac_address: ieee-nearest-non-tmpr-bridge
635 # transmit: False
636
637 # - name: GigabitEthernet0/0/0/2
638 # destination:
639 # mac_address: ieee-nearest-bridge
640 # receive: False
641
642 # Using rendred:
643 - name: Render platform specific commands from task input using rendered state
644 cisco.iosxr.iosxr_lldp_interfaces:
645 config:
646 - name: GigabitEthernet0/0/0/1
647 destination:
648 mac_address: ieee-nearest-non-tmpr-bridge
649 transmit: false
650 - name: GigabitEthernet0/0/0/2
651 destination:
652 mac_address: ieee-nearest-bridge
653 receive: false
654 state: rendered
655 # ------------------------
656 # Module Execution Result
657 # ------------------------
658
659 # "rendered": [
660 # "interface GigabitEthernet0/0/0/2",
661 # "lldp destination mac-address ieee-nearest-non-tmpr-bridge",
662 # "lldp transmit disable",
663 # "interface GigabitEthernet0/0/0/1",
664 # "lldp receive disable",
665 # "lldp destination mac-address ieee-nearest-bridge"
666 # ]
667 """
668 RETURN = """
669 before:
670 description: The configuration as structured data prior to module invocation.
671 returned: always
672 type: list
673 sample: >
674 The configuration returned will always be in the same format
675 of the parameters above.
676 after:
677 description: The configuration as structured data after module completion.
678 returned: when changed
679 type: list
680 sample: >
681 The configuration returned will always be in the same format
682 of the parameters above.
683 commands:
684 description: The set of commands pushed to the remote device.
685 returned: always
686 type: list
687 sample: ['interface GigabitEthernet0/0/0/1', 'lldp destination mac-address ieee-nearest-non-tmpr-bridge', 'no lldp transmit disable']
688 """
689
690
691 from ansible.module_utils.basic import AnsibleModule
692
693 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.lldp_interfaces.lldp_interfaces import (
694 Lldp_interfacesArgs,
695 )
696 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.lldp_interfaces.lldp_interfaces import (
697 Lldp_interfaces,
698 )
699
700
701 def main():
702 """
703 Main entry point for module execution
704
705 :returns: the result form module invocation
706 """
707 required_if = [
708 ("state", "merged", ("config",)),
709 ("state", "replaced", ("config",)),
710 ("state", "overridden", ("config",)),
711 ("state", "rendered", ("config",)),
712 ("state", "parsed", ("running_config",)),
713 ]
714 mutually_exclusive = [("config", "running_config")]
715 module = AnsibleModule(
716 argument_spec=Lldp_interfacesArgs.argument_spec,
717 required_if=required_if,
718 supports_check_mode=True,
719 mutually_exclusive=mutually_exclusive,
720 )
721
722 result = Lldp_interfaces(module).execute_module()
723 module.exit_json(**result)
724
725
726 if __name__ == "__main__":
727 main()