Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_vlans.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_vlans
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_vlans
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 author: Mohamed Javeed (@javeedf)
22 short_description: Manage VLAN and its parameters
23 description:
24 - This module provides configuration management of VLANs parameters
25 on devices running Enterprise SONiC Distribution by Dell Technologies.
26 options:
27 config:
28 description: A dictionary of VLAN options.
29 type: list
30 elements: dict
31 suboptions:
32 vlan_id:
33 description:
34 - ID of the VLAN
35 - Range is 1 to 4094
36 type: int
37 required: true
38 description:
39 description:
40 - Description about the VLAN.
41 type: str
42 autostate:
43 version_added: 3.1.0
44 description:
45 - Enable or disable autostate functionality for the VLAN interface.
46 - Default value for this field if not configured yet will be "enable" which is equivalent to true.
47 type: bool
48
49 state:
50 description:
51 - The state that the configuration should be left in.
52 type: str
53 choices:
54 - merged
55 - replaced
56 - overridden
57 - deleted
58 default: merged
59 """
60
61 EXAMPLES = """
62 # Using "merged" state
63
64 # Before state:
65 # -------------
66 #
67 # sonic# show Vlan
68 # Q: A - Access (Untagged), T - Tagged
69 # NUM Status Q Ports
70 # 10 Inactive
71 # 30 Inactive
72 #
73 # sonic#
74 #
75
76
77 - name: Merges given VLAN attributes with the device configuration
78 dellemc.enterprise_sonic.sonic_vlans:
79 config:
80 - vlan_id: 10
81 description: "Internal"
82 state: merged
83
84 # After state:
85 # ------------
86 #
87 # sonic# show Vlan
88 # Q: A - Access (Untagged), T - Tagged
89 # NUM Status Q Ports
90 # 10 Inactive
91 # 30 Inactive
92 #
93 # sonic#
94 #
95 # sonic# show interface Vlan 10
96 # Description: Internal
97 # Vlan10 is up
98 # Mode of IPV4 address assignment: not-set
99 # Mode of IPV6 address assignment: not-set
100 # IP MTU 6000 bytes
101 # sonic#
102 #
103
104 # Using "replaced" state
105
106 # Before state:
107 # -------------
108 #
109 # sonic# show Vlan
110 # Q: A - Access (Untagged), T - Tagged
111 # NUM Status Q Ports
112 # 10 Inactive
113 # 30 Inactive
114 #
115 # sonic#
116
117 - name: Replace all attributes of specified VLANs with provided configuration
118 dellemc.enterprise_sonic.sonic_vlans:
119 config:
120 - vlan_id: 10
121 state: replaced
122
123 # After state:
124 # ------------
125 #
126 # sonic# show Vlan
127 # Q: A - Access (Untagged), T - Tagged
128 # NUM Status Q Ports
129 # 10 Inactive
130 # 30 Inactive
131 #
132 # sonic#
133
134 # Using "overridden" state
135
136 # Before state:
137 # -------------
138 #
139 # sonic# show Vlan
140 # Q: A - Access (Untagged), T - Tagged
141 # NUM Status Q Ports
142 # 10 Inactive
143 # 30 Inactive
144 #
145 # sonic#
146
147 - name: Override device configuration of all VLANs with provided configuration
148 dellemc.enterprise_sonic.sonic_vlans:
149 config:
150 - vlan_id: 10
151 state: overridden
152
153 # After state:
154 # ------------
155 #
156 # sonic# show Vlan
157 # Q: A - Access (Untagged), T - Tagged
158 # NUM Status Q Ports
159 # 10 Inactive
160 #
161 # sonic#
162
163 # Using "deleted" state
164
165 # Before state:
166 # -------------
167 #
168 # sonic# show interface Vlan 70
169 # Description: Internal
170 # Vlan70 is up
171 # Mode of IPV4 address assignment: not-set
172 # Mode of IPV6 address assignment: not-set
173 # IP MTU 6000 bytes
174
175 - name: Deletes attributes of the given VLANs
176 dellemc.enterprise_sonic.sonic_vlans:
177 config:
178 - vlan_id: 70
179 description: "Internal"
180 state: deleted
181
182 # After state:
183 # ------------
184 #
185 # sonic# show interface Vlan 70
186 # Vlan70 is up
187 # Mode of IPV4 address assignment: not-set
188 # Mode of IPV6 address assignment: not-set
189 # IP MTU 6000 bytes
190
191 # Before state:
192 # -------------
193 #
194 # sonic# show Vlan
195 # Q: A - Access (Untagged), T - Tagged
196 # NUM Status Q Ports
197 # 10 Inactive
198 # 20 Inactive
199 #
200 # sonic#
201
202 - name: Deletes attributes of the given VLANs
203 dellemc.enterprise_sonic.sonic_vlans:
204 config:
205 - vlan_id: 20
206 state: deleted
207
208 # After state:
209 # ------------
210 #
211 # sonic# show Vlan
212 # Q: A - Access (Untagged), T - Tagged
213 # NUM Status Q Ports
214 # 10 Inactive
215 #
216 # sonic#
217
218
219 # Using "deleted" state
220
221 # Before state:
222 # -------------
223 #
224 # sonic# show Vlan
225 # Q: A - Access (Untagged), T - Tagged
226 # NUM Status Q Ports
227 # 10 Inactive
228 # 20 Inactive
229 # 30 Inactive
230 #
231 # sonic#
232
233 - name: Deletes all the VLANs on the switch
234 dellemc.enterprise_sonic.sonic_vlans:
235 config:
236 state: deleted
237
238 # After state:
239 # ------------
240 #
241 # sonic# show Vlan
242 # Q: A - Access (Untagged), T - Tagged
243 # NUM Status Q Ports
244 #
245 # sonic#
246 """
247
248 RETURN = """
249 before:
250 description: The configuration prior to the module invocation.
251 returned: always
252 type: list
253 sample: >
254 The configuration that is returned is always in the same format
255 as the parameters above.
256 after:
257 description: The resulting configuration module invocation.
258 returned: when changed
259 type: list
260 sample: >
261 The configuration returned is always in the same format
262 as the parameters above.
263 commands:
264 description: The set of commands pushed to the remote device.
265 returned: always
266 type: list
267 sample: ['command 1', 'command 2', 'command 3']
268 """
269
270
271 from ansible.module_utils.basic import AnsibleModule
272 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.vlans.vlans import VlansArgs
273 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.vlans.vlans import Vlans
274
275
276 def main():
277 """
278 Main entry point for module execution
279
280 :returns: the result form module invocation
281 """
282 module = AnsibleModule(argument_spec=VlansArgs.argument_spec,
283 supports_check_mode=True)
284
285 result = Vlans(module).execute_module()
286 module.exit_json(**result)
287
288
289 if __name__ == '__main__':
290 main()