Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_qos_interfaces.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_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_qos_interfaces
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 interfaces configuration on SONiC
22 description:
23 - This module provides configuration management of QoS interfaces for devices running SONiC
24 author: "S. Talabi (@stalabi1)"
25 options:
26 config:
27 description:
28 - QoS interfaces configuration
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of the interface
35 type: str
36 required: True
37 queues:
38 description:
39 - Queue configuration
40 type: list
41 elements: dict
42 suboptions:
43 id:
44 description:
45 - Queue identification
46 - Range 0-7 for interface queues, range 0-47 for CPU queues
47 type: int
48 required: True
49 wred_profile:
50 description:
51 - Name of the WRED profile
52 type: str
53 scheduler_policy:
54 description:
55 - Name of scheduler policy to be applied to traffic on the interface
56 type: str
57 cable_length:
58 version_added: 3.1.0
59 description:
60 - Cable length of the interface
61 type: str
62 choices: ['5m', '40m', '300m']
63 default: '40m'
64 qos_maps:
65 description:
66 - QoS maps interface configuration
67 type: dict
68 suboptions:
69 dscp_fwd_group:
70 description:
71 - DSCP to forwarding group map associated with the interface
72 type: str
73 dot1p_fwd_group:
74 description:
75 - DOT1P to forwarding group map associated with the interface
76 type: str
77 fwd_group_dscp:
78 description:
79 - Forwarding group to DSCP map associated with the interface
80 type: str
81 fwd_group_dot1p:
82 description:
83 - Forwarding group to DOT1P map associated with the interface
84 type: str
85 fwd_group_queue:
86 description:
87 - Forwarding group to queue map associated with the interface
88 type: str
89 fwd_group_pg:
90 description:
91 - Forwading group to priority group map associated with the interface
92 type: str
93 pfc_priority_queue:
94 description:
95 - PFC priority to queue map associated with the interface
96 type: str
97 pfc_priority_pg:
98 description:
99 - PFC priority to priority group map associated with the interface
100 type: str
101 pfc:
102 description:
103 - PFC configuration
104 type: dict
105 suboptions:
106 asymmetric:
107 description:
108 - Enable or disable asymmetric PFC on the interface
109 type: bool
110 default: False
111 priorities:
112 description:
113 - PFC priorities configuration
114 type: list
115 elements: dict
116 suboptions:
117 dot1p:
118 description:
119 - DOT1P value, range 0-7
120 - Maxium of 2 priorities supported
121 type: int
122 required: True
123 enable:
124 description:
125 - Enable or disable the priority
126 type: bool
127 default: False
128 watchdog_action:
129 description:
130 - PFC watchdog storm action
131 type: str
132 choices:
133 - drop
134 - forward
135 - alert
136 default: drop
137 watchdog_detect_time:
138 description:
139 - PFC watchdog detection time in milliseconds, range 100-5000
140 type: int
141 watchdog_restore_time:
142 description:
143 - PFC watchdog restoration time milliseconds, range 100-60000
144 type: int
145 state:
146 description:
147 - The state of the configuration after module completion
148 - Replaced and overridden states are not supported for this module due to configuration constraints
149 type: str
150 choices:
151 - merged
152 - deleted
153 default: merged
154 """
155
156 EXAMPLES = """
157 # Using "merged" state
158 #
159 # Before state:
160 # -------------
161 #
162 # sonic# show running-configuration interface Eth 1/5
163 # !
164 # interface Eth1/5
165 # (No QoS configuration present for the interface)
166
167 - name: Merge QoS interfaces configuration
168 dellemc.enterprise_sonic.sonic_qos_interfaces:
169 config:
170 - name: Eth1/5
171 queues:
172 - id: 0
173 wred_profile: profile1
174 scheduler_policy: policy1
175 cable_length: 40m
176 qos_maps:
177 dscp_fwd_group: dscp_map1
178 dot1p_fwd_group: dot1p_map1
179 fwd_group_dscp: fwd_dscp_map1
180 fwd_group_dot1p: fwd_dot1p_map1
181 fwd_group_queue: fwd_queue_map1
182 fwd_group_pg: fwd_pg_map1
183 pfc_priority_queue: pfc_queue_map1
184 pfc_priority_pg: pfc_pg_map1
185 pfc:
186 asymmetric: true
187 watchdog_action: alert
188 watchdog_detect_time: 100
189 watchdog_restore_time: 200
190 priorities:
191 - dot1p: 0
192 enable: true
193 - dot1p: 1
194 enable: true
195 state: merged
196
197 # After state:
198 # ------------
199 #
200 # sonic# show running-configuration interface Eth 1/5
201 # !
202 # interface Eth1/5
203 # queue 0 wred-policy profile1
204 # scheduler-policy policy1
205 # cable-length 40m
206 # qos-map dscp-tc dscp_map1
207 # qos-map dot1p-tc dot1p_map1
208 # qos-map tc-queue fwd_queue_map1
209 # qos-map tc-pg fwd_pg_map1
210 # qos-map tc-dscp fwd_dscp_map1
211 # qos-map tc-dot1p fwd_dot1p_map1
212 # qos-map pfc-priority-queue pfc_queue_map1
213 # qos-map pfc-priority-pg pfc_pg_map1
214 # priority-flow-control priority 0
215 # priority-flow-control priority 1
216 # priority-flow-control asymmetric
217 # priority-flow-control watchdog action alert
218 # priority-flow-control watchdog on detect-time 100
219 # priority-flow-control watchdog restore-time 200
220 #
221 #
222 # Using "deleted" state
223 #
224 # Before state:
225 # -------------
226 #
227 # sonic# show running-configuration interface Eth 1/5
228 # !
229 # interface Eth1/5
230 # queue 0 wred-policy profile2
231 # queue 1 wred-policy profile1
232 # scheduler-policy policy2
233 # cable-length 5m
234 # qos-map dscp-tc dscp_map2
235 # qos-map dot1p-tc dot1p_map2
236 # qos-map tc-queue fwd_queue_map2
237 # qos-map tc-pg fwd_pg_map2
238 # qos-map tc-dscp fwd_dscp_map2
239 # qos-map tc-dot1p fwd_dot1p_map2
240 # qos-map pfc-priority-queue pfc_queue_map1
241 # qos-map pfc-priority-pg pfc_pg_map1
242 # priority-flow-control priority 1
243 # priority-flow-control watchdog action drop
244 # priority-flow-control watchdog on detect-time 150
245 # priority-flow-control watchdog restore-time 250
246 # sonic# show running-configuration interface Eth 1/6
247 # !
248 # interface Eth1/6
249 # queue 0 wred-policy profile1
250 # scheduler-policy policy1
251 # cable-length 40m
252 # qos-map dscp-tc dscp_map1
253 # qos-map dot1p-tc dot1p_map1
254 # qos-map tc-queue fwd_queue_map1
255 # qos-map tc-pg fwd_pg_map1
256 # qos-map tc-dscp fwd_dscp_map1
257 # qos-map tc-dot1p fwd_dot1p_map1
258 # qos-map pfc-priority-queue pfc_queue_map1
259 # qos-map pfc-priority-pg pfc_pg_map1
260 # priority-flow-control priority 0
261 # priority-flow-control asymmetric
262 # priority-flow-control watchdog on detect-time 100
263 # priority-flow-control watchdog restore-time 200
264
265 - name: Delete QoS interfaces attributes
266 dellemc.enterprise_sonic.sonic_interfaces:
267 config:
268 - name: Eth1/5
269 queues:
270 - id: 0
271 wred_profile: profile2
272 - id: 1
273 scheduler_policy: policy2
274 cable_length: 5m
275 qos_maps:
276 dscp_fwd_group: dscp_map2
277 dot1p_fwd_group: dot1p_map2
278 fwd_group_dscp: fwd_dscp_map2
279 fwd_group_dot1p: fwd_dot1p_map2
280 fwd_group_queue: fwd_queue_map2
281 fwd_group_pg: fwd_pg_map2
282 - name: Eth1/6
283 pfc:
284 asymmetric: true
285 watchdog_action: drop
286 watchdog_detect_time: 100
287 watchdog_restore_time: 200
288 priorities:
289 - dot1p: 0
290 enable: true
291 - dot1p: 1
292 enable: true
293 state: deleted
294
295 # After state:
296 # ------------
297 #
298 # sonic# show running-configuration interface Eth 1/5
299 # !
300 # interface Eth1/5
301 # cable-length 40m
302 # qos-map pfc-priority-queue pfc_queue_map1
303 # qos-map pfc-priority-pg pfc_pg_map1
304 # priority-flow-control priority 1
305 # priority-flow-control watchdog action drop
306 # priority-flow-control watchdog on detect-time 150
307 # priority-flow-control watchdog restore-time 250
308 # sonic# show running-configuration interface Eth 1/6
309 # !
310 # interface Eth1/6
311 # queue 0 wred-policy profile1
312 # scheduler-policy policy1
313 # cable-length 40m
314 # qos-map dscp-tc dscp_map1
315 # qos-map dot1p-tc dot1p_map1
316 # qos-map tc-queue fwd_queue_map1
317 # qos-map tc-pg fwd_pg_map1
318 # qos-map tc-dscp fwd_dscp_map1
319 # qos-map tc-dot1p fwd_dot1p_map1
320 # qos-map pfc-priority-queue pfc_queue_map1
321 # qos-map pfc-priority-pg pfc_pg_map1
322 """
323
324 RETURN = """
325 before:
326 description: The configuration prior to the module invocation.
327 returned: always
328 type: list
329 sample: >
330 The configuration returned will always be in the same format
331 as the parameters above.
332 after:
333 description: The resulting configuration from module invocation.
334 returned: when changed, if C(check_mode) is not set
335 type: list
336 sample: >
337 The configuration returned will always be in the same format
338 as the parameters above.
339 after_generated:
340 description: The generated (simulated) configuration from module invocation.
341 returned: when C(check_mode)
342 type: list
343 sample: >
344 The configuration returned will always be in the same format
345 as the parameters above.
346 commands:
347 description: The set of commands pushed to the remote device.
348 returned: always
349 type: list
350 sample: ['command 1', 'command 2', 'command 3']
351 """
352
353
354 from ansible.module_utils.basic import AnsibleModule
355 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.qos_interfaces.qos_interfaces import Qos_interfacesArgs
356 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.qos_interfaces.qos_interfaces import Qos_interfaces
357
358
359 def main():
360 """
361 Main entry point for module execution
362
363 :returns: the result form module invocation
364 """
365 module = AnsibleModule(argument_spec=Qos_interfacesArgs.argument_spec,
366 supports_check_mode=True)
367
368 result = Qos_interfaces(module).execute_module()
369 module.exit_json(**result)
370
371
372 if __name__ == '__main__':
373 main()