Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ospfv3_area.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_area
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_ospfv3_area
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 OSPFv3 area settings on SONiC.
23 description:
24 - This module provides configuration for the area settings of OSPFv3 running on SONiC switches.
25 - Configure global/VRF OSPFv3 instance before configuring OSPFv3 areas.
26 - Configure OSPFv3 instance before configuring OSPFv3 areas.
27 author: "Santhosh kumar T (@santhosh-kt)"
28 options:
29 config:
30 description:
31 - Specifies configuration for OSPFv3 areas.
32 - I(stub) and I(nssa) are mutually exclusive.
33 - If I(area_id=0 or 0.0.0.0), I(stub/nssa) should not be specified.
34 type: list
35 elements: dict
36 suboptions:
37 area_id:
38 type: str
39 required: true
40 description:
41 - Area ID of the network (A.B.C.D or 0 to 4294967295).
42 filter_list_in:
43 type: str
44 description:
45 - Inter-area prefix filter list.
46 - Filter incoming prefixes into the area.
47 - Expects name of a prefix list.
48 filter_list_out:
49 type: str
50 description:
51 - Inter-area prefix filter list.
52 - Filter outgoing prefixes from the area.
53 - Expects name of a prefix list.
54 nssa:
55 type: dict
56 description:
57 - Configuration for NSSA type area.
58 - I(default_originate) and I(no_summary) are mutually exclusive.
59 suboptions:
60 default_originate:
61 type: dict
62 description:
63 - Advertise default route for the NSSA area.
64 suboptions:
65 enabled:
66 type: bool
67 description:
68 - Enable to advertise the default route for the NSSA area.
69 required: true
70 metric:
71 type: int
72 description:
73 - Configure metric for the redistributed route (0 to 16777214).
74 metric_type:
75 type: int
76 description:
77 - Configure metric type for the redistributed route.
78 choices: [1, 2]
79 enabled:
80 type: bool
81 description:
82 - Configure area as NSSA type area.
83 required: true
84 no_summary:
85 type: bool
86 description:
87 - Disable inter-area route injection into the NSSA.
88 ranges:
89 type: list
90 elements: dict
91 description:
92 - Configure address range summarization on border routers.
93 suboptions:
94 prefix:
95 type: str
96 required: true
97 description:
98 - Configure address range prefix.
99 advertise:
100 type: bool
101 description:
102 - Enable address range advertising.
103 - Default value while creating a new range is True.
104 - If the I(cost) is specified, I(advertise) is unconditionally set to True during playbook execution.
105 cost:
106 type: int
107 description:
108 - Configure cost of address range (0 to 16777215).
109 ranges:
110 type: list
111 elements: dict
112 description:
113 - Configure address range summarization on border routers.
114 suboptions:
115 prefix:
116 type: str
117 required: true
118 description:
119 - Configure address range prefix.
120 advertise:
121 type: bool
122 description:
123 - Enable address range advertising.
124 - Default value while creating a new range is True.
125 - If the I(cost) is specified, I(advertise) is unconditionally set to True during playbook execution.
126 cost:
127 type: int
128 description:
129 - Configure cost of address range (0 to 16777215).
130 stub:
131 type: dict
132 description:
133 - Configuration for STUB type area.
134 suboptions:
135 enabled:
136 type: bool
137 description:
138 - Configure area as STUB type area.
139 required: true
140 no_summary:
141 type: bool
142 description:
143 - Disable inter-area route injection into the STUB.
144 vrf_name:
145 type: str
146 required: true
147 description:
148 - Name of the VRF this area belongs to.
149 state:
150 description:
151 - Specifies the type of configuration update to be performed on the device.
152 type: str
153 choices:
154 - merged
155 - replaced
156 - overridden
157 - deleted
158 default: merged
159 """
160
161 EXAMPLES = """
162 # Using "deleted" state
163 #
164 # Before state:
165 # -------------
166 # sonic(config-router-ospfv3)# show configuration
167 # !
168 # router ospfv3 vrf Vrf1
169 # area 0.0.0.1 stub no-summary
170 # area 0.0.0.1 filter-list prefix pf1 in
171 # area 0.0.0.1 filter-list prefix pf2 out
172 # area 0.0.0.2 stub no-summary
173 # area 0.0.0.1 range 1::1/64 not-advertise
174 # area 0.0.0.1 range 1::2/64
175 # area 0.0.0.2 range 1::1/64
176 # area 0.0.0.3 range 1::3/24 cost 14
177 # sonic(config-router-ospfv3)#
178
179 - name: "test delete all settings for areas"
180 dellemc.enterprise_sonic.sonic_ospfv3_area:
181 state: deleted
182 config:
183 - area_id: 0.0.0.1
184 vrf_name: Vrf1
185 - area_id: 0.0.0.2
186 vrf_name: Vrf1
187 ranges:
188 - prefix: 1::1/64
189 advertise: true
190 stub:
191 enabled: true
192 no_summary: true
193
194 # After state
195 # -------------
196 # sonic(config-router-ospfv3)# show configuration
197 # !
198 # router ospfv3 vrf Vrf1
199 # area 0.0.0.3 range 1::3/24 cost 14
200 # sonic(config-router-ospfv3)#
201
202
203 # Using "deleted" state
204 # Before state:
205 # -------------
206 # sonic(config-router-ospfv3)# show configuration
207 # !
208 # router ospfv3 vrf Vrf1
209 # area 0.0.0.1 nssa no-summary
210 # area 0.0.0.3 filter-list prefix pf1 in
211 # area 0.0.0.1 nssa
212 # area 0.0.0.4 stub no-summary
213 # area 0.0.0.1 nssa range 1::1/64
214 # area 0.0.0.1 nssa range 1::2/64 cost 20
215 # area 0.0.0.2 range 1::1/64 not-advertise
216 # area 0.0.0.2 range 1::2/64 advertise cost 4
217 # area 0.0.0.2 range 1::3/24 not-advertise
218 # sonic(config-router-ospfv3)#
219
220 - name: "test clear subsections"
221 dellemc.enterprise_sonic.sonic_ospfv3_area:
222 state: deleted
223 config:
224 - area_id: 0.0.0.1
225 vrf_name: Vrf1
226 nssa:
227 enabled: true
228 ranges: []
229 - area_id: 0.0.0.2
230 vrf_name: Vrf1
231 ranges: []
232 - area_id: 4
233 vrf_name: Vrf1
234
235 # After state
236 # -------------
237 # sonic(config-router-ospfv3)# show configuration
238 # !
239 # router ospfv3 vrf Vrf1
240 # area 0.0.0.1 nssa no-summary
241 # area 0.0.0.3 filter-list prefix pf1 in
242 # area 0.0.0.1 nssa
243 # sonic(config-router-ospfv3)#
244
245
246 # Using "deleted" state
247 # Before state:
248 # -------------
249 # sonic# show running-configuration ospfv3
250 # !
251 # router ospfv3 vrf Vrf1
252 # area 0.0.0.1 nssa no-summary
253 # area 0.0.0.1 filter-list prefix pf1 in
254 # area 0.0.0.1 filter-list prefix pf2 out
255 # area 0.0.0.3 filter-list prefix pf1 in
256 # area 0.0.0.1 nssa
257 # area 0.0.0.4 stub no-summary
258 # area 0.0.0.1 nssa range 1::1/64
259 # area 0.0.0.1 nssa range 1::2/64 cost 20
260 # area 0.0.0.2 range 1::1/64 not-advertise
261 # area 0.0.0.2 range 1::2/64 advertise cost 4
262 # area 0.0.0.2 range 1::3/24 not-advertise
263 # router ospfv3
264 # area 0.0.0.1 nssa no-summary
265 # area 0.0.0.1 filter-list prefix pf1 in
266 # area 0.0.0.1 filter-list prefix pf2 out
267 # area 0.0.0.3 filter-list prefix pf1 in
268 # area 0.0.0.1 nssa
269 # area 0.0.0.4 stub no-summary
270 # area 0.0.0.1 nssa range 1::1/64
271 # area 0.0.0.1 nssa range 1::2/64 cost 20
272 # area 0.0.0.2 range 1::1/64 not-advertise
273 # area 0.0.0.2 range 1::2/64 advertise cost 4
274 # area 0.0.0.2 range 1::3/24 not-advertise
275 # sonic#
276
277 - name: "test clear subsections"
278 dellemc.enterprise_sonic.sonic_ospfv3_area:
279 state: deleted
280 config:
281 - area_id: 0.0.0.1
282 vrf_name: Vrf1
283 filter_list_in: pf1
284 filter_list_out: pf2
285 nssa:
286 enabled: true
287 range:
288 - prefix: 1::2/64
289 advertise: true
290 cost: 20
291 - area_id: 0.0.0.2
292 vrf_name: Vrf1
293 range:
294 - prefix: 1::2/64
295 - area_id: 3
296 vrf_name: default
297 - area_id: 4
298 vrf_name: default
299 stub:
300 enabled: true
301 no_summary: true
302
303 # After state
304 # -------------
305 # sonic# show running-configuration ospfv3
306 # !
307 # router ospfv3 vrf Vrf1
308 # area 0.0.0.1 nssa no-summary
309 # area 0.0.0.3 filter-list prefix pf1 in
310 # area 0.0.0.1 nssa
311 # area 0.0.0.4 stub no-summary
312 # area 0.0.0.1 nssa range 1::1/64
313 # area 0.0.0.2 range 1::1/64 not-advertise
314 # area 0.0.0.2 range 1::3/24 not-advertise
315 # router ospfv3
316 # area 0.0.0.1 nssa no-summary
317 # area 0.0.0.1 filter-list prefix pf1 in
318 # area 0.0.0.1 filter-list prefix pf2 out
319 # area 0.0.0.1 nssa
320 # area 0.0.0.4
321 # area 0.0.0.1 nssa range 1::1/64
322 # area 0.0.0.1 nssa range 1::2/64 cost 20
323 # area 0.0.0.2 range 1::1/64 not-advertise
324 # area 0.0.0.2 range 1::2/64 advertise cost 4
325 # area 0.0.0.2 range 1::3/24 not-advertise
326 # sonic#
327
328
329 # Using "merged" state
330 # Before state:
331 # -------------
332 # sonic# show running-configuration ospfv3
333 # !
334 # router ospfv3 vrf Vrf2
335 # !
336 # router ospfv3 vrf Vrf1
337 # sonic#
338
339 - name: merge examples of all settings
340 dellemc.enterprise_sonic.sonic_ospfv3_area:
341 state: merged
342 config:
343 - area_id: 1
344 vrf_name: Vrf1
345 - area_id: 2
346 vrf_name: Vrf1
347 stub:
348 enabled: true
349 no_summary: true
350 - area_id: 3
351 vrf_name: Vrf1
352 filter_list_in: pf1
353 filter_list_out: pf2
354 ranges:
355 - prefix: 1::1/64
356 - prefix: 1::2/64
357 advertise: true
358 cost: 4
359 - prefix: 1::3/24
360 advertise: false
361 - prefix: 1::4/24
362 advertise: true
363 cost: 10
364 - area_id: 4
365 vrf_name: Vrf1
366 - area_id: 5
367 vrf_name: Vrf2
368
369 # After state
370 # -------------
371 # sonic# show running-configuration ospfv3
372 #
373 # outer ospfv3 vrf Vrf1
374 # area 0.0.0.1
375 # area 0.0.0.2 stub no-summary
376 # area 0.0.0.3 filter-list prefix pf1 in
377 # area 0.0.0.3 filter-list prefix pf2 out
378 # area 0.0.0.4
379 # area 0.0.0.3 range 1::1/64
380 # area 0.0.0.3 range 1::2/64 advertise cost 4
381 # area 0.0.0.3 range 1::3/24 not-advertise
382 # area 0.0.0.3 range 1::4/24 advertise cost 10
383 # !
384 # router ospfv3 vrf Vrf2
385 # area 0.0.0.5
386 # sonic#
387
388
389 # Using "merged" state
390 # Before state:
391 # -------------
392 # sonic(config-router-ospfv3)# show configuration
393 # !
394 # router ospfv3 vrf Vrf2
395 # sonic(config-router-ospfv3)# show configuration
396 # !
397 # router ospfv3 vrf Vrf1
398 # sonic(config-router-ospfv3)#
399
400 - name: merge smallest group of settings
401 dellemc.enterprise_sonic.sonic_ospfv3_area:
402 state: merged
403 config:
404 - area_id: 0.0.0.1
405 vrf_name: Vrf1
406 - area_id: 0.0.0.2
407 vrf_name: Vrf1
408 nssa:
409 enabled: true
410 no_summary: true
411 - area_id: 0.0.0.3
412 vrf_name: Vrf1
413 ranges:
414 - prefix: 1::1/64
415 nssa:
416 enabled: true
417 default_originate:
418 enabled: true
419 - area_id: 0.0.0.4
420 vrf_name: Vrf2
421 stub:
422 enabled: true
423 - area_id: 0.0.0.5
424 vrf_name: Vrf2
425 filter_list_in: pf1
426 filter_list_out: pf2
427
428 # After state
429 # -------------
430 # sonic(config-router-ospfv3)# show configuration
431 # !
432 # router ospfv3 vrf Vrf1
433 # area 0.0.0.1
434 # area 0.0.0.2 nssa no-summary
435 # area 0.0.0.3 range 1::1/64
436 # area 0.0.0.3 nssa default-information-originate
437 # sonic(config-router-ospfv3)# router ospfv3 vrf Vrf2
438 # sonic(config-router-ospfv3)# show configuration
439 # !
440 # router ospfv3 vrf Vrf2
441 # area 0.0.0.4 stub
442 # area 0.0.0.5 filter-list prefix pf1 in
443 # area 0.0.0.5 filter-list prefix pf2 out
444 # sonic(config-router-ospfv3)#
445
446
447 # Using "merged" state
448 # Before state:
449 # -------------
450 # sonic(config-router-ospfv3)# show configuration
451 # !
452 # router ospfv3 vrf Vrf1
453 # area 0.0.0.1 stub no-summary
454 # area 0.0.0.1 filter-list prefix pf1 in
455 # area 0.0.0.1 filter-list prefix pf2 out
456 # area 0.0.0.1 range 1::1/64 not-advertise
457 # area 0.0.0.1 range 1::2/64 advertise
458 # sonic(config-router-ospfv3)#
459
460 - name: "test merge all settings"
461 dellemc.enterprise_sonic.sonic_ospfv3_area:
462 state: merged
463 config:
464 - area_id: 0.0.0.1
465 vrf_name: Vrf1
466 filter_list_in: pf2
467 filter_list_out: pf1
468 ranges:
469 - prefix: 1::1/64
470 advertise: true
471 cost: 12
472 - prefix: 1::2/64
473 advertise: false
474 stub:
475 enabled: true
476 no_summary: false
477
478 # After state
479 # -------------
480 # sonic(config-router-ospfv3)# show configuration
481 # !
482 # router ospfv3 vrf Vrf1
483 # area 0.0.0.1 stub
484 # area 0.0.0.1 filter-list prefix pf2 in
485 # area 0.0.0.1 filter-list prefix pf1 out
486 # area 0.0.0.1 range 1::1/64 advertise cost 12
487 # area 0.0.0.1 range 1::2/64 not-advertise
488 # sonic(config-router-ospfv3)#
489
490
491 # Using "replaced" state
492 # Before state:
493 # -------------
494 # sonic# show running-configuration ospfv3
495 # !
496 # router ospfv3 vrf Vrf1
497 # area 0.0.0.1 nssa no-summary
498 # area 0.0.0.1 filter-list prefix pf1 in
499 # area 0.0.0.1 filter-list prefix pf2 out
500 # area 0.0.0.3 filter-list prefix pf1 in
501 # area 0.0.0.1 nssa
502 # area 0.0.0.4 stub no-summary
503 # area 0.0.0.1 nssa range 1::1/64
504 # area 0.0.0.1 nssa range 1::2/64 cost 20
505 # area 0.0.0.2 range 1::1/64 not-advertise
506 # area 0.0.0.2 range 1::2/64 advertise cost 4
507 # area 0.0.0.2 range 1::3/24 not-advertise
508 # router ospfv3
509 # area 0.0.0.1 nssa no-summary
510 # area 0.0.0.1 filter-list prefix pf1 in
511 # area 0.0.0.1 filter-list prefix pf2 out
512 # area 0.0.0.3 filter-list prefix pf1 in
513 # area 0.0.0.1 nssa
514 # area 0.0.0.4 stub no-summary
515 # area 0.0.0.1 nssa range 1::1/64
516 # area 0.0.0.1 nssa range 1::2/64 cost 20
517 # area 0.0.0.2 range 1::1/64 not-advertise
518 # area 0.0.0.2 range 1::2/64 advertise cost 4
519 # area 0.0.0.2 range 1::3/24 not-advertise
520 # sonic#
521
522 - name: "replace areas"
523 dellemc.enterprise_sonic.sonic_ospfv3_area:
524 state: replaced
525 config:
526 - area_id: 0.0.0.1
527 vrf_name: Vrf1
528 - area_id: 0.0.0.5
529 vrf_name: Vrf1
530 nssa:
531 enabled: true
532 default_originate:
533 enabled: true
534 metric: 10
535 metric_type: 1
536 ranges:
537 - prefix: "1::1/64"
538 cost: 15
539 - area_id: 0.0.0.4
540 vrf_name: Vrf1
541 stub:
542 no_summary: true
543 enabled: true
544
545 # After state
546 # -------------
547 # sonic# show running-configuration ospfv3
548 # !
549 # router ospfv3 vrf Vrf1
550 # area 0.0.0.1
551 # area 0.0.0.4 stub no-summary
552 # area 0.0.0.5 nssa nssa default-information-originate metric 10 metric-type 1
553 # area 0.0.0.5 nssa range 1::1/64 cost 15
554 # router ospfv3
555 # area 0.0.0.1 nssa no-summary
556 # area 0.0.0.1 filter-list prefix pf1 in
557 # area 0.0.0.1 filter-list prefix pf2 out
558 # area 0.0.0.3 filter-list prefix pf1 in
559 # area 0.0.0.1 nssa
560 # area 0.0.0.4 stub no-summary
561 # area 0.0.0.1 nssa range 1::1/64
562 # area 0.0.0.1 nssa range 1::2/64 cost 20
563 # area 0.0.0.2 range 1::1/64 not-advertise
564 # area 0.0.0.2 range 1::2/64 advertise cost 4
565 # area 0.0.0.2 range 1::3/24 not-advertise
566 # sonic#
567
568
569 # Using "overridden" state
570 # Before state:
571 # -------------
572 # sonic# show running-configuration ospfv3
573 # !
574 # router ospfv3 vrf Vrf1
575 # area 0.0.0.1 nssa no-summary
576 # area 0.0.0.1 filter-list prefix pf1 in
577 # area 0.0.0.1 filter-list prefix pf2 out
578 # area 0.0.0.3 filter-list prefix pf1 in
579 # area 0.0.0.1 nssa
580 # area 0.0.0.4 stub no-summary
581 # area 0.0.0.1 nssa range 1::1/64
582 # area 0.0.0.1 nssa range 1::2/64 cost 20
583 # area 0.0.0.2 range 1::1/64 not-advertise
584 # area 0.0.0.2 range 1::2/64 advertise cost 4
585 # area 0.0.0.2 range 1::3/24 not-advertise
586 # router ospfv3
587 # area 0.0.0.1 nssa no-summary
588 # area 0.0.0.1 filter-list prefix pf1 in
589 # area 0.0.0.1 filter-list prefix pf2 out
590 # area 0.0.0.3 filter-list prefix pf1 in
591 # area 0.0.0.1 nssa
592 # area 0.0.0.4 stub no-summary
593 # area 0.0.0.1 nssa range 1::1/64
594 # area 0.0.0.1 nssa range 1::2/64 cost 20
595 # area 0.0.0.2 range 1::1/64 not-advertise
596 # area 0.0.0.2 range 1::2/64 advertise cost 4
597 # area 0.0.0.2 range 1::3/24 not-advertise
598 # sonic#
599
600 - name: "override areas"
601 dellemc.enterprise_sonic.sonic_ospfv3_area:
602 state: overridden
603 config:
604 - area_id: 0.0.0.1
605 vrf_name: Vrf1
606 - area_id: 0.0.0.5
607 vrf_name: Vrf1
608 nssa:
609 enabled: true
610 default_originate:
611 enabled: true
612 metric: 10
613 metric_type: 1
614 ranges:
615 - prefix: "1::1/64"
616 cost: 15
617 - area_id: 0.0.0.4
618 vrf_name: Vrf1
619 stub:
620 no_summary: true
621 enabled: true
622
623 # After state
624 # -------------
625 # sonic# show running-configuration ospfv3
626 # !
627 # router ospfv3 vrf Vrf1
628 # area 0.0.0.1
629 # area 0.0.0.4 stub no-summary
630 # area 0.0.0.5 nssa nssa default-information-originate metric 10 metric-type 1
631 # area 0.0.0.5 nssa range 1::1/64 cost 15
632 # router ospfv3
633 # sonic#
634 """
635
636 RETURN = """
637 before:
638 description: The configuration prior to the module invocation.
639 returned: always
640 type: list
641 sample: >
642 The configuration returned will always be in the same format
643 of the parameters above.
644 after:
645 description: The configuration resulting from model invocation.
646 returned: when changed
647 type: list
648 sample: >
649 The configuration returned will always be in the same format
650 of the parameters above.
651 after_generated:
652 description: The generated (calculated) configuration that would be applied by module invocation.
653 returned: when C(check_mode)
654 type: list
655 sample: >
656 The configuration returned will always be in the same format
657 of the parameters above.
658 commands:
659 description: The set of commands pushed to the remote device.
660 returned: always
661 type: list
662 sample: [{"config": ..., "state": ...}, {"config": ..., "state": ...}]
663 """
664
665
666 from ansible.module_utils.basic import AnsibleModule
667 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ospfv3_area.ospfv3_area import Ospfv3_areaArgs
668 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ospfv3_area.ospfv3_area import Ospfv3_area
669
670
671 def main():
672 """
673 Main entry point for module execution
674
675 :returns: the result form module invocation
676 """
677 module = AnsibleModule(argument_spec=Ospfv3_areaArgs.argument_spec,
678 supports_check_mode=True)
679
680 result = Ospfv3_area(module).execute_module()
681 module.exit_json(**result)
682
683
684 if __name__ == '__main__':
685 main()