Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_lag_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_lag_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_lag_interfaces
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage link aggregation group (LAG) interface parameters
22 description:
23 - This module manages attributes of link aggregation group (LAG) interfaces of
24 devices running Enterprise SONiC Distribution by Dell Technologies.
25 author: Abirami N (@abirami-n)
26
27 options:
28 config:
29 description:
30 - A list of LAG configurations.
31 - I(adv_speed) and I(speed) are mutually exclusive.
32 type: list
33 elements: dict
34 suboptions:
35 name:
36 description:
37 - ID of the LAG.
38 type: str
39 required: True
40 members:
41 description:
42 - The list of interfaces that are part of the group.
43 type: dict
44 suboptions:
45 interfaces:
46 description:
47 - The list of interfaces that are part of the group.
48 type: list
49 elements: dict
50 suboptions:
51 member:
52 description:
53 - The interface name.
54 type: str
55 mode:
56 description:
57 - Specifies mode of the port-channel while creation.
58 - Functional default is C(lacp).
59 type: str
60 choices:
61 - static
62 - lacp
63 ethernet_segment:
64 description:
65 - Specifies Ethernet segment.
66 - I(esi_type) and I(esi) can not be deleted separately.
67 - When I(state=deleted) and both I(esi) and I(df_preference) are not specifed, the entire Ethernet segment will be deleted.
68 version_added: 2.5.0
69 type: dict
70 suboptions:
71 esi_type:
72 description:
73 - Specifies type of Ethernet Segment Identifier.
74 required: True
75 type: str
76 choices:
77 - auto_lacp
78 - auto_system_mac
79 - ethernet_segment_id
80 esi:
81 description:
82 - Specifies value of Ethernet Segment Identifier.
83 - Only C(AUTO) is supported when I(esi_type=auto_lacp) or I(esi_type=auto_system_mac).
84 type: str
85 df_preference:
86 description:
87 - The preference for Designated Forwarder election method.
88 - The range of df_preference value is from 1 to 65535.
89 type: int
90 fallback:
91 description:
92 - Enable fallback mode.
93 version_added: 3.1.0
94 type: bool
95 fast_rate:
96 description:
97 - Enable LACP fast rate mode.
98 version_added: 3.1.0
99 type: bool
100 graceful_shutdown:
101 description:
102 - Enable graceful shutdown.
103 version_added: 3.1.0
104 type: bool
105 lacp_individual:
106 description:
107 - Specifies LACP individual configuration.
108 - Applicable only when I(mode=lacp).
109 version_added: 3.1.0
110 type: dict
111 suboptions:
112 enable:
113 description:
114 - Enable LACP individual.
115 type: bool
116 timeout:
117 description:
118 - Specifies LACP individual timeout in seconds.
119 - The range is from 3 to 90.
120 type: int
121 min_links:
122 description:
123 - Specifies minimum number of links.
124 - The range is from 1 to 32.
125 version_added: 3.1.0
126 type: int
127 speed:
128 description:
129 - LAG Interface speed measured in megabytes.
130 - Supported speeds are dependent on the type of switch.
131 choices:
132 - 10
133 - 100
134 - 1000
135 - 2500
136 - 5000
137 - 10000
138 - 20000
139 - 25000
140 - 40000
141 - 50000
142 - 100000
143 - 200000
144 - 400000
145 - 800000
146 version_added: 4.0.0
147 type: int
148 adv_speed:
149 description:
150 - Advertised speed of the LAG interface measured in megabytes.
151 - Supported speeds are dependent on the type of switch.
152 choices:
153 - 10
154 - 100
155 - 1000
156 - 2500
157 - 5000
158 - 10000
159 - 20000
160 - 25000
161 - 40000
162 - 50000
163 - 100000
164 - 200000
165 - 400000
166 - 800000
167 version_added: 4.0.0
168 type: int
169 system_mac:
170 description:
171 - Specifies system MAC address for the portchannel.
172 version_added: 3.1.0
173 type: str
174 state:
175 description:
176 - The state that the configuration should be left in.
177 type: str
178 choices:
179 - merged
180 - replaced
181 - overridden
182 - deleted
183 default: merged
184 """
185
186 EXAMPLES = """
187 # Using "merged" state
188 #
189 # Before state:
190 # -------------
191 #
192 # interface Eth1/10
193 # mtu 9100
194 # speed 100000
195 # no shutdown
196 # !
197 # interface PortChannel10
198 # no shutdown
199 #
200
201 - name: Merge LAG interfaces configuration
202 dellemc.enterprise_sonic.sonic_lag_interfaces:
203 config:
204 - name: PortChannel10
205 fallback: true
206 fast_rate: true
207 graceful_shutdown: true
208 members:
209 interfaces:
210 - member: Eth1/10
211 system_mac: "12:12:12:12:12:12"
212 ethernet_segment:
213 esi_type: auto_lacp
214 df_preference: 2222
215 - name: PortChannel12
216 min_links: 2
217 members:
218 interfaces:
219 - member: Eth1/15
220 - member: Eth1/16
221 - member: Eth1/17
222 lacp_individual:
223 enable: true
224 timeout: 30
225 state: merged
226
227 # After state:
228 # ------------
229 #
230 # interface Eth1/10
231 # channel-group 10
232 # mtu 9100
233 # speed 100000
234 # no shutdown
235 # !
236 # interface Eth1/15
237 # channel-group 12
238 # mtu 9100
239 # speed 100000
240 # no shutdown
241 # !
242 # interface Eth1/16
243 # channel-group 12
244 # mtu 9100
245 # speed 100000
246 # no shutdown
247 # !
248 # interface Eth1/17
249 # channel-group 12
250 # mtu 9100
251 # speed 100000
252 # no shutdown
253 # !
254 # interface PortChannel10
255 # fast_rate
256 # fallback
257 # graceful-shutdown
258 # no shutdown
259 # system-mac 12:12:12:12:12:12
260 # !
261 # evpn ethernet-segment auto-lacp
262 # df-preference 2222
263 # !
264 # !
265 # interface PortChannel12
266 # min-links 2
267 # lacp individual
268 # lacp individual timeout 30
269 # no shutdown
270 #
271
272 # Using "replaced" state
273 #
274 # Before state:
275 # -------------
276 #
277 # interface Eth1/5
278 # channel-group 10
279 # mtu 9100
280 # speed 100000
281 # no shutdown
282 # !
283 # interface Eth1/7
284 # no channel-group
285 # mtu 9100
286 # speed 100000
287 # no shutdown
288 # !
289 # interface PortChannel10
290 # graceful-shutdown
291 # no shutdown
292 # system-mac 12:12:12:12:12:12
293 # !
294 # evpn ethernet-segment auto-lacp
295 # df-preference 2222
296 #
297
298 - name: Replace LAG configurations of specified LAG interfaces
299 dellemc.enterprise_sonic.sonic_lag_interfaces:
300 config:
301 - name: PortChannel20
302 members:
303 interfaces:
304 - member: Eth1/6
305 system_mac: "14:14:14:14:14:14"
306 ethernet_segment:
307 esi_type: auto_system_mac
308 df_preference: 6666
309 - name: PortChannel10
310 members:
311 interfaces:
312 - member: Eth1/7
313 system_mac: "14:14:14:14:14:14"
314 ethernet_segment:
315 esi_type: auto_system_mac
316 df_preference: 3333
317 state: replaced
318
319 # After state:
320 # ------------
321 #
322 # interface Eth1/5
323 # mtu 9100
324 # speed 100000
325 # no shutdown
326 # !
327 # interface Eth1/6
328 # channel-group 20
329 # mtu 9100
330 # speed 100000
331 # no shutdown
332 # !
333 # interface Eth1/7
334 # channel-group 10
335 # mtu 9100
336 # speed 100000
337 # no shutdown
338 # !
339 # interface PortChannel10
340 # no shutdown
341 # system-mac 14:14:14:14:14:14
342 # !
343 # evpn ethernet-segment auto-system-mac
344 # df-preference 3333
345 # !
346 # interface PortChanne20
347 # no shutdown
348 # system-mac 14:14:14:14:14:14
349 # !
350 # evpn ethernet-segment auto-system-mac
351 # df-preference 6666
352 #
353
354 # Using "overridden" state
355 #
356 # Before state:
357 # -------------
358 #
359 # interface Eth1/5
360 # channel-group 10
361 # mtu 9100
362 # speed 100000
363 # no shutdown
364 # !
365 # interface Eth1/6
366 # no channel-group
367 # mtu 9100
368 # speed 100000
369 # no shutdown
370 # !
371 # interface PortChannel10
372 # fast_rate
373 # fallback
374 # no shutdown
375 # !
376 # evpn ethernet-segment auto-system-mac
377 # df-preference 2222
378 #
379
380 - name: Override all LAG interface configurations
381 dellemc.enterprise_sonic.sonic_lag_interfaces:
382 config:
383 - name: PortChannel20
384 min_links: 2
385 members:
386 interfaces:
387 - member: Eth1/6
388 - member: Eth1/7
389 - member: Eth1/8
390 system_mac: "12:12:12:12:12:12"
391 ethernet_segment:
392 esi_type: auto_lacp
393 df_preference: 3333
394 lacp_individual:
395 enable: true
396 timeout: 60
397 state: overridden
398
399 # After state:
400 # ------------
401 #
402 # interface Eth1/5
403 # mtu 9100
404 # speed 100000
405 # no shutdown
406 # !
407 # interface Eth1/6
408 # channel-group 20
409 # mtu 9100
410 # speed 100000
411 # no shutdown
412 # !
413 # interface Eth1/7
414 # channel-group 20
415 # mtu 9100
416 # speed 100000
417 # no shutdown
418 # !
419 # interface Eth1/8
420 # channel-group 20
421 # mtu 9100
422 # speed 100000
423 # no shutdown
424 # !
425 # interface PortChannel20
426 # min-links 2
427 # lacp individual
428 # lacp individual timeout 60
429 # no shutdown
430 # system-mac 12:12:12:12:12:12
431 # !
432 # evpn ethernet-segment auto-lacp
433 # df-preference 3333
434 #
435
436 # Using "deleted" state
437 #
438 # Before state:
439 # -------------
440 #
441 # interface Eth1/10
442 # channel-group 10
443 # mtu 9100
444 # speed 100000
445 # no shutdown
446 # !
447 # interface Eth1/15
448 # channel-group 12
449 # mtu 9100
450 # speed 100000
451 # no shutdown
452 # !
453 # interface Eth1/16
454 # channel-group 12
455 # mtu 9100
456 # speed 100000
457 # no shutdown
458 # !
459 # interface PortChannel 10
460 # no shutdown
461 # system-mac 12:12:12:12:12:12
462 # !
463 # evpn ethernet-segment auto-lacp
464 # df-preference 2222
465 # !
466 # interface PortChannel 12
467 # fast_rate
468 # fallback
469 # graceful-shutdown
470 # min-links 2
471 # no shutdown
472 #
473
474 - name: Delete all LAG interfaces
475 dellemc.enterprise_sonic.sonic_lag_interfaces:
476 config:
477 state: deleted
478
479 # After state:
480 # -------------
481 #
482 # interface Eth1/10
483 # mtu 9100
484 # speed 100000
485 # no shutdown
486 # !
487 # interface Eth1/15
488 # mtu 9100
489 # speed 100000
490 # no shutdown
491 # !
492 # interface Eth1/16
493 # mtu 9100
494 # speed 100000
495 # no shutdown
496 #
497
498 # Using "deleted" state
499 #
500 # Before state:
501 # -------------
502 # interface Eth1/10
503 # channel-group 10
504 # mtu 9100
505 # speed 100000
506 # no shutdown
507 # !
508 # interface Eth1/11
509 # channel-group 10
510 # mtu 9100
511 # speed 100000
512 # no shutdown
513 # !
514 # interface Eth1/20
515 # channel-group 20
516 # mtu 9100
517 # speed 100000
518 # no shutdown
519 # !
520 # interface PortChannel10
521 # min-links 2
522 # no shutdown
523 # system-mac 12:12:12:12:12:12
524 # !
525 # evpn ethernet-segment auto-lacp
526 # df-preference 2222
527 # !
528 # interface PortChannel20
529 # no shutdown
530 #
531
532 - name: Delete specified LAG configurations and LAG interfaces
533 dellemc.enterprise_sonic.sonic_lag_interfaces:
534 config:
535 - name: PortChannel10
536 min_links: 2
537 members:
538 interfaces:
539 - member: Eth1/10
540 system_mac: "12:12:12:12:12:12"
541 ethernet_segment:
542 esi_type: auto_lacp
543 - name: PortChannel20
544 state: deleted
545
546 # After state:
547 # -------------
548 #
549 # interface Eth1/10
550 # mtu 9100
551 # speed 100000
552 # no shutdown
553 # !
554 # interface Eth1/11
555 # channel-group 10
556 # mtu 9100
557 # speed 100000
558 # no shutdown
559 # !
560 # interface Eth1/20
561 # mtu 9100
562 # speed 100000
563 # no shutdown
564 # !
565 # interface PortChannel10
566 # no shutdown
567 #
568 """
569
570 RETURN = """
571 before:
572 description: The configuration prior to the module invocation.
573 returned: always
574 type: list
575 sample: >
576 The configuration that is returned is always in the same format
577 as the parameters above.
578 after:
579 description: The resulting configuration on module invocation.
580 returned: when changed
581 type: list
582 sample: >
583 The configuration returned is always in the same format
584 as the parameters above.
585 after_generated:
586 description: The configuration expected as a result of module invocation.
587 returned: when C(check_mode)
588 type: list
589 sample: >
590 The configuration returned will always be in the same format
591 as the parameters above.
592 commands:
593 description: The set of commands pushed to the remote device.
594 returned: always
595 type: list
596 sample: ['command 1', 'command 2', 'command 3']
597 """
598
599
600 from ansible.module_utils.basic import AnsibleModule
601 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.lag_interfaces.lag_interfaces import Lag_interfacesArgs
602 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.lag_interfaces.lag_interfaces import Lag_interfaces
603
604
605 def main():
606 """
607 Main entry point for module execution
608
609 :returns: the result form module invocation
610 """
611 module = AnsibleModule(argument_spec=Lag_interfacesArgs.argument_spec,
612 supports_check_mode=True)
613
614 result = Lag_interfaces(module).execute_module()
615 module.exit_json(**result)
616
617
618 if __name__ == '__main__':
619 main()