Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_qos_wred.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_qos_wred
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_qos_wred
17 version_added: 2.5.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage QoS WRED profiles configuration on SONiC
22 description:
23 - This module provides configuration management of QoS WRED profiles for devices running SONiC
24 author: "S. Talabi (@stalabi1)"
25 options:
26 config:
27 description:
28 - QoS WRED profile configuration
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of the WRED profile
35 type: str
36 required: True
37 ecn:
38 description:
39 - ECN setting for colored packets
40 type: str
41 choices:
42 - 'all'
43 - 'none'
44 green:
45 description:
46 - WRED configuration for green packets
47 type: dict
48 suboptions:
49 enable:
50 description:
51 - Enable or disable WRED for green packets
52 type: bool
53 min_threshold:
54 description:
55 - Minimum threshold set for green packets in bytes
56 - Range 1000-12480000
57 type: int
58 max_threshold:
59 description:
60 - Maximum threshold set for green packets in bytes
61 - Range 1000-12480000
62 type: int
63 drop_probability:
64 description:
65 - Drop probablity percentage rate for green packets
66 - Range 0-100
67 type: int
68 yellow:
69 description:
70 - WRED configuration for yellow packets
71 version_added: 4.0.0
72 type: dict
73 suboptions:
74 enable:
75 description:
76 - Enable or disable WRED for yellow packets
77 type: bool
78 min_threshold:
79 description:
80 - Minimum threshold set for yellow packets in bytes
81 - Range 1000-12480000
82 type: int
83 max_threshold:
84 description:
85 - Maximum threshold set for yellow packets in bytes
86 - Range 1000-12480000
87 type: int
88 drop_probability:
89 description:
90 - Drop probablity percentage rate for yellow packets
91 - Range 0-100
92 type: int
93 red:
94 description:
95 - WRED configuration for red packets
96 version_added: 4.0.0
97 type: dict
98 suboptions:
99 enable:
100 description:
101 - Enable or disable WRED for red packets
102 type: bool
103 min_threshold:
104 description:
105 - Minimum threshold set for red packets in bytes
106 - Range 1000-12480000
107 type: int
108 max_threshold:
109 description:
110 - Maximum threshold set for red packets in bytes
111 - Range 1000-12480000
112 type: int
113 drop_probability:
114 description:
115 - Drop probablity percentage rate for red packets
116 - Range 0-100
117 type: int
118 state:
119 description:
120 - The state of the configuration after module completion.
121 type: str
122 choices:
123 - merged
124 - deleted
125 - overridden
126 - replaced
127 default: merged
128 """
129
130 EXAMPLES = """
131 # Using "merged" state
132 #
133 # Before state:
134 # -------------
135 #
136 # sonic# show qos wred-policy
137 # (No qos wred-policy configuration present)
138
139 - name: Merge QoS WRED policy configuration
140 dellemc.enterprise_sonic.sonic_qos_wred:
141 config:
142 - name: profile1
143 ecn: green
144 green:
145 enable: true
146 min_threshold: 1000
147 max_threshold: 5000
148 drop_probability: 25
149 red:
150 enable: true
151 min_threshold: 1000
152 max_threshold: 5000
153 drop_probability: 25
154 yellow:
155 enable: true
156 min_threshold: 1000
157 max_threshold: 5000
158 drop_probability: 25
159 state: merged
160
161 # After state:
162 # ------------
163 #
164 # sonic# show qos wred-policy
165 # ---------------------------------------------------
166 # Policy : profile1
167 # ---------------------------------------------------
168 # ecn : ecn_all
169 # green-min-threshold : 1 KBytes
170 # green-max-threshold : 5 KBytes
171 # green-drop-probability : 25
172 # red-min-threshold : 1 KBytes
173 # red-max-threshold : 5 KBytes
174 # red-drop-probability : 25
175 # yellow-min-threshold : 1 KBytes
176 # yellow-max-threshold : 5 KBytes
177 # yellow-drop-probability : 25
178 #
179 #
180 # Using "replaced" state
181 #
182 # Before state:
183 # -------------
184 #
185 # sonic# show qos wred-policy
186 # ---------------------------------------------------
187 # Policy : profile1
188 # ---------------------------------------------------
189 # ecn : ecn_all
190 # green-min-threshold : 1 KBytes
191 # green-max-threshold : 5 KBytes
192 # green-drop-probability : 25
193 # red-min-threshold : 1 KBytes
194 # red-max-threshold : 5 KBytes
195 # red-drop-probability : 25
196 # yellow-min-threshold : 1 KBytes
197 # yellow-max-threshold : 5 KBytes
198 # yellow-drop-probability : 25
199
200
201 - name: Replace QoS WRED policy configuration
202 dellemc.enterprise_sonic.sonic_qos_wred:
203 config:
204 - name: profile1
205 green:
206 drop_probability: 75
207 state: replaced
208
209 # After state:
210 # ------------
211 #
212 # sonic# show qos wred-policy
213 # ---------------------------------------------------
214 # Policy : profile1
215 # ---------------------------------------------------
216 # green-drop-probability : 75
217
218 # Using "overridden" state
219 #
220 # Before state:
221 # -------------
222 #
223 # sonic# show qos wred-policy
224 # ---------------------------------------------------
225 # Policy : profile1
226 # ---------------------------------------------------
227 # ecn : ecn_all
228 # green-min-threshold : 1 KBytes
229 # green-max-threshold : 5 KBytes
230 # green-drop-probability : 25
231 # red-min-threshold : 1 KBytes
232 # red-max-threshold : 5 KBytes
233 # red-drop-probability : 25
234 # yellow-min-threshold : 1 KBytes
235 # yellow-max-threshold : 5 KBytes
236 # yellow-drop-probability : 25
237
238 - name: Override QoS WRED policy configuration
239 dellemc.enterprise_sonic.sonic_qos_wred:
240 config:
241 - name: profile2
242 ecn: green
243 green:
244 enable: false
245 min_threshold: 3000
246 max_threshold: 9000
247 drop_probability: 75
248 state: overridden
249
250 # After state:
251 # ------------
252 #
253 # sonic# show qos wred-policy
254 # ---------------------------------------------------
255 # Policy : profile2
256 # ---------------------------------------------------
257 # ecn : ecn_all
258 # green-min-threshold : 3 KBytes
259 # green-max-threshold : 9 KBytes
260 # green-drop-probability : 75
261 # red-min-threshold : 1 KBytes
262 # red-max-threshold : 5 KBytes
263 # red-drop-probability : 25
264 # yellow-min-threshold : 1 KBytes
265 # yellow-max-threshold : 5 KBytes
266 # yellow-drop-probability : 25
267 #
268 #
269 # Using "deleted" state
270 #
271 # Before state:
272 # -------------
273 #
274 # sonic# show qos wred-policy
275 # ---------------------------------------------------
276 # Policy : profile1
277 # ---------------------------------------------------
278 # ecn : ecn_all
279 # green-min-threshold : 1 KBytes
280 # green-max-threshold : 5 KBytes
281 # green-drop-probability : 25
282 # red-min-threshold : 1 KBytes
283 # red-max-threshold : 5 KBytes
284 # red-drop-probability : 25
285 # yellow-min-threshold : 1 KBytes
286 # yellow-max-threshold : 5 KBytes
287 # yellow-drop-probability : 25
288 # ---------------------------------------------------
289 # Policy : profile2
290 # ---------------------------------------------------
291 # ecn : ecn_all
292 # green-min-threshold : 3 KBytes
293 # green-max-threshold : 9 KBytes
294 # green-drop-probability : 75
295 # red-min-threshold : 1 KBytes
296 # red-max-threshold : 5 KBytes
297 # red-drop-probability : 25
298 # yellow-min-threshold : 1 KBytes
299 # yellow-max-threshold : 5 KBytes
300 # yellow-drop-probability : 25
301
302 - name: Delete QoS WRED policy configuration
303 dellemc.enterprise_sonic.sonic_qos_wred:
304 config:
305 - name: profile1
306 - name: profile2
307 green:
308 enable: false
309 min_threshold: 3000
310 max_threshold: 9000
311 state: deleted
312
313 # After state:
314 # ------------
315 #
316 # sonic# show qos wred-policy
317 # ---------------------------------------------------
318 # Policy : profile2
319 # ---------------------------------------------------
320 # ecn : ecn_all
321 # green-drop-probability : 75
322 # red-min-threshold : 1 KBytes
323 # red-max-threshold : 5 KBytes
324 # red-drop-probability : 25
325 # yellow-min-threshold : 1 KBytes
326 # yellow-max-threshold : 5 KBytes
327 # yellow-drop-probability : 25
328 """
329
330 RETURN = """
331 before:
332 description: The configuration prior to the module invocation.
333 returned: always
334 type: list
335 sample: >
336 The configuration returned will always be in the same format
337 as the parameters above.
338 after:
339 description: The resulting configuration module invocation.
340 returned: when changed
341 type: list
342 sample: >
343 The configuration returned will always be in the same format
344 as the parameters above.
345 after_generated:
346 description: The generated configuration module invocation.
347 returned: when C(check_mode)
348 type: list
349 sample: >
350 The configuration returned will always be in the same format
351 as the parameters above.
352 commands:
353 description: The set of commands pushed to the remote device.
354 returned: always
355 type: list
356 sample: ['command 1', 'command 2', 'command 3']
357 """
358
359
360 from ansible.module_utils.basic import AnsibleModule
361 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.qos_wred.qos_wred import Qos_wredArgs
362 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.qos_wred.qos_wred import Qos_wred
363
364
365 def main():
366 """
367 Main entry point for module execution
368
369 :returns: the result form module invocation
370 """
371 module = AnsibleModule(argument_spec=Qos_wredArgs.argument_spec,
372 supports_check_mode=True)
373
374 result = Qos_wred(module).execute_module()
375 module.exit_json(**result)
376
377
378 if __name__ == '__main__':
379 main()