Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_br_l2pt.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_br_l2pt
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_br_l2pt
17 version_added: '3.1.0'
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage L2PT configurations on SONiC
22 description:
23 - This module provides configuration management of L2PT parameters
24 in devices running SONiC.
25 author: "Allen Ting (@allenkting)"
26 options:
27 config:
28 description: A list of L2PT configurations.
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description: Interface name for L2PT configuration.
34 type: str
35 required: true
36 bridge_l2pt_params:
37 description: VLAN ID list per supported Layer 2 protocol.
38 type: list
39 elements: dict
40 suboptions:
41 protocol:
42 description: L2 protocol.
43 type: str
44 required: true
45 choices: ['LLDP', 'LACP', 'STP', 'CDP']
46 vlan_ids:
47 description:
48 - List of VLAN IDs on which the L2 Protocol packets are to be tunneled.
49 - Ranges can be specified in the list of VLAN IDs using the delimiter '-'.
50 type: list
51 elements: str
52 state:
53 description:
54 - The state of the configuration after module completion.
55 type: str
56 choices:
57 - merged
58 - deleted
59 - replaced
60 - overridden
61 default: merged
62 """
63 EXAMPLES = """
64 # Using "merged" state
65 #
66 # Before state:
67 # -------------
68 # sonic# show running-configuration interface Ethernet 0
69 # !
70 # interface Ethernet0
71 # mtu 9100
72 # speed 400000
73 # fec RS
74 # unreliable-los auto
75 # no shutdown
76 # switchport l2proto-tunnel lldp Vlan 10
77
78 - name: Modify interface L2PT configurations
79 dellemc.enterprise_sonic.sonic_br_l2pt:
80 config:
81 - name: Ethernet0
82 bridge_l2pt_params:
83 - protocol: 'LACP'
84 vlan_ids:
85 - 10-12
86 - protocol: 'CDP'
87 vlan_ids:
88 - 20
89 - 40-60
90 - protocol: 'STP'
91 vlan_ids:
92 - 25-26
93 state: merged
94
95 # After state:
96 # ------------
97 # sonic# show running-configuration interface Ethernet0
98 # !
99 # interface Ethernet0
100 # mtu 9100
101 # speed 400000
102 # fec RS
103 # unreliable-los auto
104 # no shutdown
105 # switchport l2proto-tunnel cdp Vlan 20,40-60
106 # switchport l2proto-tunnel lacp Vlan 10-12
107 # switchport l2proto-tunnel lldp Vlan 10
108 # switchport l2proto-tunnel stp Vlan 25-26
109
110
111 # Using "merged" state
112 #
113 # Before state:
114 # -------------
115 # sonic# show running-configuration interface Ethernet 0
116 # !
117 # interface Ethernet0
118 # mtu 9100
119 # speed 400000
120 # fec RS
121 # unreliable-los auto
122 # no shutdown
123 # switchport l2proto-tunnel cdp Vlan 20, 40-50
124 # switchport l2proto-tunnel lacp Vlan 10-11
125 # switchport l2proto-tunnel lldp Vlan 10
126 # switchport l2proto-tunnel stp Vlan 25-26
127
128 - name: Modify interface L2PT configurations
129 dellemc.enterprise_sonic.sonic_br_l2pt:
130 config:
131 - name: Ethernet0
132 bridge_l2pt_params:
133 - protocol: 'LLDP'
134 vlan_ids:
135 - 12
136 - protocol: 'LACP'
137 vlan_ids:
138 - 12
139 - protocol: 'CDP'
140 vlan_ids:
141 - 20
142 - 45-60
143 - protocol: 'STP'
144 vlan_ids:
145 - 20-21
146 state: merged
147
148 # After state:
149 # ------------
150 # sonic# show running-configuration interface Ethernet0
151 # !
152 # interface Ethernet0
153 # mtu 9100
154 # speed 400000
155 # fec RS
156 # unreliable-los auto
157 # no shutdown
158 # switchport l2proto-tunnel cdp Vlan 20,40-60
159 # switchport l2proto-tunnel lacp Vlan 10-12
160 # switchport l2proto-tunnel lldp Vlan 10,12
161 # switchport l2proto-tunnel stp Vlan 20-21,25-26
162
163
164 # Using "deleted" state
165 #
166 # Before state:
167 # -------------
168 # sonic# show running-configuration interface Ethernet 0
169 # !
170 # interface Ethernet0
171 # mtu 9100
172 # speed 400000
173 # fec RS
174 # unreliable-los auto
175 # no shutdown
176 # switchport l2proto-tunnel lacp Vlan 10-12
177 # switchport l2proto-tunnel cdp Vlan 20,40-60
178 # switchport l2proto-tunnel stp Vlan 25-26
179
180 - name: Delete interface L2PT configurations
181 dellemc.enterprise_sonic.sonic_br_l2pt:
182 config:
183 - name: Ethernet0
184 bridge_l2pt_params:
185 - protocol: 'LACP'
186 vlan_ids:
187 - 10-12
188 state: deleted
189
190 # After state:
191 # ------------
192 # sonic# show running-configuration interface Ethernet0
193 # !
194 # interface Ethernet0
195 # mtu 9100
196 # speed 400000
197 # fec RS
198 # unreliable-los auto
199 # no shutdown
200 # switchport l2proto-tunnel cdp Vlan 20,40-60
201 # switchport l2proto-tunnel stp Vlan 25-26
202
203
204 # Using "deleted" state
205 #
206 # Before state:
207 # -------------
208 # sonic# show running-configuration interface Ethernet 0
209 # !
210 # interface Ethernet0
211 # mtu 9100
212 # speed 400000
213 # fec RS
214 # unreliable-los auto
215 # no shutdown
216 # switchport l2proto-tunnel lacp Vlan 10-12
217 # switchport l2proto-tunnel cdp Vlan 20,40-60
218 # switchport l2proto-tunnel stp Vlan 25-26
219 # sonic# show running-configuration interface Ethernet 8
220 # !
221 # interface Ethernet8
222 # mtu 9100
223 # speed 400000
224 # fec RS
225 # unreliable-los auto
226 # no shutdown
227 # switchport l2proto-tunnel lldp Vlan 100
228 # switchport l2proto-tunnel stp Vlan 100-150
229
230 - name: Delete all interface L2PT configurations
231 dellemc.enterprise_sonic.sonic_br_l2pt:
232 config:
233 state: deleted
234
235 # After state:
236 # ------------
237 # sonic# show running-configuration interface Ethernet0
238 # !
239 # interface Ethernet0
240 # mtu 9100
241 # speed 400000
242 # fec RS
243 # unreliable-los auto
244 # no shutdown
245 # sonic# show running-configuration interface Ethernet 8
246 # !
247 # interface Ethernet8
248 # mtu 9100
249 # speed 400000
250 # fec RS
251 # unreliable-los auto
252 # no shutdown
253
254
255 # Using "deleted" state
256 #
257 # Before state:
258 # -------------
259 # sonic# show running-configuration interface Ethernet 0
260 # !
261 # interface Ethernet0
262 # mtu 9100
263 # speed 400000
264 # fec RS
265 # unreliable-los auto
266 # no shutdown
267 # switchport l2proto-tunnel lacp Vlan 10-12
268 # switchport l2proto-tunnel cdp Vlan 20,40-60
269 # switchport l2proto-tunnel stp Vlan 25-26
270
271 - name: Delete L2PT configurations for protocol
272 dellemc.enterprise_sonic.sonic_br_l2pt:
273 config:
274 - name: Ethernet0
275 bridge_l2pt_params:
276 - protocol: 'LACP'
277 - protocol: 'CDP'
278 vlan_ids: []
279 state: deleted
280
281 # After state:
282 # ------------
283 # sonic# show running-configuration interface Ethernet0
284 # !
285 # interface Ethernet0
286 # mtu 9100
287 # speed 400000
288 # fec RS
289 # unreliable-los auto
290 # no shutdown
291 # switchport l2proto-tunnel stp Vlan 25-26
292
293
294 # Using "deleted" state
295 #
296 # Before state:
297 # -------------
298 # sonic# show running-configuration interface Ethernet 0
299 # !
300 # interface Ethernet0
301 # mtu 9100
302 # speed 400000
303 # fec RS
304 # unreliable-los auto
305 # no shutdown
306 # switchport l2proto-tunnel lacp Vlan 10-12
307 # switchport l2proto-tunnel cdp Vlan 20,40-60
308 # switchport l2proto-tunnel stp Vlan 25-26
309
310 - name: Delete interface L2PT configurations
311 dellemc.enterprise_sonic.sonic_br_l2pt:
312 config:
313 - name: Ethernet0
314 bridge_l2pt_params:
315 - protocol: 'LACP'
316 vlan_ids:
317 - 11
318 - protocol: 'CDP'
319 vlan_ids:
320 - 40-50
321 state: deleted
322
323 # After state:
324 # ------------
325 # sonic# show running-configuration interface Ethernet0
326 # !
327 # interface Ethernet0
328 # mtu 9100
329 # speed 400000
330 # fec RS
331 # unreliable-los auto
332 # no shutdown
333 # switchport l2proto-tunnel lacp Vlan 10,12
334 # switchport l2proto-tunnel cdp Vlan 20,51-60
335 # switchport l2proto-tunnel stp Vlan 25-26
336
337
338 # Using "deleted" state
339 #
340 # Before state:
341 # -------------
342 # sonic# show running-configuration interface Ethernet 0
343 # !
344 # interface Ethernet0
345 # mtu 9100
346 # speed 400000
347 # fec RS
348 # unreliable-los auto
349 # no shutdown
350 # switchport l2proto-tunnel lacp Vlan 10-12
351 # switchport l2proto-tunnel cdp Vlan 20,40-60
352 # switchport l2proto-tunnel stp Vlan 25-26
353 # sonic# show running-configuration interface Ethernet 8
354 # !
355 # interface Ethernet8
356 # mtu 9100
357 # speed 400000
358 # fec RS
359 # unreliable-los auto
360 # no shutdown
361 # switchport l2proto-tunnel lacp Vlan 10-12
362 # switchport l2proto-tunnel cdp Vlan 20,40-60
363 # switchport l2proto-tunnel stp Vlan 25-26
364
365 - name: Delete L2PT configurations for entire interface
366 dellemc.enterprise_sonic.sonic_br_l2pt:
367 config:
368 - name: Ethernet0
369 bridge_l2pt_params: []
370 - name: Ethernet8
371 state: deleted
372
373 # After state:
374 # ------------
375 # sonic# show running-configuration interface Ethernet 0
376 # !
377 # interface Ethernet0
378 # mtu 9100
379 # speed 400000
380 # fec RS
381 # unreliable-los auto
382 # no shutdown
383 # sonic# show running-configuration interface Ethernet 8
384 # !
385 # interface Ethernet8
386 # mtu 9100
387 # speed 400000
388 # fec RS
389 # unreliable-los auto
390 # no shutdown
391
392
393 # Using "replaced" state
394 #
395 # Before state:
396 # -------------
397 # sonic# show running-configuration interface Ethernet 0
398 # !
399 # interface Ethernet0
400 # mtu 9100
401 # speed 400000
402 # fec RS
403 # unreliable-los auto
404 # no shutdown
405 # switchport l2proto-tunnel lacp Vlan 10-12
406 # switchport l2proto-tunnel cdp Vlan 20,40-60
407 # switchport l2proto-tunnel stp Vlan 25-26
408 # sonic# show running-configuration interface Ethernet 8
409 # !
410 # interface Ethernet8
411 # mtu 9100
412 # speed 400000
413 # fec RS
414 # unreliable-los auto
415 # no shutdown
416 # switchport l2proto-tunnel lldp Vlan 100
417 # switchport l2proto-tunnel stp Vlan 100-150
418
419 - name: Replace interface L2PT configurations
420 dellemc.enterprise_sonic.sonic_br_l2pt:
421 config:
422 - name: Ethernet0
423 bridge_l2pt_params:
424 - protocol: 'LLDP'
425 vlan_ids:
426 - 10-12
427 - protocol: 'LACP'
428 vlan_ids:
429 - 8
430 - 12-14
431 - protocol: 'CDP'
432 vlan_ids:
433 - 20-45
434 state: replaced
435
436 # After state:
437 # ------------
438 # sonic# show running-configuration interface Ethernet 0
439 # !
440 # interface Ethernet0
441 # mtu 9100
442 # speed 400000
443 # fec RS
444 # unreliable-los auto
445 # no shutdown
446 # switchport l2proto-tunnel lldp Vlan 10-12
447 # switchport l2proto-tunnel lacp Vlan 8,12-14
448 # switchport l2proto-tunnel cdp Vlan 20-45
449 # sonic# show running-configuration interface Ethernet 8
450 # !
451 # interface Ethernet8
452 # mtu 9100
453 # speed 400000
454 # fec RS
455 # unreliable-los auto
456 # no shutdown
457 # switchport l2proto-tunnel lldp Vlan 100
458 # switchport l2proto-tunnel stp Vlan 100-150
459
460
461 # Using "overridden" state
462 #
463 # Before state:
464 # -------------
465 # sonic# show running-configuration interface Ethernet 0
466 # !
467 # interface Ethernet0
468 # mtu 9100
469 # speed 400000
470 # fec RS
471 # unreliable-los auto
472 # no shutdown
473 # switchport l2proto-tunnel lldp Vlan 10
474 # switchport l2proto-tunnel lacp Vlan 15-50
475 # switchport l2proto-tunnel cdp 20
476 # switchport l2proto-tunnel stp 25-26
477 # sonic# show running-configuration interface Ethernet 8
478 # !
479 # interface Ethernet8
480 # mtu 9100
481 # speed 400000
482 # fec RS
483 # unreliable-los auto
484 # no shutdown
485 # switchport l2proto-tunnel lldp Vlan 100
486 # switchport l2proto-tunnel stp Vlan 100-150
487
488 - name: Override interface L2PT configurations
489 dellemc.enterprise_sonic.sonic_br_l2pt:
490 config:
491 - name: Ethernet0
492 bridge_l2pt_params:
493 - protocol: 'LACP'
494 vlan_ids:
495 - 10-12
496 - protocol: 'CDP'
497 vlan_ids:
498 - 20
499 - 40-60
500 - protocol: 'STP'
501 vlan_ids:
502 - 25-26
503 state: overridden
504
505 # After state:
506 # ------------
507 # sonic# show running-configuration interface Ethernet0
508 # !
509 # interface Ethernet0
510 # mtu 9100
511 # speed 400000
512 # fec RS
513 # unreliable-los auto
514 # no shutdown
515 # switchport l2proto-tunnel cdp Vlan 20,40-60
516 # switchport l2proto-tunnel lacp Vlan 10-12
517 # switchport l2proto-tunnel stp Vlan 25-26
518 """
519 RETURN = """
520 before:
521 description: The configuration prior to the module invocation.
522 returned: always
523 type: list
524 after:
525 description: The configuration resulting from module invocation.
526 returned: when changed
527 type: list
528 after_generated:
529 description: The configuration that would result from non-check-mode module invocation.
530 returned: when C(check_mode)
531 type: list
532 commands:
533 description: The set of commands pushed to the remote device. In C(check_mode) the needed commands are displayed, but not pushed to the device.
534 returned: always
535 type: list
536 sample: ['command 1', 'command 2', 'command 3']
537 """
538
539 from ansible.module_utils.basic import AnsibleModule
540 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.br_l2pt.br_l2pt import Br_l2ptArgs
541 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.br_l2pt.br_l2pt import Br_l2pt
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=Br_l2ptArgs.argument_spec,
551 supports_check_mode=True)
552
553 result = Br_l2pt(module).execute_module()
554 module.exit_json(**result)
555
556
557 if __name__ == '__main__':
558 main()