Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/modules/iosxr_lldp_global.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_global
27 """
28
29 from __future__ import absolute_import, division, print_function
30
31
32 __metaclass__ = type
33
34
35 DOCUMENTATION = """
36 module: iosxr_lldp_global
37 short_description: Resource module to configure LLDP.
38 description:
39 - This module manages Global Link Layer Discovery Protocol (LLDP) settings on IOS-XR
40 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: The provided global LLDP configuration.
48 type: dict
49 suboptions:
50 holdtime:
51 description:
52 - Specifies the holdtime (in sec) to be sent in packets.
53 type: int
54 reinit:
55 description:
56 - Specifies the delay (in sec) for LLDP initialization on any interface.
57 type: int
58 subinterfaces:
59 description:
60 - Enable or disable LLDP over sub-interfaces.
61 type: bool
62 timer:
63 description:
64 - Specifies the rate at which LLDP packets are sent (in sec).
65 type: int
66 tlv_select:
67 description:
68 - Specifies the LLDP TLVs to enable or disable.
69 type: dict
70 suboptions:
71 management_address:
72 description:
73 - Enable or disable management address TLV.
74 type: bool
75 port_description:
76 description:
77 - Enable or disable port description TLV.
78 type: bool
79 system_capabilities:
80 description:
81 - Enable or disable system capabilities TLV.
82 type: bool
83 system_description:
84 description:
85 - Enable or disable system description TLV.
86 type: bool
87 system_name:
88 description:
89 - Enable or disable system name TLV.
90 type: bool
91 running_config:
92 description:
93 - This option is used only with state I(parsed).
94 - The value of this option should be the output received from the IOS-XR device
95 by executing the command B(show running-config lldp).
96 - The state I(parsed) reads the configuration from C(running_config) option and
97 transforms it into Ansible structured data as per the resource module's argspec
98 and the value is then returned in the I(parsed) key within the result.
99 type: str
100 state:
101 description:
102 - The state of the configuration after module completion.
103 type: str
104 choices:
105 - merged
106 - replaced
107 - deleted
108 - parsed
109 - gathered
110 - rendered
111 - overridden
112 default: merged
113
114 """
115 EXAMPLES = """
116 # Using merged
117 #
118 #
119 # -------------
120 # Before State
121 # -------------
122 #
123 #
124 # RP/0/0/CPU0:an-iosxr#sh run lldp
125 # Tue Aug 6 19:27:54.933 UTC
126 # % No such configuration item(s)
127 #
128 #
129
130 - name: Merge provided LLDP configuration with the existing configuration
131 cisco.iosxr.iosxr_lldp_global:
132 config:
133 holdtime: 100
134 reinit: 2
135 timer: 3000
136 subinterfaces: true
137 tlv_select:
138 management_address: false
139 system_description: false
140 state: merged
141
142 #
143 #
144 # ------------------------
145 # Module Execution Result
146 # ------------------------
147 #
148 # "before": {}
149 #
150 # "commands": [
151 # "lldp subinterfaces enable",
152 # "lldp holdtime 100",
153 # "lldp reinit 2",
154 # "lldp tlv-select system-description disable",
155 # "lldp tlv-select management-address disable",
156 # "lldp timer 3000"
157 # ]
158 #
159 # "after": {
160 # "holdtime": 100,
161 # "reinit": 2,
162 # "subinterfaces": true,
163 # "timer": 3000,
164 # "tlv_select": {
165 # "management_address": false,
166 # "system_description": false
167 # }
168 # }
169 #
170 #
171 # ------------
172 # After state
173 # ------------
174 #
175 #
176 # RP/0/0/CPU0:an-iosxr#sh run lldp
177 # Tue Aug 6 21:31:10.587 UTC
178 # lldp
179 # timer 3000
180 # reinit 2
181 # subinterfaces enable
182 # holdtime 100
183 # tlv-select
184 # management-address disable
185 # system-description disable
186 # !
187 # !
188 #
189 #
190
191
192 # Using replaced
193 #
194 #
195 # -------------
196 # Before State
197 # -------------
198 #
199 # RP/0/0/CPU0:an-iosxr#sh run lldp
200 # Tue Aug 6 21:31:10.587 UTC
201 # lldp
202 # timer 3000
203 # reinit 2
204 # subinterfaces enable
205 # holdtime 100
206 # tlv-select
207 # management-address disable
208 # system-description disable
209 # !
210 # !
211 #
212 #
213
214 - name: Replace existing LLDP device configuration with provided configuration
215 cisco.iosxr.iosxr_lldp_global:
216 config:
217 holdtime: 100
218 tlv_select:
219 port_description: false
220 system_description: true
221 management_description: true
222 state: replaced
223
224 #
225 #
226 # ------------------------
227 # Module Execution Result
228 # ------------------------
229 #
230 # "before": {
231 # "holdtime": 100,
232 # "reinit": 2,
233 # "subinterfaces": true,
234 # "timer": 3000,
235 # "tlv_select": {
236 # "management_address": false,
237 # "system_description": false
238 # }
239 # }
240 #
241 # "commands": [
242 # "no lldp reinit 2",
243 # "no lldp subinterfaces enable",
244 # "no lldp timer 3000",
245 # "no lldp tlv-select management-address disable",
246 # "no lldp tlv-select system-description disable",
247 # "lldp tlv-select port-description disable"
248 # ]
249 #
250 # "after": {
251 # "holdtime": 100,
252 # "tlv_select": {
253 # "port_description": false
254 # }
255 # }
256 #
257 #
258 # ------------
259 # After state
260 # ------------
261 #
262 # RP/0/0/CPU0:an-iosxr#sh run lldp
263 # Tue Aug 6 21:53:08.407 UTC
264 # lldp
265 # holdtime 100
266 # tlv-select
267 # port-description disable
268 # !
269 # !
270 #
271 #
272
273
274 # Using deleted
275 #
276 # ------------
277 # Before state
278 # ------------
279 #
280 #
281 # RP/0/0/CPU0:an-iosxr#sh run lldp
282 # Tue Aug 6 21:31:10.587 UTC
283 # lldp
284 # timer 3000
285 # reinit 2
286 # subinterfaces enable
287 # holdtime 100
288 # tlv-select
289 # management-address disable
290 # system-description disable
291 # !
292 # !
293 #
294 #
295
296 - name: Deleted existing LLDP configurations from the device
297 cisco.iosxr.iosxr_lldp_global:
298 state: deleted
299
300 #
301 #
302 # ------------------------
303 # Module Execution Result
304 # ------------------------
305 #
306 # "before": {
307 # "holdtime": 100,
308 # "reinit": 2,
309 # "subinterfaces": true,
310 # "timer": 3000,
311 # "tlv_select": {
312 # "management_address": false,
313 # "system_description": false
314 # }
315 # },
316 #
317 # "commands": [
318 # "no lldp holdtime 100",
319 # "no lldp reinit 2",
320 # "no lldp subinterfaces enable",
321 # "no lldp timer 3000",
322 # "no lldp tlv-select management-address disable",
323 # "no lldp tlv-select system-description disable"
324 # ]
325 #
326 # "after": {}
327 #
328 #
329 # -----------
330 # After state
331 # -----------
332 #
333 # RP/0/0/CPU0:an-iosxr#sh run lldp
334 # Tue Aug 6 21:38:31.187 UTC
335 # lldp
336 # !
337 #
338 # Using parsed:
339
340 # parsed.cfg
341 # lldp
342 # timer 3000
343 # reinit 2
344 # subinterfaces enable
345 # holdtime 100
346 # tlv-select
347 # management-address disable
348 # system-description disable
349 # !
350 # !
351
352 - name: Convert lldp global config to argspec without connecting to the appliance
353 cisco.iosxr.iosxr_lldp_global:
354 running_config: "{{ lookup('file', './parsed.cfg') }}"
355 state: parsed
356
357 # ------------------------
358 # Module Execution Result
359 # ------------------------
360 # parsed:
361 # holdtime: 100
362 # reinit: 2
363 # timer: 3000
364 # subinterfaces: True
365 # tlv_select:
366 # management_address: False
367 # system_description: False
368
369 # using gathered:
370
371 # Device config:
372 # lldp
373 # timer 3000
374 # reinit 2
375 # subinterfaces enable
376 # holdtime 100
377 # tlv-select
378 # management-address disable
379 # system-description disable
380 # !
381 # !
382
383 - name: Gather IOSXR lldp global configuration
384 cisco.iosxr.iosxr_lldp_global:
385 config:
386 state: gathered
387
388
389 # ------------------------
390 # Module Execution Result
391 # ------------------------
392 # gathered:
393 # holdtime: 100
394 # reinit: 2
395 # timer: 3000
396 # subinterfaces: True
397 # tlv_select:
398 # management_address: False
399 # system_description: False
400
401 # using rendered:
402
403 - name: Render platform specific commands from task input using rendered state
404 cisco.iosxr.iosxr_lldp_global:
405 config:
406 holdtime: 100
407 reinit: 2
408 timer: 3000
409 subinterfaces: true
410 tlv_select:
411 management_address: false
412 system_description: false
413 state: rendered
414
415 #
416 #
417 # ------------------------
418 # Module Execution Result
419 # ------------------------
420 #
421 # "rendered": [
422 # "lldp subinterfaces enable",
423 # "lldp holdtime 100",
424 # "lldp reinit 2",
425 # "lldp tlv-select system-description disable",
426 # "lldp tlv-select management-address disable",
427 # "lldp timer 3000"
428 # ]
429 """
430 RETURN = """
431 before:
432 description: The configuration as structured data prior to module invocation.
433 returned: always
434 type: dict
435 sample: >
436 The configuration returned will always be in the same format
437 of the parameters above.
438 after:
439 description: The configuration as structured data after module completion.
440 returned: when changed
441 type: dict
442 sample: >
443 The configuration returned will always be in the same format
444 of the parameters above.
445 commands:
446 description: The set of commands pushed to the remote device.
447 returned: always
448 type: list
449 sample: ['lldp subinterfaces enable', 'lldp holdtime 100', 'no lldp tlv-select management-address disable']
450 """
451
452
453 from ansible.module_utils.basic import AnsibleModule
454
455 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.lldp_global.lldp_global import (
456 Lldp_globalArgs,
457 )
458 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.lldp_global.lldp_global import (
459 Lldp_global,
460 )
461
462
463 def main():
464 """
465 Main entry point for module execution
466
467 :returns: the result form module invocation
468 """
469 required_if = [
470 ("state", "merged", ("config",)),
471 ("state", "replaced", ("config",)),
472 ("state", "rendered", ("config",)),
473 ("state", "parsed", ("running_config",)),
474 ]
475 mutually_exclusive = [("config", "running_config")]
476 module = AnsibleModule(
477 argument_spec=Lldp_globalArgs.argument_spec,
478 required_if=required_if,
479 supports_check_mode=True,
480 mutually_exclusive=mutually_exclusive,
481 )
482
483 result = Lldp_global(module).execute_module()
484 module.exit_json(**result)
485
486
487 if __name__ == "__main__":
488 main()