Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_lldp_interfaces.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
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 sonic_lldp_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_lldp_interfaces
17 version_added: '2.1.0'
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage Inteface LLDP configurations on SONiC
22 description:
23 - This module provides configuration management of interface LLDP parameters
24 in devices running SONiC.
25 - It is intended for use in conjunction with global LLDP.
26 author: 'Divya Balasubramanian(@divya-balasubramania)'
27 options:
28 config:
29 description: The set of link layer discovery protocol interface attribute configurations
30 type: list
31 elements: dict
32 suboptions:
33 name:
34 description:
35 - Interface name in which LLDP needs to be configured on.
36 type: str
37 required: true
38 enable:
39 description:
40 - This argument is a boolean value to enable or disable LLDP.
41 - This command is supported only on physical interfaces and not on logical interfaces.
42 type: bool
43 mode:
44 description:
45 - By default both transmit and receive of LLDP frames is enabled.
46 - This command can be used to configure either in receive only or transmit only mode.
47 - This command is supported on physical and logical interfaces.
48 type: str
49 choices:
50 - 'receive'
51 - 'transmit'
52 network_policy:
53 description:
54 - Network policy number, range 1-128.
55 version_added: '3.1.0'
56 type: int
57 med_tlv_select:
58 description:
59 - This command can be used to select whether to advertise the LLDP-MED TLVs or not.
60 By default the LLDP-MED TLVs are advertised.
61 - This command is supported only on physical interfaces and not on logical interfaces.
62 type: dict
63 suboptions:
64 network_policy:
65 description:
66 - This command can be used to select whether to advertise network-policy
67 LLDP-MED TLVs or not. By default network-policy LLDP-MED TLVs are advertised.
68 type: bool
69 power_management:
70 description:
71 - This command can be used to select whether to advertise power-management
72 LLDP-MED TLVs or not. By default power-management LLDP-MED TLVs are advertised.
73 type: bool
74 tlv_select:
75 description:
76 - This command can be used to select whether to advertise the LLDP 802.3at or bt
77 power management TLVs or not. By default this TLV is advertised.
78 - This command is supported only on physical interfaces and not on logical interfaces.
79 type: dict
80 suboptions:
81 power_management:
82 description:
83 - This command can be used to select whether to advertise power-management
84 LLDP TLVs or not. By default power-management LLDP TLVs are advertised.
85 type: bool
86 port_vlan_id:
87 description:
88 - This command can be used to select whether to advertise port-vlan-id
89 LLDP TLVs or not. By default port-vlan-id LLDP TLVs are advertised.
90 version_added: '3.1.0'
91 type: bool
92 vlan_name:
93 description:
94 - This command can be used to select whether to advertise vlan-name
95 LLDP TLVs or not. By default vlan-name LLDP TLVs are advertised.
96 version_added: '3.1.0'
97 type: bool
98 link_aggregation:
99 description:
100 - This command can be used to select whether to advertise link-aggregation
101 LLDP TLVs or not. By default link-aggregation LLDP TLVs are advertised.
102 version_added: '3.1.0'
103 type: bool
104 max_frame_size:
105 description:
106 - This command can be used to select whether to advertise max-frame-size
107 LLDP TLVs or not. By default max-frame-size LLDP TLVs are advertised.
108 version_added: '3.1.0'
109 type: bool
110 vlan_name_tlv:
111 description:
112 - This command can be used to configure the vlan list for the Vlan name TLV advertisement.
113 - This command is supported only on physical interfaces and not on logical interfaces.
114 version_added: '3.1.0'
115 type: dict
116 suboptions:
117 max_tlv_count:
118 description:
119 - This command can be used to configure the maximum number of Vlan name TLVs
120 that can be advertised on the interface.
121 - Range is 1-128 and the default value is 10.
122 type: int
123 allowed_vlans:
124 description:
125 - This command can be used to configure the vlan list for the Vlan name TLV advertisement.
126 - Multiple Vlans or Vlan ranges can be configured.
127 - Ranges are specified by a start and end Vlan value separated by hyphen.
128 - Vlans configured should be in the range 1-4094.
129 type: list
130 elements: dict
131 suboptions:
132 vlan:
133 type: str
134 description: Configures the specified VLAN or VLAN range.
135 tlv_set:
136 description:
137 - This command can be used to configure an IPv4 or IPv6 management address
138 that will be used to advertise by LLDP on an interface
139 - This command is supported only on physical interfaces and not on logical interfaces.
140 type: dict
141 suboptions:
142 ipv4_management_address:
143 description:
144 - To configure IPv4 management address for LLDP in A.B.C.D format
145 type: str
146 ipv6_management_address:
147 description:
148 - To configure IPv6 management address for LLDP in A:B::C:D format
149 type: str
150 state:
151 description:
152 - The state specifies the type of configuration update to be performed on the device.
153 - If the state is "merged", merge specified attributes with existing configured attributes.
154 - For "deleted", delete the specified attributes from existing configuration.
155 - For "replaced", replaces lldp interface configuration of the specified interfaces with provided configuration.
156 - For "overridden", overrides all on-device lldp interface configurations with the provided configuration.
157 type: str
158 choices:
159 - merged
160 - deleted
161 - replaced
162 - overridden
163 default: merged
164 """
165
166 EXAMPLES = """
167 # Using "deleted" state
168 #
169 # Before state:
170 # -------------
171 # sonic# show running-configuration interface Ethernet 1
172 # !
173 # interface Ethernet1
174 # mtu 9100
175 # speed 25000
176 # unreliable-los auto
177 # no shutdown
178 # lldp transmit
179 # network-policy 1
180 # lldp tlv-set management-address ipv4 10.1.1.2
181 # sonic#
182
183 - name: Delete LLDP interface configurations
184 dellemc.enterprise_sonic.sonic_lldp_interfaces:
185 config:
186 - name: Ethernet1
187 mode: transmit
188 network_policy: 1
189 tlv_set:
190 ipv4_management_address: 10.1.1.2
191 state: deleted
192
193 # After state:
194 # ------------
195 # sonic# show running-configuration interface Ethernet 1
196 # !
197 # interface Ethernet1
198 # mtu 9100
199 # speed 25000
200 # unreliable-los auto
201 # no shutdown
202 # sonic#
203
204
205 # Using "deleted" state
206 #
207 # Before state:
208 # -------------
209 # sonic# show running-configuration interface
210 # !
211 # interface Ethernet0
212 # mtu 9100
213 # speed 25000
214 # unreliable-los auto
215 # no shutdown
216 # !
217 # interface Ethernet1
218 # mtu 9100
219 # speed 25000
220 # unreliable-los auto
221 # no shutdown
222 # !
223 # sonic#
224
225 - name: Delete default LLDP Interface configurations
226 dellemc.enterprise_sonic.sonic_lldp_interfaces:
227 config:
228 - name: Ethernet1
229 tlv_select:
230 power-management: true
231 port_vlan_id: true
232 vlan_name: true
233 link_aggregation: true
234 max_frame_size: true
235 med_tlv_select:
236 network_policy: true
237 state: deleted
238
239 # After State:
240 # ------------
241 # sonic# show running-configuration interface
242 # !
243 # interface Ethernet0
244 # mtu 9100
245 # speed 25000
246 # unreliable-los auto
247 # no shutdown
248 # !
249 # interface Ethernet1
250 # mtu 9100
251 # speed 25000
252 # unreliable-los auto
253 # no shutdown
254 # no lldp med-tlv-select network-policy
255 # no lldp tlv-select power-management
256 # no lldp tlv-select port-vlan-id
257 # no lldp tlv-select vlan-name
258 # no lldp tlv-select link-aggregation
259 # no lldp tlv-select max-frame-size
260 # sonic#
261
262
263 # Using "deleted" state
264 #
265 # Before state:
266 # -------------
267 # sonic# show running-configuration interface
268 # !
269 # interface Ethernet0
270 # mtu 9100
271 # speed 25000
272 # unreliable-los auto
273 # no shutdown
274 # lldp receive
275 # lldp tlv-set management-address ipv4 20.1.1.1
276 # lldp vlan-name-tlv allowed Vlan 10,15-20
277 # lldp vlan-name-tlv max-tlv-count 15
278 # !
279 # interface Ethernet1
280 # mtu 9100
281 # speed 25000
282 # unreliable-los auto
283 # no shutdown
284 # lldp transmit
285 # lldp tlv-set management-address ipv4 21.1.1.1
286 # lldp vlan-name-tlv allowed Vlan 10,15-20
287 # lldp vlan-name-tlv max-tlv-count 15
288 # !
289 # sonic#
290
291 - name: Delete default LLDP Interface configurations
292 dellemc.enterprise_sonic.sonic_lldp_interfaces:
293 config:
294 - name: Ethernet0
295 vlan_name_tlv:
296 allowed_vlans:
297 - vlan: 10
298 - vlan: 15-20
299 max_tlv_count: 15
300 - name: Ethernet1
301 state: deleted
302
303 # After state:
304 # ------------
305 # sonic# show running-configuration interface
306 # !
307 # interface Ethernet0
308 # mtu 9100
309 # speed 25000
310 # unreliable-los auto
311 # no shutdown
312 # lldp receive
313 # lldp tlv-set management-address ipv4 20.1.1.1
314 # !
315 # interface Ethernet1
316 # mtu 9100
317 # speed 25000
318 # unreliable-los auto
319 # no shutdown
320 # sonic#
321
322
323 # Using "merged" state
324 #
325 # Before state:
326 # -------------
327 # sonic# show running-configuration interface
328 # !
329 # interface Ethernet0
330 # mtu 9100
331 # speed 25000
332 # unreliable-los auto
333 # no shutdown
334 # !
335 # interface Ethernet1
336 # mtu 9100
337 # speed 25000
338 # unreliable-los auto
339 # no shutdown
340 # no lldp enable
341 # !
342 # sonic#
343
344 - name: Modify LLDP Interface configurations
345 dellemc.enterprise_sonic.sonic_lldp_interfaces:
346 config:
347 - name: Ethernet1
348 enable: true
349 mode: transmit
350 network_policy: 2
351 med_tlv_select:
352 power_management: true
353 tlv_set:
354 ipv4_management_address: 10.1.1.2
355 vlan_name_tlv:
356 allowed_vlans:
357 - vlan: 10
358 - vlan: 15-20
359 max_tlv_count: 15
360 state: merged
361
362 # After State:
363 # ------------
364 # sonic# show running-configuration interface
365 # !
366 # interface Ethernet0
367 # mtu 9100
368 # speed 25000
369 # unreliable-los auto
370 # no shutdown
371 # !
372 # interface Ethernet1
373 # mtu 9100
374 # speed 25000
375 # unreliable-los auto
376 # no shutdown
377 # lldp transmit
378 # network-policy 2
379 # lldp tlv-set management-address ipv4 10.1.1.2
380 # lldp vlan-name-tlv allowed Vlan 10,15-20
381 # lldp vlan-name-tlv max-tlv-count 15
382 # sonic#
383
384 # Using "replaced" state
385 #
386 # Before state:
387 # -------------
388 #
389 # sonic# show running-configuration interface
390 # !
391 # interface Eth1/5
392 # mtu 9100
393 # speed 10000
394 # unreliable-los auto
395 # no shutdown
396 # lldp tlv-set management-address ipv6 10::1
397 # no lldp med-tlv-select network-policy
398 # no lldp med-tlv-select power-management
399 # lldp vlan-name-tlv allowed Vlan 10,15-20
400 # lldp vlan-name-tlv max-tlv-count 15
401 #
402 # !
403 # interface Eth1/6
404 # mtu 9100
405 # speed 10000
406 # unreliable-los auto
407 # no shutdown
408 # no lldp med-tlv-select power-management
409 # no lldp tlv-select power-management
410
411 - name: Replace LLDP interface configurations
412 dellemc.enterprise_sonic.sonic_lldp_interfaces:
413 config:
414 - name: Eth1/5
415 mode: receive
416 tlv_set:
417 ipv6_management_address: '30::1'
418 med_tlv_select:
419 network_policy: false
420 vlan_name_tlv:
421 allowed_vlans:
422 - vlan: 20-30
423 max_tlv_count: 20
424 state: replaced
425
426 # After State:
427
428 # ------------
429 #
430 # sonic# show running-configuration interface
431 # !
432 # interface Eth1/5
433 # mtu 9100
434 # speed 10000
435 # unreliable-los auto
436 # no shutdown
437 # lldp receive
438 # lldp tlv-set management-address ipv6 30::1
439 # no lldp med-tlv-select network-policy
440 # lldp vlan-name-tlv allowed Vlan 20-30
441 # lldp vlan-name-tlv max-tlv-count 20
442 # !
443 # interface Eth1/6
444 # mtu 9100
445 # speed 10000
446 # unreliable-los auto
447 # no shutdown
448 # no lldp med-tlv-select power-management
449 # no lldp tlv-select power-management
450
451 # Using "overridden" state
452 #
453 # Before state:
454 # -------------
455 #
456 # sonic# show running-configuration interface
457 # interface Eth1/5
458 # mtu 9100
459 # speed 10000
460 # unreliable-los auto
461 # no shutdown
462 # lldp transmit
463 # lldp tlv-set management-address ipv6 30::2
464 # !
465 # interface Eth1/6
466 # mtu 9100
467 # speed 10000
468 # unreliable-los auto
469 # no shutdown
470 # lldp transmit
471 # lldp tlv-set management-address ipv4 40.1.1.1
472
473 - name: Override LLDP interface configurations
474 dellemc.enterprise_sonic.sonic_lldp_interfaces:
475 config:
476 - name: Eth1/5
477 mode: receive
478 tlv_set:
479 ipv4_management_address: '10.1.1.2'
480 vlan_name_tlv:
481 allowed_vlans:
482 - vlan: 10
483 - vlan: 15-20
484 max_tlv_count: 15
485 state: overridden
486
487 # After state:
488 # ------------
489 #
490 # sonic# show running-configuration interface
491 # !
492 # interface Eth1/5
493 # mtu 9100
494 # speed 10000
495 # unreliable-los auto
496 # no shutdown
497 # lldp receive
498 # lldp tlv-set management-address ipv4 10.1.1.2
499 # lldp vlan-name-tlv allowed Vlan 10,15-20
500 # lldp vlan-name-tlv max-tlv-count 15
501 # !
502 # interface Eth1/6
503 # mtu 9100
504 # speed 10000
505 # unreliable-los auto
506 # no shutdown
507 """
508
509 RETURN = """
510 before:
511 description: The configuration prior to the module invocation.
512 returned: always
513 sample: >
514 The configuration returned will always be in the same format
515 as the parameters above.
516 type: list
517 after:
518 description: The resulting configuration module invocation.
519 returned: when changed
520 sample: >
521 The configuration returned will always be in the same format
522 as the parameters above.
523 type: list
524 after_generated:
525 description: The generated configuration from module invocation.
526 returned: when C(check_mode)
527 type: list
528 sample: >
529 The configuration returned will always be in the same format
530 of the parameters above.
531 commands:
532 description: The set of commands pushed to the remote device.
533 returned: always
534 type: list
535 sample: ['command 1', 'command 2', 'command 3']
536 """
537
538
539 from ansible.module_utils.basic import AnsibleModule
540 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.lldp_interfaces.lldp_interfaces import Lldp_interfacesArgs
541 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.lldp_interfaces.lldp_interfaces import Lldp_interfaces
542
543
544 def main():
545 """
546 Main entry point for module execution
547
548 :returns: the result form module invocation
549 """
550 module = AnsibleModule(argument_spec=Lldp_interfacesArgs.argument_spec,
551 supports_check_mode=True)
552
553 result = Lldp_interfaces(module).execute_module()
554 module.exit_json(**result)
555
556
557 if __name__ == '__main__':
558 main()