Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ospfv3.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_ospfv3
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_ospfv3
18 version_added: '3.1.0'
19 notes:
20 - Supports C(check_mode).
21 - Tested against Enterprise SONiC Distribution by Dell Technologies.
22 short_description: Configure global OSPFv3 protocol settings on SONiC.
23 description:
24 - This module provides configuration management of global OSPFv3 parameters on devices running SONiC.
25 - Configure VRF instance before configuring OSPFv3 in a VRF.
26 author: "Thenmozhi Gopal (@thenmozhi-gopal), Naresh Sasivarnan (@NareshSasivarnan)"
27
28 options:
29 config:
30 description:
31 - Specifies the OSPFv3 related configuration.
32 type: list
33 elements: dict
34 suboptions:
35 auto_cost_reference_bandwidth:
36 description:
37 - Configure interface auto cost reference bandwidth (1 to 4294967).
38 type: int
39 distance:
40 description:
41 - Configure route administrative distance.
42 type: dict
43 suboptions:
44 all:
45 description:
46 - Distance value for all type of routes (1 to 255).
47 type: int
48 external:
49 description:
50 - External routes (1 to 255).
51 type: int
52 inter_area:
53 description:
54 - Inter area routes (1 to 255).
55 type: int
56 intra_area:
57 description:
58 - Intra area routes (1 to 255).
59 type: int
60 graceful_restart:
61 description:
62 - OSPFv3 non stop forwarding (NSF) also known as OSPFv3 Graceful Restart.
63 type: dict
64 suboptions:
65 enable:
66 description:
67 - Enable graceful restart.
68 type: bool
69 grace_period:
70 description:
71 - Maximum length of the grace period (1 to 1800).
72 type: int
73 helper:
74 description:
75 - OSPFv3 GR Helper.
76 type: dict
77 suboptions:
78 enable:
79 description:
80 - Enable Helper support.
81 type: bool
82 advertise_router_id:
83 description:
84 - Advertising Router ID.
85 type: list
86 elements: str
87 planned_only:
88 description:
89 - Supported only planned restart.
90 type: bool
91 strict_lsa_checking:
92 description:
93 - Enable strict LSA check.
94 type: bool
95 supported_grace_time:
96 description:
97 - Supported grace interval (10 to 1800).
98 type: int
99 log_adjacency_changes:
100 description:
101 - Enable OSPFv3 adjacency state logs.
102 type: str
103 choices:
104 - brief
105 - detail
106 maximum_paths:
107 description:
108 - Configure maximum number of multiple paths for ECMP support (1 to 256).
109 type: int
110 redistribute:
111 description:
112 - Configure route redistribution into OSPFv3 router.
113 type: list
114 elements: dict
115 suboptions:
116 always:
117 description:
118 - Enable default route redistribution into OSPFv3 always.
119 - Only available for I(protocol=default_route).
120 type: bool
121 metric:
122 description:
123 - Metric value for redistributed routes (0 to 16777214).
124 type: int
125 metric_type:
126 description:
127 - Metric type for redistributed routes.
128 type: int
129 choices:
130 - 1
131 - 2
132 protocol:
133 description:
134 - Configure the type of protocol to redistribute into OSPFv3.
135 - Deleting I(protocol) alone will also delete all the other configuration under I(redistribute).
136 - C(bgp) - Border Gateway Protocol.
137 - C(connected) - Directly connected or attached subnets and hosts.
138 - C(default_route) - Default routes.
139 - C(kernel) - Kernel routes other than FRR installed routes.
140 - C(static) - Statically configured routes.
141 type: str
142 choices:
143 - bgp
144 - connected
145 - default_route
146 - kernel
147 - static
148 required: true
149 route_map:
150 description:
151 - Route map to filter redistributed routes.
152 - Configure route map before.
153 type: str
154 router_id:
155 description:
156 - Configure OSPFv3 router identifier (A.B.C.D).
157 type: str
158 timers:
159 description:
160 - Configures router timers.
161 type: dict
162 suboptions:
163 lsa_min_arrival:
164 description:
165 - LSA minimum arrival timer (0 to 600000).
166 type: int
167 throttle_spf:
168 description:
169 - OSPFv3 SPF timers.
170 - I(delay_time), I(initial_hold_time) and I(maximum_hold_time) are required together.
171 type: dict
172 suboptions:
173 delay_time:
174 description:
175 - SPF delay time in milliseconds (0 to 600000).
176 type: int
177 initial_hold_time:
178 description:
179 - SPF initial hold time in milliseconds (0 to 600000).
180 type: int
181 maximum_hold_time:
182 description:
183 - SPF maximum hold time in milliseconds (0 to 600000).
184 type: int
185 write_multiplier:
186 description:
187 - Configure write multiplier (1 to 100).
188 - Maximum number of interfaces serviced per write.
189 type: int
190 vrf_name:
191 description:
192 - Specifies the vrf name.
193 type: str
194 default: 'default'
195 state:
196 description:
197 - Specifies the operation to be performed on the OSPFv3 process configured on the device.
198 - In case of merged, the input configuration will be merged with the existing OSPFv3 configuration on the device.
199 - In case of deleted, the specified existing OSPFv3 configuration will be removed from the device.
200 - In case of overridden, all the existing OSPFv3 configuration will be deleted and the specified input configuration will be installed.
201 - In case of replaced, the existing OSPFv3 configuration on the device will be replaced by the configuration
202 in the playbook for each VRF group configured by the playbook.
203 type: str
204 default: merged
205 choices: ['merged', 'deleted', 'replaced', 'overridden']
206 """
207
208 EXAMPLES = """
209 # Using deleted
210
211 # Before state:
212 # -------------
213 #
214 # sonic# show running-configuration ospfv3
215 # router ospfv3 vrf Vrf_1
216 # timers throttle spf 50 20 1000
217 # redistribute bgp metric 15 metric-type 2 route-map RMAP
218 # !
219 # router ospfv3
220 # ospfv3 router-id 20.20.20.20
221 # distance 30
222 # distance ospfv3 external 20
223 # write-multiplier 20
224 # !
225 # sonic#
226 # sonic# show running-configuration vrf Vrf_1
227 # !
228 # ip vrf Vrf_1
229 # sonic# show running-configuration ipv6 prefix-list
230 # !
231 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/64
232 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/64
233 # sonic# show running-configuration route-map
234 # !
235 # route-map RMAP permit 1
236 # sonic#
237
238 - name: Delete the OSPFv3 configurations
239 sonic_ospfv3:
240 config:
241 - vrf_name: 'default'
242 router_id: "20.20.20.20"
243 distance:
244 external: 20
245 - vrf_name: "Vrf_1"
246 timers:
247 throttle_spf:
248 delay_time: 50
249 initial_hold_time: 20
250 maximum_hold_time: 1000
251 state: deleted
252
253 # After state:
254 # ------------
255 #
256 # sonic# show running-configuration ospfv3
257 # router ospfv3 vrf Vrf_1
258 # redistribute bgp metric 15 metric-type 2 route-map RMAP
259 # !
260 # router ospfv3
261 # distance 30
262 # write-multiplier 20
263 # !
264 # sonic#
265
266
267 # Using deleted
268
269 # Before state:
270 # -------------
271 #
272 # sonic# show running-configuration ospfv3
273 # router ospfv3 vrf Vrf_1
274 # timers throttle spf 50 20 1000
275 # redistribute bgp metric 15 metric-type 2 route-map RMAP
276 # !
277 # router ospfv3
278 # distance 30
279 # write-multiplier 20
280 # !
281 # sonic#
282 # sonic# show running-configuration vrf Vrf_1
283 # !
284 # ip vrf Vrf_1
285 # sonic# show running-configuration ipv6 prefix-list
286 # !
287 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/24
288 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/24
289 # sonic# show running-configuration route-map
290 # !
291 # route-map RMAP permit 1
292 # sonic#
293
294 - name: Delete the OSPFv3 configurations
295 sonic_ospfv3:
296 config:
297 - vrf_name: "Vrf_1"
298 state: deleted
299
300 # After state:
301 # ------------
302 #
303 # sonic# show running-configuration ospfv3
304 # router ospfv3
305 # distance 30
306 # write-multiplier 20
307 # !
308 # sonic#
309
310
311 # Using merged
312
313 # Before state:
314 # -------------
315 #
316 # sonic# show running-configuration ospfv3
317 # (No ospfv3 configuration present)
318 # sonic# show running-configuration vrf Vrf_1
319 # !
320 # ip vrf Vrf_1
321 # sonic# show running-configuration ipv6 prefix-list
322 # !
323 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/24
324 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/24
325 # sonic# show running-configuration route-map
326 # !
327 # route-map RMAP permit 1
328 # sonic#
329
330 - name: Add the OSPFv3 configurations
331 sonic_ospfv3:
332 config:
333 - vrf_name: 'default'
334 router_id: "10.10.10.10"
335 distance:
336 external: 20
337 - vrf_name: "Vrf_1"
338 timers:
339 throttle_spf:
340 delay_time: 10
341 initial_hold_time: 20
342 maximum_hold_time: 50
343 redistribute:
344 - protocol: "bgp"
345 metric: 15
346 metric_type: 2
347 route_map: "RMAP"
348 state: merged
349
350 # After state:
351 # ------------
352 #
353 # sonic# show running-configuration ospfv3
354 # router ospfv3 vrf Vrf_1
355 # timers throttle spf 10 20 50
356 # redistribute bgp metric 15 metric-type 2 route-map RMAP
357 # !
358 # router ospfv3
359 # ospfv3 router-id 10.10.10.10
360 # distance ospfv3 external 20
361 # !
362 # sonic#
363
364
365 # Using merged
366
367 # Before state:
368 # -------------
369 #
370 # sonic# show running-configuration ospfv3
371 # router ospfv3 vrf Vrf_1
372 # timers throttle spf 10 20 50
373 # redistribute bgp metric 15 metric-type 2 route-map RMAP
374 # !
375 # router ospfv3
376 # ospfv3 router-id 10.10.10.10
377 # distance ospfv3 external 20
378 # !
379 # sonic#
380 # sonic# show running-configuration vrf Vrf_1
381 # !
382 # ip vrf Vrf_1
383 # sonic# show running-configuration ipv6 prefix-list
384 # !
385 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/24
386 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/24
387 # sonic# show running-configuration route-map
388 # !
389 # route-map RMAP permit 1
390 # sonic#
391
392 - name: Add the OSPFv3 configurations
393 sonic_ospfv3:
394 config:
395 - vrf_name: 'default'
396 write_multiplier: 20
397 router_id: "20.20.20.20"
398 distance:
399 all: 30
400 - vrf_name: "Vrf_1"
401 timers:
402 throttle_spf:
403 delay_time: 50
404 initial_hold_time: 20
405 maximum_hold_time: 100
406 state: merged
407
408 # After state:
409 # ------------
410 #
411 # sonic# show running-configuration ospfv3
412 # router ospfv3 vrf Vrf_1
413 # timers throttle spf 50 20 100
414 # redistribute bgp metric 15 metric-type 2 route-map RMAP
415 # !
416 # router ospfv3
417 # ospfv3 router-id 20.20.20.20
418 # distance 30
419 # distance ospfv3 external 20
420 # write-multiplier 20
421 # !
422 # sonic#
423
424
425 # Using replaced
426
427 # Before state:
428 # -------------
429 #
430 # sonic# show running-configuration ospfv3
431 # router ospfv3 vrf Vrf_1
432 # timers throttle spf 50 20 10
433 # redistribute bgp metric 15 metric-type 2 route-map RMAP
434 # !
435 # router ospfv3
436 # ospfv3 router-id 20.20.20.20
437 # distance 30
438 # distance ospfv3 external 20
439 # write-multiplier 20
440 # !
441 # sonic#
442 # sonic# show running-configuration vrf Vrf_1
443 # !
444 # ip vrf Vrf_1
445 # sonic# show running-configuration ipv6 prefix-list
446 # !
447 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/24
448 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/24
449 # sonic# show running-configuration route-map
450 # !
451 # route-map RMAP permit 1
452 # route-map RMAP2 permit 2
453 # sonic#
454
455 - name: Replace the OSPFv3 vrf default configurations
456 sonic_ospfv3:
457 config:
458 - vrf_name: 'default'
459 router_id: "20.20.20.20"
460 redistribute:
461 - protocol: "connected"
462 metric: 15
463 metric_type: 2
464 route_map: "RMAP2"
465 distance:
466 all: 20
467 state: replaced
468
469 # After state:
470 # ------------
471 #
472 # sonic# show running-configuration ospfv3
473 # router ospfv3 vrf Vrf_1
474 # timers throttle spf 50 20 10
475 # redistribute bgp metric 15 metric-type 2 route-map RMAP
476 # !
477 # router ospfv3
478 # ospfv3 router-id 20.20.20.20
479 # distance 20
480 # redistribute connected metric 15 metric-type 2 route-map RMAP2
481 # !
482
483
484 # Using overridden
485
486 # Before state:
487 # -------------
488 #
489 # sonic# show running-configuration ospfv3
490 # router ospfv3 vrf Vrf_1
491 # timers throttle spf 50 20 10
492 # redistribute bgp metric 15 metric-type 2 route-map RMAP
493 # !
494 # router ospfv3
495 # ospfv3 router-id 20.20.20.20
496 # distance 30
497 # distance ospfv3 external 20
498 # write-multiplier 20
499 # !
500 # sonic#
501 # sonic# show running-configuration vrf Vrf_1
502 # !
503 # ip vrf Vrf_1
504 # sonic# show running-configuration ipv6 prefix-list
505 # !
506 # ipv6 prefix-list PRF_LIST seq 1 permit 1::1/24
507 # ipv6 prefix-list PRF_LIST2 seq 1 permit 2::1/24
508 # sonic# show running-configuration route-map
509 # !
510 # route-map RMAP permit 1
511 # route-map RMAP2 permit 2
512 # sonic#
513
514 - name: Override the OSPFv3 configurations
515 sonic_ospfv3:
516 config:
517 - vrf_name: 'default'
518 router_id: "20.20.20.20"
519 redistribute:
520 - protocol: "connected"
521 metric: 15
522 metric_type: 2
523 route_map: "RMAP2"
524 distance:
525 all: 20
526 state: replaced
527
528 # After state:
529 # ------------
530 #
531 # sonic# show running-configuration ospfv3
532 # router ospfv3
533 # ospfv3 router-id 20.20.20.20
534 # distance 20
535 # redistribute connected metric 15 metric-type 2 route-map RMAP2
536 # !
537 """
538
539 RETURN = """
540 before:
541 description: The configuration prior to the module invocation.
542 returned: always
543 type: list
544 sample: >
545 The configuration returned will always be in the same format
546 as the parameters above.
547 after:
548 description: The configuration resulting from module invocation.
549 returned: when changed
550 type: list
551 sample: >
552 The configuration returned will always be in the same format
553 as the parameters above.
554 after_generated:
555 description: The generated (calculated) configuration that would be applied by module invocation.
556 returned: when C(check_mode)
557 type: list
558 sample: >
559 The configuration returned will always be in the same format
560 as the parameters above.
561 commands:
562 description: The set of commands pushed to the remote device.
563 returned: always
564 type: list
565 sample: ['command 1', 'command 2', 'command 3']
566 """
567
568
569 from ansible.module_utils.basic import AnsibleModule
570 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ospfv3.ospfv3 import Ospfv3Args
571 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ospfv3.ospfv3 import Ospfv3
572
573
574 def main():
575 """
576 Main entry point for module execution
577
578 :returns: the result form module invocation
579 """
580 module = AnsibleModule(argument_spec=Ospfv3Args.argument_spec,
581 supports_check_mode=True)
582
583 result = Ospfv3(module).execute_module()
584 module.exit_json(**result)
585
586
587 if __name__ == '__main__':
588 main()