Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_port_group.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_port_group
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_port_group
18 version_added: 2.1.0
19 notes:
20 - Supports C(check_mode).
21 short_description: Manages port group configuration on SONiC.
22 description:
23 - This module provides configuration management of port group for devices running SONiC.
24 author: 'M. Zhang (@mingjunzhang2019)'
25 options:
26 config:
27 description:
28 - A list of port group configurations.
29 type: list
30 elements: dict
31 suboptions:
32 id:
33 type: str
34 description:
35 - The index of the port group.
36 required: true
37 speed:
38 description:
39 - Speed for the port group.
40 - This configures the speed for all the memebr ports of the prot group.
41 - Supported speeds are dependent on the type of switch.
42 type: str
43 choices:
44 - SPEED_10MB
45 - SPEED_100MB
46 - SPEED_1GB
47 - SPEED_2500MB
48 - SPEED_5GB
49 - SPEED_10GB
50 - SPEED_20GB
51 - SPEED_25GB
52 - SPEED_40GB
53 - SPEED_50GB
54 - SPEED_100GB
55 - SPEED_200GB
56 - SPEED_400GB
57 state:
58 description:
59 - The state of the configuration after module completion.
60 type: str
61 choices:
62 - merged
63 - replaced
64 - overridden
65 - deleted
66 default: merged
67 """
68
69 EXAMPLES = """
70 #
71 # Using "deleted" state
72 #
73 # Before state:
74 # -------------
75 #
76 # sonic# show port-group
77 # -------------------------------------------------------------------------------------
78 # Port-group Interface range Valid speeds Default Speed Current Speed
79 # -------------------------------------------------------------------------------------
80 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 10G
81 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
82 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
83 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
84 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
85 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
86 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
87 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
88 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
89 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
90 #
91 - name: Configure port group speed
92 sonic_port_group:
93 config:
94 - id: 1
95 - id: 10
96 state: deleted
97 #
98 #
99 # After state:
100 # ------------
101 #
102 # sonic# show port-group
103 # -------------------------------------------------------------------------------------
104 # Port-group Interface range Valid speeds Default Speed Current Speed
105 # -------------------------------------------------------------------------------------
106 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 25G
107 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
108 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
109 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
110 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
111 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
112 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
113 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
114 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
115 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
116 #
117 # Using "deleted" state
118 #
119 # Before state:
120 # -------------
121 #
122 # sonic# show port-group
123 # -------------------------------------------------------------------------------------
124 # Port-group Interface range Valid speeds Default Speed Current Speed
125 # -------------------------------------------------------------------------------------
126 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 10G
127 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
128 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
129 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
130 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
131 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
132 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
133 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
134 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
135 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
136 #
137 - name: Configure port group speed
138 sonic_port_group:
139 config:
140 - id:
141 state: deleted
142 #
143 #
144 # After state:
145 # ------------
146 #
147 # sonic# show port-group
148 # -------------------------------------------------------------------------------------
149 # Port-group Interface range Valid speeds Default Speed Current Speed
150 # -------------------------------------------------------------------------------------
151 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 25G
152 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
153 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
154 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
155 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
156 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
157 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
158 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
159 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 25G
160 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
161 #
162 # Using "merged" state
163 #
164 # Before state:
165 # -------------
166 #
167 # sonic# show port-group
168 # -------------------------------------------------------------------------------------
169 # Port-group Interface range Valid speeds Default Speed Current Speed
170 # -------------------------------------------------------------------------------------
171 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 25G
172 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
173 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
174 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
175 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
176 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
177 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
178 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
179 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 25G
180 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
181 #
182 - name: Configure port group speed
183 sonic_port_group:
184 config:
185 - id: 1
186 speed: SPEED_10GB
187 - id: 9
188 speed: SPEED_10GB
189 state: merged
190 #
191 #
192 # After state:
193 # ------------
194 #
195 # sonic# show port-group
196 # -------------------------------------------------------------------------------------
197 # Port-group Interface range Valid speeds Default Speed Current Speed
198 # -------------------------------------------------------------------------------------
199 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 10G
200 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
201 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
202 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
203 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
204 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
205 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
206 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
207 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
208 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
209 #
210 # Using "replaced" state
211 #
212 # Before state:
213 # -------------
214 #
215 # sonic# show port-group
216 # -------------------------------------------------------------------------------------
217 # Port-group Interface range Valid speeds Default Speed Current Speed
218 # -------------------------------------------------------------------------------------
219 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 25G
220 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
221 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
222 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 10G
223 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
224 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
225 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
226 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
227 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 25G
228 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
229 #
230 - name: Replace port group speed
231 sonic_port_group:
232 config:
233 - id: 1
234 speed: SPEED_10GB
235 - id: 9
236 speed: SPEED_10GB
237 state: replaced
238 #
239 # After state:
240 # ------------
241 #
242 # sonic# show port-group
243 # -------------------------------------------------------------------------------------
244 # Port-group Interface range Valid speeds Default Speed Current Speed
245 # -------------------------------------------------------------------------------------
246 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 10G
247 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
248 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
249 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 10G
250 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
251 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
252 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
253 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
254 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
255 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
256 #
257 # Using "overridden" state
258 #
259 # Before state:
260 # -------------
261 #
262 # sonic# show port-group
263 # -------------------------------------------------------------------------------------
264 # Port-group Interface range Valid speeds Default Speed Current Speed
265 # -------------------------------------------------------------------------------------
266 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 25G
267 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 10G
268 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 10G
269 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
270 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 10G
271 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
272 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 10G
273 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 10G
274 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
275 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 10G
276 #
277 - name: Override port group speed
278 sonic_port_group:
279 config:
280 - id: 1
281 speed: SPEED_10GB
282 - id: 9
283 speed: SPEED_10GB
284 state: overridden
285 #
286 # After state:
287 # ------------
288 #
289 # sonic# show port-group
290 # -------------------------------------------------------------------------------------
291 # Port-group Interface range Valid speeds Default Speed Current Speed
292 # -------------------------------------------------------------------------------------
293 # 1 Ethernet0 - Ethernet3 10G, 25G 25G 10G
294 # 2 Ethernet4 - Ethernet7 10G, 25G 25G 25G
295 # 3 Ethernet8 - Ethernet11 10G, 25G 25G 25G
296 # 4 Ethernet12 - Ethernet15 10G, 25G 25G 25G
297 # 5 Ethernet16 - Ethernet19 10G, 25G 25G 25G
298 # 6 Ethernet20 - Ethernet23 10G, 25G 25G 25G
299 # 7 Ethernet24 - Ethernet27 10G, 25G 25G 25G
300 # 8 Ethernet28 - Ethernet31 10G, 25G 25G 25G
301 # 9 Ethernet32 - Ethernet35 10G, 25G 25G 10G
302 # 10 Ethernet36 - Ethernet39 10G, 25G 25G 25G
303 #
304 """
305
306 RETURN = """
307 before:
308 description: The configuration prior to the module invocation.
309 returned: always
310 type: list
311 sample: >
312 The configuration returned will always be in the same format
313 as the parameters above.
314 after:
315 description: The resulting configuration module invocation.
316 returned: when changed
317 type: list
318 sample: >
319 The configuration returned will always be in the same format
320 as the parameters above.
321 after_generated:
322 description: The generated configuration module invocation.
323 returned: when C(check_mode)
324 type: list
325 sample: >
326 The configuration returned will always be in the same format
327 as the parameters above.
328 commands:
329 description: The set of commands pushed to the remote device.
330 returned: always
331 type: list
332 sample: ['command 1', 'command 2', 'command 3']
333 """
334
335
336 from ansible.module_utils.basic import AnsibleModule
337 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.port_group.port_group import Port_groupArgs
338 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.port_group.port_group import Port_group
339
340
341 def main():
342 """
343 Main entry point for module execution
344
345 :returns: the result form module invocation
346 """
347 module = AnsibleModule(argument_spec=Port_groupArgs.argument_spec,
348 supports_check_mode=True)
349
350 result = Port_group(module).execute_module()
351 module.exit_json(**result)
352
353
354 if __name__ == '__main__':
355 main()