Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_vrrp.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_vrrp
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_vrrp
18 author: "Santhosh Kumar T(@santhosh-kt)"
19 version_added: "2.5.0"
20 short_description: Configure VRRP protocol settings on SONiC.
21 description:
22 - This module provides configuration management of VRRP protocol settings on devices running SONiC
23 - Configure interface IP address before configuring VRRP
24 - Configure interface VRF forwarding before configuring VRRP in a VRF
25 options:
26 config:
27 description:
28 - Specifies the VRRP related configuration.
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Full name of the Layer 3 interface, i.e. Eth1/1.
35 required: true
36 type: str
37 group:
38 description:
39 - Defining the VRRP/VRRP6 group
40 type: list
41 elements: dict
42 suboptions:
43 virtual_router_id:
44 description:
45 - VRRP ID (1 to 255)
46 type: int
47 required: true
48 afi:
49 description:
50 - VRRP configurations to be set for the interface mentioned in types(VRRP/VRRP6).
51 type: str
52 required: true
53 choices:
54 - ipv4
55 - ipv6
56 virtual_address:
57 description:
58 - Configure virtual IP Address.
59 type: list
60 elements: dict
61 suboptions:
62 address:
63 description:
64 - List of IP addresses to be set.
65 type: str
66 advertisement_interval:
67 description:
68 - Configure advertisement interval (1 to 254)
69 type: int
70 preempt:
71 description:
72 - Enable preempt
73 type: bool
74 preempt_delay:
75 description:
76 - Configure preempt delay interval (0 to 1000)
77 type: int
78 version_added: 4.0.0
79 priority:
80 description:
81 - Priority for MASTER election (1 to 254)
82 type: int
83 track_interface:
84 description:
85 - Configure track interface for priority change.
86 - I(interface) and I(priority_increment) are required together.
87 type: list
88 elements: dict
89 suboptions:
90 interface:
91 description:
92 - Full name of the Layer 3 interface, i.e. Eth1/1.
93 type: str
94 required: true
95 priority_increment:
96 description:
97 - Weight for changing priority (1 to 254)
98 type: int
99 use_v2_checksum:
100 description:
101 - Enable checksum compatibility with VRRPv2 (Not supported for IPv6).
102 type: bool
103 version:
104 description:
105 - Configure VRRP Version 2 or 3 (Not supported for IPv6).
106 type: int
107 choices:
108 - 2
109 - 3
110 state:
111 description:
112 - Specifies the operation to be performed on the VRRP process configured on the device.
113 - In case of merged, the input configuration will be merged with the existing VRRP configuration on the device.
114 - In case of deleted, the existing VRRP configuration will be removed from the device.
115 - In case of overridden, all existing VRRP configuration will be deleted and the specified input configuration will be installed.
116 - In case of replaced, the existing VRRP configuration on the device will be replaced by the configuration in the
117 playbook for each VRRP interface/group configured by the playbook.
118 default: merged
119 type: str
120 choices: ['merged', 'deleted','replaced', 'overridden']
121 """
122
123 EXAMPLES = """
124 # Using "deleted" state
125 #
126 # Before state:
127 # -------------
128 #
129 # sonic# show running-configuration interface
130 # !
131 # interface Eth1/1
132 # mtu 9100
133 # speed 400000
134 # fec RS
135 # no shutdown
136 # ip address 81.1.1.1/24
137 # ipv6 address 81::1/24
138 # !
139 # vrrp 1 address-family ipv4
140 # preempt
141 # vip 81.1.1.3
142 # vip 81.1.1.4
143 # !
144 # vrrp 10 address-family ipv6
145 # priority 10
146 # preempt-delay 4
147 # advertisement-interval 4
148 # vip 81::3
149 # vip 81::4
150 # !
151 # interface Eth1/3
152 # mtu 9100
153 # speed 400000
154 # fec RS
155 # no shutdown
156 # ip address 61.1.1.1/24
157 # !
158 # vrrp 5 address-family ipv4
159 # priority 20
160 # vip 61.1.1.3
161 # !
162 # vrrp 15 address-family ipv4
163 # priority 20
164 # preempt
165 # vip 61.1.1.4
166 # !
167 - name: Delete VRRP and VRRP6 relay configurations
168 sonic_vrrp:
169 config:
170 - name: 'Eth1/1'
171 group:
172 - virtual_router_id: 1
173 afi: ipv4
174 virtual_address:
175 - address: 81.1.1.4
176 preempt: true
177 - virtual_router_id: 10
178 afi: ipv6
179 advertisement_interval: 4
180 priority: 10
181 preempt_delay: 4
182 - name: 'Eth1/3'
183 group:
184 - virtual_router_id: 5
185 afi: ipv4
186 virtual_address:
187 - address: 61.1.1.3
188 priority: 20
189 - virtual_router_id: 15
190 afi: ipv4
191 state: deleted
192 # After state:
193 # ------------
194 #
195 # sonic# show running-configuration interface
196 # !
197 # interface Eth1/1
198 # mtu 9100
199 # speed 400000
200 # fec RS
201 # no shutdown
202 # ip address 81.1.1.1/24
203 # ipv6 address 81::1/24
204 # !
205 # vrrp 1 address-family ipv4
206 # vip 81.1.1.3
207 # !
208 # vrrp 10 address-family ipv6
209 # vip 81::3
210 # vip 81::4
211 # !
212 # interface Eth1/3
213 # mtu 9100
214 # speed 400000
215 # fec RS
216 # no shutdown
217 # ip address 61.1.1.1/24
218 # !
219
220 # Using "merged" state
221 #
222 # Before state:
223 # -------------
224 #
225 # sonic# show running-configuration interface
226 # !
227 # interface Eth1/1
228 # mtu 9100
229 # speed 400000
230 # fec RS
231 # no shutdown
232 # ip address 81.1.1.1/24
233 # ipv6 address 81::1/24
234 # !
235 # interface Eth1/3
236 # mtu 9100
237 # speed 400000
238 # fec RS
239 # no shutdown
240 # ip address 61.1.1.1/24
241 # !
242 - name: Add VRRP and VRRP6 configurations
243 sonic_vrrp:
244 config:
245 - name: 'Eth1/1'
246 group:
247 - virtual_router_id: 1
248 afi: ipv4
249 virtual_address:
250 - address: 81.1.1.3
251 - address: 81.1.1.4
252 preempt: true
253 - virtual_router_id: 10
254 afi: ipv6
255 virtual_address:
256 - address: 81::3
257 - address: 81::4
258 advertisement_interval: 4
259 priority: 10
260 preempt_delay: 4
261 - name: 'Eth1/3'
262 group:
263 - virtual_router_id: 5
264 afi: ipv4
265 virtual_address:
266 - address: 61.1.1.3
267 priority: 20
268 - virtual_router_id: 15
269 afi: ipv4
270 virtual_address:
271 - address: 61.1.1.4
272 preempt: true
273 priority: 20
274 state: merged
275 # After state:
276 # ------------
277 #
278 # sonic# show running-configuration interface
279 # !
280 # interface Eth1/1
281 # mtu 9100
282 # speed 400000
283 # fec RS
284 # no shutdown
285 # ip address 81.1.1.1/24
286 # ipv6 address 81::1/24
287 # !
288 # vrrp 1 address-family ipv4
289 # preempt
290 # vip 81.1.1.3
291 # vip 81.1.1.4
292 # !
293 # vrrp 10 address-family ipv6
294 # priority 10
295 # preempt-delay 4
296 # advertisement-interval 4
297 # vip 81::3
298 # vip 81::4
299 # !
300 # interface Eth1/3
301 # mtu 9100
302 # speed 400000
303 # fec RS
304 # no shutdown
305 # ip address 61.1.1.1/24
306 # !
307 # vrrp 5 address-family ipv4
308 # priority 20
309 # vip 61.1.1.3
310 # !
311 # vrrp 15 address-family ipv4
312 # priority 20
313 # preempt
314 # vip 61.1.1.4
315 # !
316
317 # Using "replaced" state
318 #
319 # Before state:
320 # -------------
321 #
322 # sonic# show running-configuration interface
323 # !
324 # interface Eth1/1
325 # mtu 9100
326 # speed 400000
327 # fec RS
328 # no shutdown
329 # ip address 81.1.1.1/24
330 # ipv6 address 81::1/24
331 # !
332 # vrrp 1 address-family ipv4
333 # preempt
334 # vip 81.1.1.3
335 # vip 81.1.1.4
336 # !
337 # vrrp 10 address-family ipv6
338 # priority 10
339 # preempt-delay 4
340 # advertisement-interval 4
341 # vip 81::3
342 # vip 81::4
343 # !
344 # interface Eth1/3
345 # mtu 9100
346 # speed 400000
347 # fec RS
348 # no shutdown
349 # ip address 61.1.1.1/24
350 # !
351 # vrrp 5 address-family ipv4
352 # priority 20
353 # vip 61.1.1.3
354 # !
355 # vrrp 15 address-family ipv4
356 # priority 20
357 # preempt
358 # vip 61.1.1.4
359 # !
360 - name: Replace VRRP and VRRP6 relay configurations
361 sonic_vrrp:
362 config:
363 - name: 'Eth1/1'
364 group:
365 - virtual_router_id: 10
366 afi: ipv6
367 priority: 20
368 - name: 'Eth1/3'
369 group:
370 - virtual_router_id: 5
371 afi: ipv4
372 virtual_address:
373 - address: 61.1.1.5
374 preempt: false
375 track_interface:
376 - interface: Eth1/1
377 priority_increment: 10
378 state: replaced
379 # After state:
380 # ------------
381 #
382 # sonic# show running-configuration interface
383 # !
384 # interface Eth1/1
385 # mtu 9100
386 # speed 400000
387 # fec RS
388 # no shutdown
389 # ip address 81.1.1.1/24
390 # ipv6 address 81::1/24
391 # !
392 # vrrp 1 address-family ipv4
393 # vip 81.1.1.3
394 # vip 81.1.1.4
395 # !
396 # vrrp 10 address-family ipv6
397 # priority 20
398 # !
399 # interface Eth1/3
400 # mtu 9100
401 # speed 400000
402 # fec RS
403 # no shutdown
404 # ip address 61.1.1.1/24
405 # !
406 # vrrp 5 address-family ipv4
407 # no preempt
408 # vip 61.1.1.5
409 # track-interface Eth1/1 weight 10
410 # !
411 # vrrp 15 address-family ipv4
412 # priority 20
413 # preempt
414 # vip 61.1.1.4
415 # !
416
417 # Using "overridden" state
418 #
419 # Before state:
420 # -------------
421 #
422 # sonic# show running-configuration interface
423 # !
424 # interface Eth1/1
425 # mtu 9100
426 # speed 400000
427 # fec RS
428 # no shutdown
429 # ip address 81.1.1.1/24
430 # ipv6 address 81::1/24
431 # !
432 # vrrp 1 address-family ipv4
433 # preempt
434 # vip 81.1.1.3
435 # vip 81.1.1.4
436 # !
437 # vrrp 10 address-family ipv6
438 # priority 10
439 # advertisement-interval 4
440 # preempt-delay 4
441 # vip 81::3
442 # vip 81::4
443 # !
444 # interface Eth1/3
445 # mtu 9100
446 # speed 400000
447 # fec RS
448 # no shutdown
449 # ip address 61.1.1.1/24
450 # !
451 # vrrp 5 address-family ipv4
452 # priority 20
453 # vip 61.1.1.3
454 # !
455 # vrrp 15 address-family ipv4
456 # priority 20
457 # preempt
458 # vip 61.1.1.4
459 # !
460 - name: Overwrite the VRRP and VRRP6 relay configurations
461 sonic_vrrp:
462 config:
463 - name: 'Eth1/1'
464 group:
465 - virtual_router_id: 15
466 afi: ipv4
467 virtual_address:
468 - address: 81.1.1.15
469 preempt: false
470 - name: 'Eth1/3'
471 group:
472 - virtual_router_id: 5
473 afi: ipv4
474 - virtual_router_id: 15
475 afi: ipv4
476 virtual_address:
477 - address: 61.1.1.5
478 state: overridden
479 # After state:
480 # ------------
481 #
482 # sonic# show running-configuration interface
483 # !
484 # interface Eth1/1
485 # mtu 9100
486 # speed 400000
487 # fec RS
488 # no shutdown
489 # ip address 81.1.1.1/24
490 # ipv6 address 81::1/24
491 # !
492 # vrrp 15 address-family ipv4
493 # no preempt
494 # vip 81.1.1.15
495 # !
496 # interface Eth1/3
497 # mtu 9100
498 # speed 400000
499 # fec RS
500 # no shutdown
501 # ip address 61.1.1.1/24
502 # !
503 # vrrp 5 address-family ipv4
504 # !
505 # vrrp 15 address-family ipv4
506 # vip 61.1.1.5
507 # !
508 """
509
510 RETURN = """
511 before:
512 description: The configuration prior to the model invocation.
513 returned: always
514 type: list
515 sample: >
516 The configuration returned will always be in the same format
517 of the parameters above.
518 after:
519 description: The resulting configuration model invocation.
520 returned: when changed
521 type: list
522 sample: >
523 The configuration returned will always be in the same format
524 of the parameters above.
525 after_generated:
526 description: The generated configuration model invocation.
527 returned: when C(check_mode)
528 type: list
529 sample: >
530 The configuration returned will always be in the same format
531 of the parameters above.
532 commands:
533 description: The set of commands pushed to the remote device.
534 returned: always
535 type: list
536 sample: ['command 1', 'command 2', 'command 3']
537 """
538
539
540 from ansible.module_utils.basic import AnsibleModule
541 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.vrrp.vrrp import VrrpArgs
542 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.vrrp.vrrp import Vrrp
543
544
545 def main():
546 """
547 Main entry point for module execution
548 :returns: the result form module invocation
549 """
550 module = AnsibleModule(argument_spec=VrrpArgs.argument_spec,
551 supports_check_mode=True)
552
553 result = Vrrp(module).execute_module()
554 module.exit_json(**result)
555
556
557 if __name__ == '__main__':
558 main()