Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_vlan_mapping.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_vlan_mapping
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_vlan_mapping
17 author: "Cypher Miller (@Cypher-Miller)"
18 version_added: "2.1.0"
19 short_description: Configure vlan mappings on SONiC.
20 description:
21 - This module provides configuration management for vlan mappings on devices running SONiC.
22 - Vlan mappings only available on TD3 and TD4 devices.
23 - For TD4 devices must enable vlan mapping first (can enable in config-switch-resource).
24 options:
25 config:
26 description:
27 - Specifies the vlan mapping related configurations.
28 type: list
29 elements: dict
30 suboptions:
31 name:
32 description:
33 - Full name of the interface, i.e. Ethernet8, PortChannel2, Eth1/2.
34 required: true
35 type: str
36 mapping:
37 description:
38 - Define vlan mappings.
39 - dot1q_tunnel and vlan_translation are mutually exclusive.
40 type: list
41 elements: dict
42 suboptions:
43 service_vlan:
44 description:
45 - Configure service provider VLAN ID.
46 - VLAN ID range is 1-4094.
47 required: true
48 type: int
49 dot1q_tunnel:
50 description:
51 - Specify a vlan stacking.
52 type: dict
53 suboptions:
54 vlan_ids:
55 description:
56 - Configure customer VLAN IDs.
57 - It can pass ranges and/or multiple list entries.
58 - Individual VLAN ID or (-) separated range of VLAN IDs.
59 type: list
60 elements: str
61 priority:
62 description:
63 - Set priority level of the vlan stacking.
64 - Priority range is 0-7.
65 type: int
66 vlan_translation:
67 description:
68 - Specify a vlan translation.
69 version_added: '3.0.0'
70 type: dict
71 suboptions:
72 multi_tag:
73 description:
74 - Indicate if there are multiple tags.
75 type: bool
76 match_single_tags:
77 description:
78 - Configure single tagged vlan translation.
79 type: list
80 elements: dict
81 suboptions:
82 outer_vlan:
83 description:
84 - Configure outer customer VLAN ID.
85 - VLAN ID range is 1-4094.
86 required: true
87 type: int
88 priority:
89 description:
90 - Set priority level of the vlan translation.
91 - Priority range is 0-7.
92 type: int
93 match_double_tags:
94 description:
95 - Configure double tagged vlan translation.
96 type: list
97 elements: dict
98 suboptions:
99 inner_vlan:
100 description:
101 - Configure inner customer VLAN ID.
102 - VLAN ID range is 1-4094.
103 - Only available for double tagged translations.
104 required: true
105 type: int
106 outer_vlan:
107 description:
108 - Configure outer customer VLAN ID.
109 - VLAN ID range is 1-4094.
110 required: true
111 type: int
112 priority:
113 description:
114 - Set priority level of the vlan translation.
115 - Priority range is 0-7.
116 type: int
117 state:
118 description:
119 - Specifies the operation to be performed on the vlan mappings configured on the device.
120 - In case of merged, the input configuration will be merged with the existing vlan mappings on the device.
121 - In case of deleted, the existing vlan mapping configuration will be removed from the device.
122 - In case of overridden, all existing vlan mappings will be deleted and the specified input configuration will be add.
123 - In case of replaced, the existing vlan mappings on the device will be replaced by the configuration for each vlan mapping.
124 type: str
125 default: merged
126 choices:
127 - merged
128 - deleted
129 - replaced
130 - overridden
131 """
132
133 EXAMPLES = """
134 #
135 # Using "deleted" state
136 #
137 # Before state:
138 # -------------
139 #
140 # sonic# show interface vlan-mappings dot1q-tunnel
141 # --------------------------------------------------------------------
142 # Name Vlan dot1q-tunnel Vlan Priority
143 # --------------------------------------------------------------------
144 # Ethernet4 360-366,392 2755 3
145 #
146 # - name: Delete dot1q_tunnel configuration
147 # sonic_vlan_mapping:
148 # config:
149 # - name: Ethernet4
150 # mapping:
151 # - service_vlan: 2755
152 # dot1q_tunnel:
153 # vlan_ids:
154 # - 392
155 # - 360-362
156 # state: deleted
157 #
158 # After state:
159 # ------------
160 #
161 # sonic# show interface vlan-mappings dot1q-tunnel
162 # --------------------------------------------------------------------
163 # Name Vlan dot1q-tunnel Vlan Priority
164 # --------------------------------------------------------------------
165 # Ethernet4 363-366 2755 3
166 #
167 # Using "deleted" state
168 #
169 # Before state:
170 # -------------
171 #
172 # sonic# show interface vlan-mappings
173 # Flags: M - Multi-tag
174 # ---------------------------------------------------------
175 # Name Outer Inner Mapped Vlan Priority Flags
176 # ---------------------------------------------------------
177 # Ethernet8 610 600 2567 - -
178 # Ethernet8 611 601 2567 1 -
179 # Ethernet8 612 602 2567 2 -
180 #
181 # - name: Delete vlan translation configuration
182 # sonic_vlan_mapping:
183 # config:
184 # - name: Ethernet8
185 # mapping:
186 # - service_vlan: 2567
187 # vlan_translation:
188 # match_double_tags:
189 # - inner_vlan: 602
190 # outer_vlan: 612
191 # priority: 2
192 # state: deleted
193 #
194 # After state:
195 # ------------
196 #
197 # sonic# show interface vlan-mappings
198 # Flags: M - Multi-tag
199 # ---------------------------------------------------------
200 # Name Outer Inner Mapped Vlan Priority Flags
201 # ---------------------------------------------------------
202 # Ethernet8 610 600 2567 - -
203 # Ethernet8 611 601 2567 1 -
204 #
205 #
206 # Using "merged" state
207 #
208 # Before state:
209 # -------------
210 #
211 # sonic# show interface vlan-mappings dot1q-tunnel
212 #
213 # - name: Merge dot1q_tunnel configuration
214 # sonic_vlan_mapping:
215 # config:
216 # - name: Ethernet4
217 # mapping:
218 # - service_vlan: 2755
219 # dot1q_tunnel:
220 # vlan_ids:
221 # - 392
222 # - 360-366
223 # priority: 3
224 # state: merged
225 #
226 # After state:
227 # ------------
228 #
229 # sonic# show interface vlan-mappings dot1q-tunnel
230 # --------------------------------------------------------------------
231 # Name Vlan dot1q-tunnel Vlan Priority
232 # --------------------------------------------------------------------
233 # Ethernet4 360-366,392 2755 3
234 #
235 # Using "merged" state
236 #
237 # Before state:
238 # -------------
239 #
240 # sonic# show interface vlan-mappings dot1q-tunnel
241 # --------------------------------------------------------------------
242 # Name Vlan dot1q-tunnel Vlan Priority
243 # --------------------------------------------------------------------
244 # Ethernet4 360-366,392 2755 3
245 #
246 # - name: Merge vlan translation configuration
247 # sonic_vlan_mapping:
248 # config:
249 # - name: Ethernet8
250 # mapping:
251 # - service_vlan: 2567
252 # vlan_translation:
253 # match_double_tags:
254 # - inner_vlan: 600
255 # outer_vlan: 610
256 # - inner_vlan: 601
257 # outer_vlan: 611
258 # priority: 1
259 # - inner_vlan: 602
260 # outer_vlan: 612
261 # priority: 2
262 # state: merged
263 #
264 # After state:
265 # ------------
266 #
267 # sonic# show interface vlan-mappings
268 # Flags: M - Multi-tag
269 # ---------------------------------------------------------
270 # Name Outer Inner Mapped Vlan Priority Flags
271 # ---------------------------------------------------------
272 # Ethernet8 610 600 2567 - -
273 # Ethernet8 611 601 2567 1 -
274 # Ethernet8 612 602 2567 2 -
275 #
276 # sonic# show interface vlan-mappings dot1q-tunnel
277 # --------------------------------------------------------------------
278 # Name Vlan dot1q-tunnel Vlan Priority
279 # --------------------------------------------------------------------
280 # Ethernet4 360-366,392 2755 3
281 #
282 #
283 # Using "replaced" state
284 #
285 # Before state:
286 # -------------
287 #
288 # sonic# show interface vlan-mappings dot1q-tunnel
289 # --------------------------------------------------------------------
290 # Name Vlan dot1q-tunnel Vlan Priority
291 # --------------------------------------------------------------------
292 # Ethernet4 360-366,392 2755 3
293 #
294 # - name: Replace dot1q_tunnel configuration
295 # sonic_vlan_mapping:
296 # config:
297 # - name: Ethernet4
298 # mapping:
299 # - service_vlan: 2755
300 # dot1q_tunnel:
301 # vlan_ids:
302 # - 660-666
303 # priority: 6
304 # state: replaced
305 #
306 # After state:
307 # ------------
308 #
309 # sonic# show interface vlan-mappings dot1q-tunnel
310 # --------------------------------------------------------------------
311 # Name Vlan dot1q-tunnel Vlan Priority
312 # --------------------------------------------------------------------
313 # Ethernet4 660-666 2755 6
314 #
315 # Using "overridden" state
316 #
317 # Before state:
318 # -------------
319 #
320 # sonic# show interface vlan-mappings
321 # Flags: M - Multi-tag
322 # ---------------------------------------------------------
323 # Name Outer Inner Mapped Vlan Priority Flags
324 # ---------------------------------------------------------
325 # Ethernet8 610 600 2567 - -
326 # Ethernet8 611 601 2567 1 -
327 # Ethernet8 612 602 2567 2 -
328 #
329 # - name: Override vlan translation configuration
330 # sonic_vlan_mapping:
331 # config:
332 # - name: Ethernet8
333 # mapping:
334 # - service_vlan: 2567
335 # vlan_translation:
336 # match_double_tags:
337 # - inner_vlan: 701
338 # outer_vlan: 711
339 # priority: 5
340 # - inner_vlan: 702
341 # outer_vlan: 712
342 # priority: 6
343 # state: overridden
344 #
345 # After state:
346 # ------------
347 #
348 # sonic# show interface vlan-mappings
349 # Flags: M - Multi-tag
350 # ---------------------------------------------------------
351 # Name Outer Inner Mapped Vlan Priority Flags
352 # ---------------------------------------------------------
353 # Ethernet8 711 701 2567 5 -
354 # Ethernet8 712 702 2567 6 -
355 #
356 """
357
358 RETURN = """
359 before:
360 description: The configuration prior to the module invocation.
361 returned: always
362 type: list
363 sample: >
364 The configuration returned will always be in the same format
365 as the parameters above.
366 after:
367 description: The resulting configuration module invocation.
368 returned: when changed
369 type: list
370 sample: >
371 The configuration returned will always be in the same format
372 as the parameters above.
373 commands:
374 description: The set of commands pushed to the remote device.
375 returned: always
376 type: list
377 sample: ['command 1', 'command 2', 'command 3']
378 """
379
380
381 from ansible.module_utils.basic import AnsibleModule
382 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.vlan_mapping.vlan_mapping import Vlan_mappingArgs
383 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.vlan_mapping.vlan_mapping import Vlan_mapping
384
385
386 def main():
387 """
388 Main entry point for module execution
389
390 :returns: the result form module invocation
391 """
392 module = AnsibleModule(argument_spec=Vlan_mappingArgs.argument_spec,
393 supports_check_mode=True)
394
395 result = Vlan_mapping(module).execute_module()
396 module.exit_json(**result)
397
398
399 if __name__ == '__main__':
400 main()