Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_vxlans.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_vxlans
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_vxlans
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: Manage VXLAN configuration on SONiC
22 description:
23 - This module provides configuration management of VXLAN for devices running SONiC
24 author: Niraimadaiselvam M (@niraimadaiselvamm)
25 options:
26 config:
27 description:
28 - A list of VXLAN configurations
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of the VXLAN
35 type: str
36 required: true
37 evpn_nvo:
38 description:
39 - EVPN NVO name
40 type: str
41 source_ip:
42 description:
43 - Source IP address of the VTEP
44 type: str
45 primary_ip:
46 description:
47 - The VTEP MCLAG primary IP address for this node
48 type: str
49 external_ip:
50 description:
51 - The VTEP MCLAG external IP address for this node
52 version_added: 2.5.0
53 type: str
54 qos_mode:
55 description:
56 - QoS mode to use for prioritizing the network traffic within a VXLAN tunnel
57 - Functional default is C(pipe)
58 version_added: 4.0.0
59 type: str
60 choices: [pipe, uniform]
61 dscp:
62 description:
63 - DSCP value of the VXLAN tunnel outer IP header, range 0-63
64 - Valid only when I(qos_mode=pipe)
65 - Functional default is 0
66 version_added: 4.0.0
67 type: int
68 vlan_map:
69 description:
70 - List of VNI VLAN map configuration
71 type: list
72 elements: dict
73 suboptions:
74 vni:
75 description:
76 - Specifies the VNI ID
77 type: int
78 required: true
79 vlan:
80 description:
81 - VLAN ID for VNI VLAN map
82 type: int
83 vrf_map:
84 description:
85 - List of VNI VRF map configuration
86 type: list
87 elements: dict
88 suboptions:
89 vni:
90 description: Specifies the VNI ID
91 type: int
92 required: true
93 vrf:
94 description:
95 - VRF name for VNI VRF map
96 type: str
97 suppress_vlan_neigh:
98 description:
99 - List of suppress VLAN neighbor configuration
100 version_added: 3.1.0
101 type: list
102 elements: dict
103 suboptions:
104 vlan_name:
105 description: Name of VLAN
106 type: str
107 state:
108 description:
109 - The state of the configuration after module completion
110 type: str
111 choices: [merged, deleted, replaced, overridden]
112 default: merged
113 """
114
115 EXAMPLES = """
116 # Using "deleted" state
117 #
118 # Before state:
119 # -------------
120 #
121 # sonic# show running-configuration vxlan
122 #
123 # interface vxlan vteptest1
124 # source-ip 1.1.1.1
125 # primary-ip 2.2.2.2
126 # map vni 101 vlan 11
127 # map vni 102 vlan 12
128 # map vni 101 vrf Vrfcheck1
129 # map vni 102 vrf Vrfcheck2
130 # suppress vlan-neigh vlan_name Vlan11
131 # suppress vlan-neigh vlan_name Vlan12
132 # !
133
134 - name: "Test vxlans deleted state 01"
135 dellemc.enterprise_sonic.sonic_vxlans:
136 config:
137 - name: vteptest1
138 source_ip: 1.1.1.1
139 vlan_map:
140 - vni: 101
141 vlan: 11
142 vrf_map:
143 - vni: 101
144 vrf: Vrfcheck1
145 suppress_vlan_neigh:
146 - vlan_name: Vlan11
147 - vlan_name: Vlan12
148 state: deleted
149
150 # After state:
151 # ------------
152 #
153 # sonic# show running-configuration vxlan
154 #
155 # interface vxlan vteptest1
156 # source-ip 1.1.1.1
157 # map vni 102 vlan 12
158 # map vni 102 vrf Vrfcheck2
159 # !
160
161
162 # Using "deleted" state
163 #
164 # Before state:
165 # -------------
166 #
167 # sonic# show running-configuration vxlan
168 #
169 # interface vxlan vteptest1
170 # source-ip 1.1.1.1
171 # qos-mode pipe dscp 14
172 # map vni 102 vlan 12
173 # map vni 102 vrf Vrfcheck2
174 # !
175
176 - name: "Test vxlans deleted state 02"
177 dellemc.enterprise_sonic.sonic_vxlans:
178 config:
179 state: deleted
180
181 # After state:
182 # ------------
183 #
184 # sonic# show running-configuration vxlan
185 #
186 # !
187
188
189 # Using "merged" state
190 #
191 # Before state:
192 # -------------
193 #
194 # sonic# show running-configuration vxlan
195 #
196 # !
197
198 - name: "Test vxlans merged state 01"
199 dellemc.enterprise_sonic.sonic_vxlans:
200 config:
201 - name: vteptest1
202 source_ip: 1.1.1.1
203 primary_ip: 2.2.2.2
204 evpn_nvo: nvo1
205 qos_mode: pipe
206 dscp: 14
207 vlan_map:
208 - vni: 101
209 vlan: 11
210 - vni: 102
211 vlan: 12
212 vrf_map:
213 - vni: 101
214 vrf: Vrfcheck1
215 - vni: 102
216 vrf: Vrfcheck2
217 suppress_vlan_neigh:
218 - vlan_name: Vlan11
219 - vlan_name: Vlan12
220 state: merged
221
222 # After state:
223 # ------------
224 #
225 # sonic# show running-configuration vxlan
226 #
227 # interface vxlan vteptest1
228 # source-ip 1.1.1.1
229 # primary-ip 2.2.2.2
230 # qos-mode pipe dscp 14
231 # map vni 101 vlan 11
232 # map vni 102 vlan 12
233 # map vni 101 vrf Vrfcheck1
234 # map vni 102 vrf Vrfcheck2
235 # suppress vlan-neigh vlan-name Vlan11
236 # suppress vlan-neigh vlan-name Vlan12
237 # !
238
239
240 # Using "overridden" state
241 #
242 # Before state:
243 # -------------
244 #
245 # sonic# show running-configuration vxlan
246 #
247 # interface vxlan vteptest1
248 # source-ip 1.1.1.1
249 # primary-ip 2.2.2.2
250 # map vni 101 vlan 11
251 # map vni 102 vlan 12
252 # map vni 101 vrf Vrfcheck1
253 # map vni 102 vrf Vrfcheck2
254 # !
255
256 - name: "Test vxlans overridden state 01"
257 dellemc.enterprise_sonic.sonic_vxlans:
258 config:
259 - name: vteptest2
260 source_ip: 3.3.3.3
261 primary_ip: 4.4.4.4
262 evpn_nvo: nvo2
263 vlan_map:
264 - vni: 101
265 vlan: 11
266 vrf_map:
267 - vni: 101
268 vrf: Vrfcheck1
269 state: overridden
270
271 # After state:
272 # ------------
273 #
274 # sonic# show running-configuration vxlan
275 #
276 # interface vxlan vteptest2
277 # source-ip 3.3.3.3
278 # primary-ip 4.4.4.4
279 # map vni 101 vlan 11
280 # map vni 101 vrf Vrfcheck1
281 # !
282
283
284 # Using "replaced" state
285 #
286 # Before state:
287 # -------------
288 #
289 # sonic# show running-configuration vxlan
290 #
291 # interface vxlan vteptest2
292 # source-ip 3.3.3.3
293 # primary-ip 4.4.4.4
294 # map vni 101 vlan 11
295 # map vni 101 vrf Vrfcheck
296 # !
297
298 - name: "Test vxlans replaced state 01"
299 dellemc.enterprise_sonic.sonic_vxlans:
300 config:
301 - name: vteptest2
302 source_ip: 5.5.5.5
303 vlan_map:
304 - vni: 101
305 vlan: 12
306 state: replaced
307
308 # After state:
309 # ------------
310 #
311 # sonic# show running-configuration vxlan
312 #
313 # interface vxlan vteptest2
314 # source-ip 5.5.5.5
315 # primary-ip 4.4.4.4
316 # map vni 101 vlan 12
317 # map vni 101 vrf Vrfcheck1
318 # !
319 """
320 RETURN = """
321 before:
322 description: The configuration prior to the module invocation.
323 returned: always
324 type: list
325 after:
326 description: The resulting configuration from module invocation.
327 returned: when changed
328 type: list
329 after_generated:
330 description: The generated configuration from module invocation.
331 returned: when C(check_mode)
332 type: list
333 commands:
334 description: The set of commands pushed to the remote device.
335 returned: always
336 type: list
337 sample: ['command 1', 'command 2', 'command 3']
338 """
339
340
341 from ansible.module_utils.basic import AnsibleModule
342 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.vxlans.vxlans import VxlansArgs
343 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.vxlans.vxlans import Vxlans
344
345
346 def main():
347 """
348 Main entry point for module execution
349
350 :returns: the result form module invocation
351 """
352 module = AnsibleModule(argument_spec=VxlansArgs.argument_spec,
353 supports_check_mode=True)
354
355 result = Vxlans(module).execute_module()
356 module.exit_json(**result)
357
358
359 if __name__ == '__main__':
360 main()