Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_l3_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_l3_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_l3_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: Configure the IPv4 and IPv6 parameters on Interfaces such as, Eth, LAG, VLAN, and loopback
22 description:
23 - Configures Layer 3 interface settings on devices running Enterprise SONiC
24 Distribution by Dell Technologies. This module provides configuration management
25 of IPv4 and IPv6 parameters on Ethernet interfaces of devices running Enterprise SONiC.
26 author: Kumaraguru Narayanan (@nkumaraguru)
27 options:
28 config:
29 description:
30 - A list of l3_interfaces configurations.
31 type: list
32 elements: dict
33 suboptions:
34 name:
35 required: true
36 type: str
37 description:
38 - Full name of the interface, for example, Eth1/3.
39 ipv4:
40 description:
41 - ipv4 configurations to be set for the Layer 3 interface mentioned in name option.
42 type: dict
43 suboptions:
44 addresses:
45 description:
46 - List of IPv4 addresses to be set.
47 type: list
48 elements: dict
49 suboptions:
50 address:
51 description:
52 - IPv4 address to be set in the format <ipv4 address>/<mask>
53 for example, 192.0.2.1/24.
54 type: str
55 secondary:
56 description:
57 - secondary flag of the ip address.
58 - Functional default is 'false'
59 type: bool
60 anycast_addresses:
61 description:
62 - List of IPv4 addresses to be set for anycast.
63 type: list
64 elements: str
65 proxy_arp:
66 description:
67 - Configurations parameters for ipv4 proxy ARP
68 version_added: 3.1.0
69 type: dict
70 suboptions:
71 mode:
72 description:
73 - Modes for proxy_arp
74 type: str
75 choices:
76 - DISABLE
77 - REMOTE_ONLY
78 - ALL
79 ipv6:
80 description:
81 - ipv6 configurations to be set for the Layer 3 interface mentioned in name option.
82 type: dict
83 suboptions:
84 addresses:
85 description:
86 - List of IPv6 addresses to be set.
87 type: list
88 elements: dict
89 suboptions:
90 address:
91 description:
92 - IPv6 address to be set in the address format is <ipv6 address>/<mask>
93 for example, 2001:db8:2201:1::1/64.
94 type: str
95 eui64:
96 description:
97 - Flag to indicate whether it is eui64 address
98 version_added: 2.5.0
99 type: bool
100 anycast_addresses:
101 description:
102 - List of IPv6 anycast addresses.
103 version_added: 3.1.0
104 type: list
105 elements: str
106 enabled:
107 description:
108 - enabled flag of the ipv6.
109 type: bool
110 autoconf:
111 description:
112 - autoconfiguration flag
113 version_added: 2.5.0
114 type: bool
115 dad:
116 description:
117 - IPv6 nd dad related configs.
118 version_added: 2.5.0
119 type: str
120 choices:
121 - ENABLE
122 - DISABLE
123 - DISABLE_IPV6_ON_FAILURE
124 nd_proxy:
125 description:
126 - Configurations parameters for ipv6 ND-proxy
127 version_added: 3.1.0
128 type: dict
129 suboptions:
130 mode:
131 description:
132 - Modes for nd_proxy
133 type: str
134 choices:
135 - DISABLE
136 - REMOTE_ONLY
137 - ALL
138 nd_proxy_rules:
139 description:
140 - List of ipv6 prefixes (subnets) for which this interface is
141 to serve as an nd proxy
142 type: list
143 elements: str
144 state:
145 description:
146 - The state of the configuration after module completion.
147 type: str
148 choices:
149 - merged
150 - deleted
151 - replaced
152 - overridden
153 default: merged
154 """
155
156 EXAMPLES = """
157 # Using "deleted" state
158 #
159 # Before state:
160 # -------------
161 #
162 # sonic# show running-configuration interface
163 # !
164 # interface Ethernet20
165 # mtu 9100
166 # speed 100000
167 # shutdown
168 # ip address 83.1.1.1/16
169 # ip address 84.1.1.1/16 secondary
170 # ipv6 address 83::1/16
171 # ipv6 address 84::1/16
172 # ipv6 address 85::/64 eui-64
173 # ipv6 enable
174 # ipv6 address autoconfig
175 # ipv6 nd dad enable
176 # ip proxy-arp enable remote-only
177 # ipv6 nd-proxy enable all
178 # !
179 # interface Ethernet24
180 # mtu 9100
181 # speed 100000
182 # shutdown
183 # ip address 91.1.1.1/16
184 # ip address 92.1.1.1/16 secondary
185 # ipv6 address 90::1/16
186 # ipv6 address 91::1/16
187 # ipv6 address 92::1/16
188 # ipv6 address 93::1/16
189 # !
190 # interface Vlan501
191 # ip anycast-address 11.12.13.14/12
192 # ip anycast-address 1.2.3.4/22
193 # ipv6 anycast-address 101::101/64
194 # ipv6 anycast-address 102::102/64
195 # !
196
197 - name: delete l3 interface attributes
198 dellemc.enterprise_sonic.sonic_l3_interfaces:
199 config:
200 - name: Ethernet20
201 ipv4:
202 proxy_arp:
203 mode: REMOTE_ONLY
204 addresses:
205 - address: 83.1.1.1/16
206 - address: 84.1.1.1/16
207 ipv6:
208 addresses:
209 - address: 85::/64
210 - name: Ethernet24
211 ipv6:
212 enabled: true
213 addresses:
214 - address: 91::1/16
215 - name: Vlan501
216 ipv4:
217 anycast_addresses:
218 - 11.12.13.14/12
219 ipv6:
220 anycast_addresses:
221 - 101::101/64
222 state: deleted
223
224 #
225 # After state:
226 # ------------
227 #
228 # sonic# show running-configuration interface
229 # !
230 # interface Ethernet20
231 # mtu 9100
232 # speed 100000
233 # shutdown
234 # ipv6 address 83::1/16
235 # ipv6 address 84::1/16
236 # ipv6 enable
237 # ipv6 address autoconfig
238 # ipv6 nd dad enable
239 # ipv6 nd-proxy enable all
240 # !
241 # interface Ethernet24
242 # mtu 9100
243 # speed 100000
244 # shutdown
245 # ip address 91.1.1.1/16
246 # ip address 92.1.1.1/16 secondary
247 # ipv6 address 90::1/16
248 # ipv6 address 92::1/16
249 # ipv6 address 93::1/16
250 # !
251 # interface Vlan501
252 # ip anycast-address 1.2.3.4/22
253 # ipv6 anycast-address 102::102/64
254 # !
255
256 # Using "deleted" state
257 #
258 # Before state:
259 # -------------
260 #
261 # sonic# show running-configuration interface
262 # !
263 # interface Ethernet20
264 # mtu 9100
265 # speed 100000
266 # shutdown
267 # ip address 83.1.1.1/16
268 # ip address 84.1.1.1/16 secondary
269 # ipv6 address 83::1/16
270 # ipv6 address 84::1/16
271 # ipv6 address 85::/64 eui-64
272 # ipv6 enable
273 # ipv6 address autoconfig
274 # ipv6 nd dad enable
275 # ip proxy-arp enable remote-only
276 # ipv6 nd-proxy enable all
277 # ipv6 nd-proxy rule prefix 5001::/24
278 # !
279 # interface Ethernet24
280 # mtu 9100
281 # speed 100000
282 # shutdown
283 # ip address 91.1.1.1/16
284 # ipv6 address 90::1/16
285 # ipv6 address 91::1/16
286 # ipv6 address 92::1/16
287 # ipv6 address 93::1/16
288 # ip proxy-arp enable all
289 # ipv6 nd-proxy enable remote-only
290 # ipv6 nd-proxy rule prefix 6001::/24
291 # !
292 # interface Vlan501
293 # ip anycast-address 11.12.13.14/12
294 # ip anycast-address 1.2.3.4/22
295 # ipv6 anycast-address 101::101/64
296 # ipv6 anycast-address 102::102/64
297 # !
298
299 - name: delete all l3 interface
300 dellemc.enterprise_sonic.sonic_l3_interfaces:
301 config:
302 state: deleted
303
304 #
305 # After state:
306 # ------------
307 #
308 # sonic# show running-configuration interface
309 # !
310 # interface Ethernet20
311 # mtu 9100
312 # speed 100000
313 # shutdown
314 # !
315 # interface Ethernet24
316 # mtu 9100
317 # speed 100000
318 # shutdown
319 # !
320 # interface Vlan501
321 # !
322
323 # Using "merged" state
324 #
325 # Before state:
326 # -------------
327 #
328 # sonic# show running-configuration interface
329 # !
330 # interface Ethernet20
331 # mtu 9100
332 # speed 100000
333 # shutdown
334 # !
335 # interface Ethernet24
336 # mtu 9100
337 # speed 100000
338 # shutdown
339 # !
340 # interface Vlan501
341 # ip anycast-address 1.2.3.4/22
342 # ipv6 anycast-address 101::101/64
343 # !
344
345 - name: Add l3 interface configurations
346 dellemc.enterprise_sonic.sonic_l3_interfaces:
347 config:
348 - name: Ethernet20
349 ipv4:
350 addresses:
351 - address: 83.1.1.1/16
352 - address: 84.1.1.1/16
353 secondary: true
354 proxy_arp:
355 mode: REMOTE_ONLY
356 ipv6:
357 enabled: true
358 dad: ENABLE
359 autoconf: true
360 addresses:
361 - address: 83::1/16
362 - address: 84::1/16
363 - address: 85::/64
364 eui64: true
365 - name: Ethernet24
366 ipv4:
367 addresses:
368 - address: 91.1.1.1/16
369 ipv6:
370 addresses:
371 - address: 90::1/16
372 - address: 91::1/16
373 - address: 92::1/16
374 - address: 93::1/16
375 nd_proxy:
376 mode: REMOTE_ONLY
377 nd_proxy_rules:
378 - 6001::/24
379 - name: Vlan501
380 ipv4:
381 anycast_addresses:
382 - 11.12.13.14/12
383 ipv6:
384 anycast_addresses:
385 - 102::102/64
386 state: merged
387
388 # After state:
389 # ------------
390 #
391 # sonic# show running-configuration interface
392 # !
393 # interface Ethernet20
394 # mtu 9100
395 # speed 100000
396 # shutdown
397 # ip address 83.1.1.1/16
398 # ip address 84.1.1.1/16 secondary
399 # ip proxy-arp enable remote-only
400 # ipv6 address 83::1/16
401 # ipv6 address 84::1/16
402 # ipv6 address 85::/64 eui-64
403 # ipv6 enable
404 # ipv6 address autoconfig
405 # ipv6 nd dad enable
406 # !
407 # interface Ethernet24
408 # mtu 9100
409 # speed 100000
410 # shutdown
411 # ip address 91.1.1.1/16
412 # ipv6 address 90::1/16
413 # ipv6 address 91::1/16
414 # ipv6 address 92::1/16
415 # ipv6 address 93::1/16
416 # ipv6 nd-proxy enable remote-only
417 # ipv6 nd-proxy rule prefix 6001::/24
418 # !
419 # interface Vlan501
420 # ip anycast-address 1.2.3.4/22
421 # ip anycast-address 11.12.13.14/12
422 # ipv6 anycast-address 101::101/64
423 # ipv6 anycast-address 102::102/64
424 # !
425
426 # Using "replaced" state
427 #
428 # Before state:
429 # -------------
430 #
431 # sonic# show running-configuration interface
432 # !
433 # interface Ethernet20
434 # mtu 9100
435 # speed 100000
436 # shutdown
437 # ip address 83.1.1.1/16
438 # ip address 84.1.1.1/16 secondary
439 # ipv6 address 83::1/16
440 # ipv6 address 84::1/16
441 # ipv6 enable
442 # !
443 # interface Ethernet24
444 # mtu 9100
445 # speed 100000
446 # shutdown
447 # ip address 91.1.1.1/16
448 # ipv6 address 90::1/16
449 # ipv6 address 91::1/16
450 # ipv6 address 92::1/16
451 # ipv6 address 93::1/16
452 # !
453
454 - name: Replace l3 interface
455 dellemc.enterprise_sonic.sonic_l3_interfaces:
456 config:
457 - name: Ethernet20
458 ipv4:
459 - address: 81.1.1.1/16
460 proxy_arp:
461 mode: ALL
462 state: replaced
463
464 # After state:
465 # ------------
466 #
467 # sonic# show running-configuration interface
468 # !
469 # interface Ethernet20
470 # mtu 9100
471 # speed 100000
472 # shutdown
473 # ip address 81.1.1.1/16
474 # ip proxy-arp enable all
475 # !
476 # interface Ethernet24
477 # mtu 9100
478 # speed 100000
479 # shutdown
480 # ip address 91.1.1.1/16
481 # ipv6 address 90::1/16
482 # ipv6 address 91::1/16
483 # ipv6 address 92::1/16
484 # ipv6 address 93::1/16
485 # !
486
487 # Using "replaced" state
488 #
489 # Before state:
490 # -------------
491 #
492 # sonic# show running-configuration interface
493 # !
494 # interface Ethernet20
495 # mtu 9100
496 # speed 100000
497 # shutdown
498 # ip address 83.1.1.1/16
499 # ip address 84.1.1.1/16 secondary
500 # ip proxy-arp enable all
501 # ipv6 address 83::1/16
502 # ipv6 address 84::1/16
503 # ipv6 enable
504 # ipv6 nd-proxy enable remote-only
505 # ipv6 nd-proxy rule prefix 6001::/24
506 # !
507 # interface Ethernet24
508 # mtu 9100
509 # speed 100000
510 # shutdown
511 # ip address 91.1.1.1/16
512 # ipv6 address 90::1/16
513 # ipv6 address 91::1/16
514 # ipv6 address 92::1/16
515 # ipv6 address 93::1/16
516 # !
517
518 - name: Replace l3 interface
519 dellemc.enterprise_sonic.sonic_l3_interfaces:
520 config:
521 - name: Ethernet20
522 state: replaced
523
524 # After state:
525 # ------------
526 #
527 # sonic# show running-configuration interface
528 # !
529 # interface Ethernet20
530 # mtu 9100
531 # speed 100000
532 # shutdown
533 # !
534 # interface Ethernet24
535 # mtu 9100
536 # speed 100000
537 # shutdown
538 # ip address 91.1.1.1/16
539 # ipv6 address 90::1/16
540 # ipv6 address 91::1/16
541 # ipv6 address 92::1/16
542 # ipv6 address 93::1/16
543 # !
544
545 # Using "overridden" state
546 #
547 # Before state:
548 # -------------
549 #
550 # sonic# show running-configuration interface
551 # !
552 # interface Ethernet20
553 # mtu 9100
554 # speed 100000
555 # shutdown
556 # ip address 83.1.1.1/16
557 # ip address 84.1.1.1/16 secondary
558 # ipv6 address 83::1/16
559 # ipv6 address 84::1/16
560 # ipv6 address 85::/64 eui-64
561 # ipv6 enable
562 # ipv6 address autoconfig
563 # ipv6 nd dad enable
564 # ipv6 nd-proxy enable remote-only
565 # ipv6 nd-proxy rule prefix 6001::/24
566 # !
567 # interface Ethernet24
568 # mtu 9100
569 # speed 100000
570 # shutdown
571 # ip address 91.1.1.1/16
572 # ipv6 address 90::1/16
573 # ipv6 address 91::1/16
574 # ipv6 address 92::1/16
575 # ipv6 address 93::1/16
576 # !
577
578 - name: Override l3 interface
579 dellemc.enterprise_sonic.sonic_l3_interfaces:
580 config:
581 - name: Ethernet24
582 ipv4:
583 - address: 81.1.1.1/16
584 proxy_arp:
585 mode: ALL
586 - name: Vlan100
587 ipv4:
588 anycast_addresses:
589 - 83.1.1.1/24
590 - 85.1.1.12/24
591 ipv6:
592 anycast_addresses:
593 - 83::1/24
594 - 85::1/24
595 nd_proxy:
596 mode: REMOTE_ONLY
597 nd_proxy_rules:
598 - 6001::/24
599 state: overridden
600
601 # After state:
602 # ------------
603 #
604 # sonic# show running-configuration interface
605 # !
606 # interface Ethernet20
607 # mtu 9100
608 # speed 100000
609 # shutdown
610 # !
611 # interface Ethernet24
612 # mtu 9100
613 # speed 100000
614 # shutdown
615 # ip address 81.1.1.1/16
616 # ip proxy-arp enable all
617 # !
618 # interface Vlan100
619 # ip anycast-address 83.1.1.1/24
620 # ip anycast-address 85.1.1.12/24
621 # ipv6 anycast-address 83::1/24
622 # ipv6 anycast-address 85::1/24
623 # ipv6 nd-proxy enable remote-only
624 # ipv6 nd-proxy rule prefix 6001::/24
625
626 # !
627 """
628
629 RETURN = """
630 before:
631 description: The configuration prior to the module invocation.
632 returned: always
633 type: list
634 sample: >
635 The configuration returned will always be in the same format
636 as the parameters above.
637 after:
638 description: The resulting configuration module invocation.
639 returned: when changed
640 type: list
641 sample: >
642 The configuration returned will always be in the same format
643 as the parameters above.
644 after_generated:
645 description: The generated configuration module invocation.
646 returned: when C(check_mode)
647 type: list
648 sample: >
649 The configuration returned will always be in the same format
650 as the parameters above.
651 commands:
652 description: The set of commands pushed to the remote device.
653 returned: always
654 type: list
655 sample: ['command 1', 'command 2', 'command 3']
656 """
657
658
659 from ansible.module_utils.basic import AnsibleModule
660 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs
661 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.l3_interfaces.l3_interfaces import L3_interfaces
662
663
664 def main():
665 """
666 Main entry point for module execution
667
668 :returns: the result form module invocation
669 """
670 module = AnsibleModule(argument_spec=L3_interfacesArgs.argument_spec,
671 supports_check_mode=True)
672
673 result = L3_interfaces(module).execute_module()
674 module.exit_json(**result)
675
676
677 if __name__ == '__main__':
678 main()