Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ipv6_router_advertisement.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_ipv6_router_advertisement
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_ipv6_router_advertisement
17 version_added: '3.1.0'
18 short_description: Manage interface-specific IPv6 Router Advertisement configurations on SONiC
19 description:
20 - This module provides configuration management of interface-specific
21 IPv6 Router Advertisement parameters for devices running SONiC.
22 - This functionality is referred to as 'ipv6 nd' in Enterprise SONiC CLI.
23 author: 'Arun Saravanan Balachandran (@ArunSaravananBalachandran)'
24 options:
25 config:
26 description:
27 - Specifies interface-specific IPv6 Router Advertisement configurations.
28 type: list
29 elements: dict
30 suboptions:
31 name:
32 description:
33 - Full name of the interface.
34 type: str
35 required: true
36 adv_interval_option:
37 description:
38 - Include Advertisement Interval option in Router Advertisement.
39 type: bool
40 home_agent_config:
41 description:
42 - Set 'Home Agent' flag in Router Advertisement.
43 type: bool
44 home_agent_lifetime:
45 description:
46 - Specifies the Home Agent lifetime in seconds when I(home_agent_config=True).
47 - The range is from 0 to 65520.
48 type: int
49 home_agent_preference:
50 description:
51 - Specifies the Home Agent preference when I(home_agent_config=True).
52 - The range is from 0 to 65535.
53 type: int
54 managed_config:
55 description:
56 - Set 'Managed Address Configuration' flag in Router Advertisement.
57 type: bool
58 mtu:
59 description:
60 - Specifies the MTU (in bytes) to be advertised.
61 - The range is from 0 to 65535.
62 type: int
63 other_config:
64 description:
65 - Set 'Other Configuration' flag in Router Advertisement.
66 type: bool
67 ra_fast_retrans:
68 description:
69 - Enable faster transmissions of RA packets.
70 type: bool
71 ra_hop_limit:
72 description:
73 - Specifies the Hop limit to be advertised.
74 - The range is from 0 to 255.
75 type: int
76 ra_interval:
77 description:
78 - Specifies the maximum Router Advertisement interval in seconds.
79 - The range is from 1 to 1800.
80 type: int
81 ra_interval_msec:
82 description:
83 - Specifies the maximum Router Advertisement interval in milliseconds.
84 - The range is from 70 to 1800000.
85 type: int
86 min_ra_interval:
87 description:
88 - Specifies the minimum Router Advertisement interval in seconds.
89 - The range is from 1 to 1350.
90 type: int
91 min_ra_interval_msec:
92 description:
93 - Specifies the minimum Router Advertisement interval in milliseconds.
94 - The range is from 30 to 1350000.
95 type: int
96 ra_lifetime:
97 description:
98 - Specifies the Router Lifetime in seconds.
99 - The range is from 0 to 9000.
100 type: int
101 ra_retrans_interval:
102 description:
103 - Specifies the Retransmission Interval in milliseconds.
104 - The range is from 0 to 4294967295.
105 type: int
106 reachable_time:
107 description:
108 - Specifies the Reachable Time in milliseconds.
109 - The range is from 0 to 3600000.
110 type: int
111 router_preference:
112 description:
113 - Specifies the default router preference.
114 type: str
115 choices:
116 - low
117 - medium
118 - high
119 suppress:
120 description:
121 - Enable suppression of Router Advertisement.
122 type: bool
123 dnssl:
124 description:
125 - Specifies the DNS search list to advertise.
126 - If I(state=deleted), options other than I(dnssl_name) are not considered.
127 type: list
128 elements: dict
129 suboptions:
130 dnssl_name:
131 description:
132 - Domain Name suffix to be advertised.
133 type: str
134 required: true
135 valid_lifetime:
136 description:
137 - Specifies the valid lifetime in seconds.
138 - The range if from 0 to 4294967295.
139 - Value of 4294967295 represents infinite valid lifetime.
140 type: int
141 ra_prefixes:
142 description:
143 - Specifies the IPv6 prefixes to be included in Router Advertisement.
144 - If I(state=deleted), options other than I(prefix) are not considered.
145 type: list
146 elements: dict
147 suboptions:
148 prefix:
149 description:
150 - IPv6 prefix to be advertised.
151 type: str
152 required: true
153 valid_lifetime:
154 description:
155 - Specifies the valid lifetime in seconds.
156 - The range if from 0 to 4294967295.
157 - Value of 4294967295 represents infinite valid lifetime.
158 type: int
159 preferred_lifetime:
160 description:
161 - Specifies the preferred lifetime in seconds.
162 - The range if from 0 to 4294967295.
163 - Value of 4294967295 represents infinite preferred lifetime.
164 type: int
165 no_autoconfig:
166 description:
167 - Indicate the prefix cannot be used for IPv6 autoconfiguration.
168 type: bool
169 off_link:
170 description:
171 - Indicate the prefix cannot be used for on-link determination.
172 type: bool
173 router_address:
174 description:
175 - Set 'Router Address' flag.
176 type: bool
177 rdnss:
178 description:
179 - Specifies the Recursive DNS server addresses to advertise.
180 - If I(state=deleted), options other than I(address) are not considered.
181 type: list
182 elements: dict
183 suboptions:
184 address:
185 description:
186 - Recursive DNS server address to be advertised.
187 type: str
188 required: true
189 valid_lifetime:
190 description:
191 - Specifies the valid lifetime in seconds.
192 - The range if from 0 to 4294967295.
193 - Value of 4294967295 represents infinite valid lifetime.
194 type: int
195 state:
196 description:
197 - The state of the configuration after module completion.
198 - C(merged) - Merges provided interface-specific IPv6 router advertisement configuration with on-device configuration.
199 - C(replaced) - Replaces on-device IPv6 router advertisement configuration of the specified interfaces with provided configuration.
200 - C(overridden) - Overrides all on-device interface-specific IPv6 router advertisement configurations with the provided configuration.
201 - C(deleted) - Deletes on-device interface-specific IPv6 router advertisement configuration.
202 type: str
203 choices:
204 - merged
205 - deleted
206 - replaced
207 - overridden
208 default: merged
209 """
210 EXAMPLES = """
211 # Using merged
212 #
213 # Before State:
214 # -------------
215 #
216 # sonic# show running-configuration interface
217 # !
218 # interface Eth1/1
219 # mtu 9100
220 # speed 400000
221 # fec RS
222 # no shutdown
223 # !
224 # interface Eth1/2
225 # mtu 9100
226 # speed 400000
227 # fec RS
228 # no shutdown
229 # no ipv6 nd suppress-ra
230 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
231 # !
232
233 - name: Add IPv6 Router Advertisement configurations
234 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
235 config:
236 - name: 'Eth1/1'
237 suppress: false
238 router_preference: high
239 ra_interval: 180
240 min_ra_interval: 60
241 ra_lifetime: 360
242 ra_retrans_interval: 30000
243 ra_hop_limit: 10
244 dnssl:
245 - dnssl_name: 'test.com'
246 valid_lifetime: 3600
247 rdnss:
248 - address: 100::100
249 - address: 100::200
250 - name: 'Eth1/2'
251 adv_interval_option: true
252 ra_fast_retrans: false
253 reachable_time: 7200000
254 ra_prefixes:
255 - prefix: 1000:0:0:2000::/64
256 valid_lifetime: 86400
257 preferred_lifetime: 86400
258 off_link: true
259 no_autoconfig: true
260 state: merged
261
262 # After State:
263 # ------------
264 #
265 # sonic# show running-configuration interface
266 # !
267 # interface Eth1/1
268 # mtu 9100
269 # speed 400000
270 # fec RS
271 # no shutdown
272 # no ipv6 nd suppress-ra
273 # ipv6 nd ra-hop-limit 10
274 # ipv6 nd ra-interval 180
275 # ipv6 nd min-ra-interval 60
276 # ipv6 nd ra-lifetime 360
277 # ipv6 nd ra-retrans-interval 30000
278 # ipv6 nd router-preference high
279 # ipv6 nd dnssl test.com 3600
280 # ipv6 nd rdnss 100::100
281 # ipv6 nd rdnss 100::200
282 # !
283 # interface Eth1/2
284 # mtu 9100
285 # speed 400000
286 # fec RS
287 # no shutdown
288 # no ipv6 nd suppress-ra
289 # no ipv6 nd ra-fast-retrans
290 # ipv6 nd adv-interval-option
291 # ipv6 nd reachable-time 1200000
292 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
293 # ipv6 nd prefix 1000:0:0:2000::/64 86400 86400 off-link no-autoconfig
294 # !
295
296
297 # Using deleted
298 #
299 # Before State:
300 # -------------
301 #
302 # sonic# show running-configuration interface
303 # !
304 # interface Eth1/1
305 # mtu 9100
306 # speed 400000
307 # fec RS
308 # no shutdown
309 # no ipv6 nd suppress-ra
310 # ipv6 nd ra-hop-limit 10
311 # ipv6 nd ra-interval 180
312 # ipv6 nd min-ra-interval 60
313 # ipv6 nd ra-lifetime 360
314 # ipv6 nd ra-retrans-interval 30000
315 # ipv6 nd router-preference high
316 # ipv6 nd dnssl test.com 3600
317 # ipv6 nd dnssl test2.com 7200
318 # ipv6 nd rdnss 100::100 3600
319 # ipv6 nd rdnss 100::200 7200
320 # !
321 # interface Eth1/2
322 # mtu 9100
323 # speed 400000
324 # fec RS
325 # no shutdown
326 # no ipv6 nd suppress-ra
327 # no ipv6 nd ra-fast-retrans
328 # ipv6 nd adv-interval-option
329 # ipv6 nd min-ra-interval msec 45500
330 # ipv6 nd reachable-time 1200000
331 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
332 # ipv6 nd prefix 1000:0:0:2000::/64 86400 86400 off-link no-autoconfig
333 # !
334
335 - name: Delete IPv6 Router Advertisement configurations
336 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
337 config:
338 - name: 'Eth1/1'
339 ra_hop_limit: 10
340 router_preference: high
341 dnssl:
342 - dnssl_name: test2.com
343 rdnss:
344 - address: 100::200
345 - name: 'Eth1/2'
346 adv_interval_option: true
347 ra_fast_retrans: false
348 ra_prefixes:
349 - prefix: 1000:0:0:2000::/64
350 state: deleted
351
352 # After State:
353 # ------------
354 #
355 # sonic# show running-configuration interface
356 # !
357 # interface Eth1/1
358 # mtu 9100
359 # speed 400000
360 # fec RS
361 # shutdown
362 # no ipv6 nd suppress-ra
363 # ipv6 nd ra-interval 180
364 # ipv6 nd min-ra-interval 60
365 # ipv6 nd ra-lifetime 360
366 # ipv6 nd ra-retrans-interval 30000
367 # ipv6 nd dnssl test.com 3600
368 # ipv6 nd rdnss 100::100 3600
369 # !
370 # interface Eth1/2
371 # mtu 9100
372 # speed 400000
373 # fec RS
374 # shutdown
375 # no ipv6 nd suppress-ra
376 # ipv6 nd min ra-interval msec 45500
377 # ipv6 nd reachable-time 1200000
378 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
379 # !
380
381
382 # Using deleted
383 #
384 # Before State:
385 # -------------
386 #
387 # sonic# show running-configuration interface
388 # !
389 # interface Eth1/1
390 # mtu 9100
391 # speed 400000
392 # fec RS
393 # no shutdown
394 # no ipv6 nd suppress-ra
395 # ipv6 nd ra-hop-limit 10
396 # ipv6 nd ra-interval 180
397 # ipv6 nd min-ra-interval 60
398 # ipv6 nd ra-lifetime 360
399 # ipv6 nd ra-retrans-interval 30000
400 # ipv6 nd dnssl test.com 3600
401 # ipv6 nd rdnss 100::100 3600
402 # ipv6 nd rdnss 100::200 7200
403 # !
404 # interface Eth1/2
405 # mtu 9100
406 # speed 400000
407 # fec RS
408 # no shutdown
409 # no ipv6 nd suppress-ra
410 # ipv6 nd adv-interval-option
411 # ipv6 nd router-preference low
412 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
413 # !
414
415 - name: Delete all IPv6 Router Advertisement configurations for interface Eth1/1
416 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
417 config:
418 - name: 'Eth1/1'
419 state: deleted
420
421 # After State:
422 # ------------
423 #
424 # sonic# show running-configuration interface
425 # !
426 # interface Eth1/1
427 # mtu 9100
428 # speed 400000
429 # fec RS
430 # no shutdown
431 # !
432 # interface Eth1/2
433 # mtu 9100
434 # speed 400000
435 # fec RS
436 # no shutdown
437 # no ipv6 nd suppress-ra
438 # ipv6 nd adv-interval-option
439 # ipv6 nd router-preference low
440 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
441 # !
442
443
444 # Using deleted
445 #
446 # Before State:
447 # -------------
448 #
449 # sonic# show running-configuration interface
450 # !
451 # interface Eth1/1
452 # mtu 9100
453 # speed 400000
454 # fec RS
455 # no shutdown
456 # no ipv6 nd suppress-ra
457 # ipv6 nd ra-hop-limit 10
458 # ipv6 nd ra-interval 180
459 # ipv6 nd min-ra-interval 60
460 # ipv6 nd ra-lifetime 360
461 # ipv6 nd ra-retrans-interval 30000
462 # ipv6 nd dnssl test.com 3600
463 # ipv6 nd rdnss 100::100 3600
464 # ipv6 nd rdnss 100::200 7200
465 # !
466 # interface Eth1/2
467 # mtu 9100
468 # speed 400000
469 # fec RS
470 # no shutdown
471 # no ipv6 nd suppress-ra
472 # ipv6 nd adv-interval-option
473 # ipv6 nd router-preference low
474 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
475 # !
476
477 - name: Delete all IPv6 Router Advertisement configurations
478 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
479 config:
480 state: deleted
481
482 # After State:
483 # ------------
484 #
485 # sonic# show running-configuration interface
486 # !
487 # interface Eth1/1
488 # mtu 9100
489 # speed 400000
490 # fec RS
491 # no shutdown
492 # !
493 # interface Eth1/2
494 # mtu 9100
495 # speed 400000
496 # fec RS
497 # no shutdown
498 # !
499
500
501 # Using replaced
502 #
503 # Before State:
504 # -------------
505 #
506 # sonic# show running-configuration interface
507 # !
508 # interface Eth1/1
509 # mtu 9100
510 # speed 400000
511 # fec RS
512 # no shutdown
513 # no ipv6 nd suppress-ra
514 # ipv6 nd ra-hop-limit 10
515 # ipv6 nd ra-interval 180
516 # ipv6 nd min-ra-interval 60
517 # ipv6 nd ra-lifetime 360
518 # ipv6 nd router-preference high
519 # !
520 # interface Eth1/2
521 # mtu 9100
522 # speed 400000
523 # fec RS
524 # no shutdown
525 # no ipv6 nd suppress-ra
526 # no ipv6 nd ra-fast-retrans
527 # ipv6 nd adv-interval-option
528 # ipv6 nd min-ra-interval msec 45500
529 # ipv6 nd ra-hop-limit 10
530 # ipv6 nd reachable-time 1200000
531 # ipv6 nd prefix 1000:0:0:1000::/64 86400 86400 off-link no-autoconfig
532 # ipv6 nd prefix 1000:0:0:2000::/64 86400 86400 off-link no-autoconfig
533 # !
534
535 - name: Replace IPv6 Router Advertisement configurations for interface Eth1/2
536 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
537 config:
538 - name: 'Eth1/2'
539 suppress: false
540 ra_interval: 300
541 router_preference: high
542 ra_prefixes:
543 - prefix: 2000:0:0:1000::/64
544 valid_lifetime: 3600
545 preferred_lifetime: 3600
546 router_address: true
547 state: replaced
548
549 # After State:
550 # ------------
551 #
552 # sonic# show running-configuration interface
553 # !
554 # interface Eth1/1
555 # mtu 9100
556 # speed 400000
557 # fec RS
558 # no shutdown
559 # no ipv6 nd suppress-ra
560 # ipv6 nd ra-hop-limit 10
561 # ipv6 nd ra-interval 180
562 # ipv6 nd min-ra-interval 60
563 # ipv6 nd ra-lifetime 360
564 # ipv6 nd router-preference high
565 # !
566 # interface Eth1/2
567 # mtu 9100
568 # speed 400000
569 # fec RS
570 # no shutdown
571 # no ipv6 nd suppress-ra
572 # ipv6 nd ra-interval 300
573 # ipv6 nd router-preference high
574 # ipv6 nd prefix 2000:0:0:1000::/64 3600 3600 router-address
575 # !
576
577
578 # Using overridden
579 #
580 # Before State:
581 # -------------
582 #
583 # sonic# show running-configuration interface
584 # !
585 # interface Eth1/1
586 # mtu 9100
587 # speed 400000
588 # fec RS
589 # no shutdown
590 # no ipv6 nd suppress-ra
591 # ipv6 nd ra-hop-limit 10
592 # ipv6 nd ra-interval 180
593 # ipv6 nd min-ra-interval 60
594 # ipv6 nd ra-lifetime 360
595 # ipv6 nd router-preference high
596 # !
597 # interface Eth1/2
598 # mtu 9100
599 # speed 400000
600 # fec RS
601 # no shutdown
602 # no ipv6 nd suppress-ra
603 # ipv6 nd ra-interval 300
604 # ipv6 nd router-preference high
605 # ipv6 nd prefix 2000:0:0:1000::/64 3600 3600 router-address
606 # !
607 # interface Eth1/3
608 # mtu 9100
609 # speed 400000
610 # fec RS
611 # no shutdown
612 # !
613
614 - name: Override all IPv6 Router Advertisement configurations
615 dellemc.enterprise_sonic.sonic_ipv6_router_advertisement:
616 config:
617 - name: 'Eth1/1'
618 suppress: false
619 home_agent_config: true
620 home_agent_lifetime: 7200
621 home_agent_preference: 100
622 - name: 'Eth1/3'
623 suppress: false
624 managed_config: true
625 other_config: true
626 ra_retrans_interval: 30000
627 state: overridden
628
629 # After State:
630 # ------------
631 #
632 # sonic# show running-configuration interface
633 # !
634 # interface Eth1/1
635 # mtu 9100
636 # speed 400000
637 # fec RS
638 # no shutdown
639 # no ipv6 nd suppress-ra
640 # ipv6 nd home-agent-config-flag
641 # ipv6 nd home-agent-lifetime 7200
642 # ipv6 nd home-agent-preference 100
643 # !
644 # interface Eth1/2
645 # mtu 9100
646 # speed 400000
647 # fec RS
648 # no shutdown
649 # !
650 # interface Eth1/3
651 # mtu 9100
652 # speed 400000
653 # fec RS
654 # no shutdown
655 # no ipv6 nd suppress-ra
656 # ipv6 nd managed-config-flag
657 # ipv6 nd other-config-flag
658 # ipv6 nd ra-retrans-interval 30000
659 # !
660 """
661 RETURN = """
662 before:
663 description: The configuration prior to the module invocation.
664 returned: always
665 type: list
666 sample: >
667 The configuration returned will always be in the same format
668 of the parameters above.
669 after:
670 description: The configuration resulting from module invocation.
671 returned: when changed
672 type: list
673 sample: >
674 The configuration returned will always be in the same format
675 of the parameters above.
676 after_generated:
677 description: The configuration that would be generated by module invocation.
678 returned: when C(check_mode)
679 type: list
680 sample: >
681 The configuration returned will always be in the same format
682 as the parameters above.
683 commands:
684 description: The set of commands pushed to the remote device.
685 returned: always
686 type: list
687 sample: ['command 1', 'command 2', 'command 3']
688 """
689
690
691 from ansible.module_utils.basic import AnsibleModule
692 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ipv6_router_advertisement.ipv6_router_advertisement import (
693 Ipv6_router_advertisementArgs
694 )
695 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ipv6_router_advertisement.ipv6_router_advertisement import (
696 Ipv6_router_advertisement
697 )
698
699
700 def main():
701 """
702 Main entry point for module execution
703
704 :returns: the result form module invocation
705 """
706 module = AnsibleModule(argument_spec=Ipv6_router_advertisementArgs.argument_spec,
707 supports_check_mode=True)
708
709 result = Ipv6_router_advertisement(module).execute_module()
710 module.exit_json(**result)
711
712
713 if __name__ == '__main__':
714 main()