Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_dcbx.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_dcbx
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_dcbx
18 version_added: '3.1.0'
19 short_description: Manage DCBx configurations on SONiC
20 description:
21 - This module provides configuration management of DCBx parameters
22 in devices running SONiC.
23 author: 'Bing Sun(@bsun-sudo), Haemanthi Sree KR (@haemanthisree)'
24 options:
25 config:
26 description: The set of DCBx attribute configurations
27 type: dict
28 suboptions:
29 global:
30 description:
31 - Global DCBx configuration
32 type: dict
33 suboptions:
34 enabled:
35 description:
36 - This argument is a boolean value to enable or disable DCBx.
37 - It has a default value of False in SONiC and has an operational
38 - default value of False for the enterproise_sonic Ansible collection
39 type: bool
40 interfaces:
41 description:
42 - Interfaces DCBx configuration
43 type: list
44 elements: dict
45 suboptions:
46 name:
47 description:
48 - Interface name for which DCBx needs to be configured.
49 - This must be a physical (Ethernet) interface.
50 type: str
51 required: true
52 enabled:
53 description:
54 - This argument is a boolean value to enable or disable DCBx.
55 - It has a default value of True in SONiC and has an operational
56 - default value of True for the enterprise_sonic Ansible collection
57 - This command is supported only on physical interfaces and not on logical interfaces.
58 type: bool
59 pfc_tlv_enabled:
60 description:
61 - This command can be used to select whether to advertise and receive PFC TLV.
62 - It has a default value of True in SONiC and has an operational
63 - default value of True for the enterproise_sonic Ansible collection
64 type: bool
65 ets_configuration_tlv_enabled:
66 description:
67 - This command can be used to select whether to advertise and receive ETS configuration TLV.
68 - It has a default value of True in SONiC and has an operational
69 - default value of True for the enterproise_sonic Ansible collection
70 type: bool
71 ets_recommendation_tlv_enabled:
72 description:
73 - This command can be used to select whether to advertise and receive ETS recommendation TLV.
74 - It has a default value of True in SONiC and has an operational
75 - default value of True for the enterproise_sonic Ansible collection
76 type: bool
77 state:
78 description:
79 - The state specifies the type of configuration update to be performed on the device.
80 - If the state is "merged", merge specified attributes with existing configured attributes.
81 - For "deleted", delete the specified attributes from existing configuration.
82 type: str
83 choices:
84 - merged
85 - deleted
86 - replaced
87 - overridden
88 default: merged
89 """
90
91 EXAMPLES = """
92 # Using "merged" state for DCBx interface configuration
93 #
94 # Before State:
95 # -------------
96 #
97 # sonic# show running-configuration interface Ethernet0
98 # !
99 # interface Ethernet0
100 # mtu 9100
101 # speed 25000
102 # unreliable-los auto
103 # no shutdown
104
105 - name: Modify DCBx Interface configurations
106 dellemc.enterprise_sonic.sonic_dcbx:
107 config:
108 -interfaces:
109 - name: Ethernet0
110 enabled: false
111 pfc_tlv_enabled: false
112 ets_configuration_tlv_enabled: false
113 ets_recommendation_tlv_enabled: false
114 state: merged
115
116 # After State:
117 # ------------
118 #
119 # sonic# show running-configuration interface Ethernet0
120 # !
121 # interface Ethernet0
122 # mtu 9100
123 # speed 25000
124 # unreliable-los auto
125 # no shutdown
126 # no dcbx enable
127 # no dcbx tlv-select pfc
128 # no dcbx tlv-select ets-conf
129 # no dcbx tlv-select ets-reco
130
131 # Using "merged" state for DCBx global configuration
132 #
133 # Before State:
134 # -------------
135 #
136 # sonic# show running-configuration | grep dcbx
137 # sonic#
138
139 - name: Modify DCBX configurations
140 dellemc.enterprise_sonic.sonic_dcbx:
141 config:
142 global:
143 enabled: true
144 state: merged
145
146 # After State:
147 # ------------
148 #
149 # sonic# show running-configuration | grep dcbx
150 # !
151 # dcbx enable
152 # !
153
154 # Using "merged" state for DCBx interface configuration
155 #
156 # Before State:
157 # -------------
158 # sonic# show running-configuration interface Ethernet 0
159 # !
160 # interface Ethernet0
161 # mtu 9100
162 # speed 25000
163 # unreliable-los auto
164 # no shutdown
165 # no dcbx enable
166 # no dcbx tlv-select pfc
167 # no dcbx tlv-select ets-conf
168 # no dcbx tlv-select ets-reco
169
170
171 - name: Modify DCBx Interface configurations
172 dellemc.enterprise_sonic.sonic_dcbx:
173 config:
174 interfaces:
175 - name: Ethernet0
176 enabled: true
177 pfc_tlv_enabled: true
178 ets_configuration_tlv_enabled: true
179 ets_recommendation_tlv_enabled: true
180 state: merged
181
182 # After State:
183 # ------------
184 #
185 # sonic# show running-configuration interface Ethernet0
186 # !
187 # interface Ethernet0
188 # mtu 9100
189 # speed 25000
190 # unreliable-los auto
191 # no shutdown
192
193 # Using "deleted" state for DCBx interface configuration
194 #
195 # Before State:
196 # -------------
197 #
198 # sonic# show running-configuration interface Ethernet 0
199 # !
200 # interface Ethernet0
201 # mtu 9100
202 # speed 25000
203 # unreliable-los auto
204 # no shutdown
205 # no dcbx enable
206 # no dcbx tlv-select pfc
207 # no dcbx tlv-select ets-conf
208 # no dcbx tlv-select ets-reco
209
210
211 - name: Delete and set default DCBx Interface configurations
212 dellemc.enterprise_sonic.sonic_dcbx:
213 config:
214 interfaces:
215 - name: Ethernet0
216 enabled: false
217 pfc_tlv_enabled: false
218 ets_configuration_tlv_enabled: false
219 ets_recommendation_tlv_enabled: false
220 state: deleted
221
222 # After State:
223 # ------------
224 #
225 # sonic# show running-configuration interface Ethernet0
226 # !
227 # interface Ethernet0
228 # mtu 9100
229 # speed 25000
230 # unreliable-los auto
231 # no shutdown
232
233 # Using "replaced" state for DCBx interface configuration
234 #
235 # Before State:
236 # -------------
237 #
238 # sonic# show running-configuration interface Ethernet0
239 # !
240 # interface Ethernet0
241 # mtu 9100
242 # speed 25000
243 # unreliable-los auto
244 # no shutdown
245 # no dcbx tlv-select pfc
246 # no dcbx tlv-select ets-conf
247 # no dcbx tlv-select ets-reco
248 #
249 # sonic# show running-configuration interface Ethernet4
250 # !
251 # interface Ethernet4
252 # mtu 9100
253 # speed 25000
254 # unreliable-los auto
255 # no shutdown
256 # no dcbx enable
257 # no dcbx tlv-select pfc
258
259 - name: Modify DCBx Interface configurations
260 dellemc.enterprise_sonic.sonic_dcbx:
261 config:
262 -interfaces:
263 - name: Ethernet0
264 enabled: false
265 state: replaced
266
267 # After State:
268 # ------------
269 #
270 # sonic# show running-configuration interface Ethernet0
271 # !
272 # interface Ethernet0
273 # mtu 9100
274 # speed 25000
275 # unreliable-los auto
276 # no shutdown
277 # no dcbx enable
278 #
279 # sonic# show running-configuration interface Ethernet4
280 # !
281 # interface Ethernet4
282 # mtu 9100
283 # speed 25000
284 # unreliable-los auto
285 # no shutdown
286 # no dcbx enable
287 # no dcbx tlv-select pfc
288
289 # Using "overridden" state for DCBx interface configuration
290 #
291 # Before State:
292 # -------------
293 # sonic# show running-configuration interface Ethernet0
294 # !
295 # interface Ethernet0
296 # mtu 9100
297 # speed 25000
298 # unreliable-los auto
299 # no shutdown
300 # no dcbx tlv-select pfc
301 # no dcbx tlv-select ets-conf
302 # no dcbx tlv-select ets-reco
303 #
304 # sonic# show running-configuration interface Ethernet4
305 # !
306 # interface Ethernet4
307 # mtu 9100
308 # speed 25000
309 # unreliable-los auto
310 # no shutdown
311 # no dcbx enable
312 # no dcbx tlv-select pfc
313 #
314 # sonic# show running-configuration interface Ethernet8
315 # !
316 # interface Ethernet8
317 # mtu 9100
318 # speed 25000
319 # unreliable-los auto
320 # no shutdown
321 # no dcbx enable
322 # no dcbx tlv-select pfc
323 # no dcbx tlv-select ets-conf
324 # no dcbx tlv-select ets-reco
325 #
326 # sonic# show running-configuration interface Ethernet12
327 # !
328 # interface Ethernet12
329 # mtu 9100
330 # speed 25000
331 # unreliable-los auto
332 # no shutdown
333
334 - name: Modify DCBx Interface configurations
335 dellemc.enterprise_sonic.sonic_dcbx:
336 config:
337 -interfaces:
338 - name: Ethernet0
339 enabled: false
340 state: overridden
341
342 # After State:
343 # ------------
344 # sonic# show running-configuration interface Ethernet0
345 # !
346 # interface Ethernet0
347 # mtu 9100
348 # speed 25000
349 # unreliable-los auto
350 # no shutdown
351 # no dcbx enable
352 #
353 # sonic# show running-configuration interface Ethernet4
354 # !
355 # interface Ethernet4
356 # mtu 9100
357 # speed 25000
358 # unreliable-los auto
359 # no shutdown
360 #
361 # sonic# show running-configuration interface Ethernet8
362 # !
363 # interface Ethernet8
364 # mtu 9100
365 # speed 25000
366 # unreliable-los auto
367 # no shutdown
368 #
369 # sonic# show running-configuration interface Ethernet12
370 # !
371 # interface Ethernet12
372 # mtu 9100
373 # speed 25000
374 # unreliable-los auto
375 # no shutdown
376
377 # Using "deleted" state for DCBx global configuration
378 #
379 # Before State:
380 # -------------
381 #
382 # sonic# show running-configuration | grep dcbx
383 # !
384 # dcbx enable
385 # !
386
387 - name: Delete DCBX mode configuration
388 dellemc.enterprise_sonic.sonic_dcbx:
389 config:
390 global:
391 enabled: true
392 state: deleted
393
394 # After State:
395 # ------------
396 #
397 # sonic# show running-configuration | grep dcbx
398 # sonic#
399 """
400
401 RETURN = """
402 before:
403 description: The configuration prior to the module invocation.
404 returned: always
405 type: list
406 sample: >
407 The configuration returned will always be in the same format
408 as the parameters above.
409 after:
410 description: The resulting configuration from module invocation.
411 returned: when changed, if C(check_mode) is not set
412 type: list
413 sample: >
414 The configuration returned will always be in the same format
415 as the parameters above.
416 after_generated:
417 description: The generated (simulated) configuration from module invocation.
418 returned: when C(check_mode)
419 type: list
420 sample: >
421 The configuration returned will always be in the same format
422 as the parameters above.
423 commands:
424 description: The set of commands pushed to the remote device.
425 returned: always
426 type: list
427 sample: ['command 1', 'command 2', 'command 3']
428 """
429
430
431 from ansible.module_utils.basic import AnsibleModule
432 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.dcbx.dcbx import DcbxArgs
433 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.dcbx.dcbx import Dcbx
434
435
436 def main():
437 """
438 Main entry point for module execution
439
440 :returns: the result from module invocation
441 """
442 module = AnsibleModule(argument_spec=DcbxArgs.argument_spec,
443 supports_check_mode=True)
444
445 result = Dcbx(module).execute_module()
446 module.exit_json(**result)
447
448
449 if __name__ == '__main__':
450 main()