Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_poe.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_poe
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_poe
17 version_added: "2.5.0"
18 short_description: Manage PoE configuration on SONiC
19 description:
20 - This module provides configuration management of PoE at global and card level for devices running SONiC
21 author: "S. Talabi (@stalabi1), Xiao Han (@Xiao_Han2)"
22 options:
23 config:
24 description:
25 - Specifies PoE configurations
26 type: dict
27 suboptions:
28 global:
29 description: configuration for global PoE card
30 type: dict
31 suboptions:
32 power_mgmt_model:
33 description:
34 - the power management algorithm to use.
35 - dynamic means that power consumption of each port is measured and calculated in real-time.
36 - static means that power allocated for each port depends on the type of power threshold configured on the port.
37 - currently only 'dynamic' and 'class' values are supported
38 type: str
39 choices: ['dynamic', 'dynamic-priority', 'static', 'static-priority', 'class']
40 usage_threshold:
41 description:
42 - Inline power usage threshold.
43 - Range is 0-99 inclusive.
44 - currently not supported on platforms.
45 type: int
46 auto_reset:
47 description:
48 - enable PoE auto reset mode for global.
49 - currently not supported on platforms.
50 type: bool
51 cards:
52 description:
53 - PoE card (power controller hardware) configuration.
54 - currently not supported on platforms.
55 type: list
56 elements: dict
57 suboptions:
58 card_id:
59 description:
60 - Identifier for the card.
61 - must be number in range of 0-7.
62 type: int
63 required: True
64 power_mgmt_model:
65 description:
66 - the power management algorithm.
67 - dynamic means that power consumption of each port is measured and calculated in real-time.
68 - static means that power allocated for each port depends on the type of power threshold configured on the port
69 type: str
70 choices: ['dynamic', 'dynamic-priority', 'static', 'static-priority', 'class']
71 usage_threshold:
72 description:
73 - Inline power usage threshold.
74 - Range is 0-99 inclusive
75 type: int
76 auto_reset:
77 description: enable PoE auto reset mode for this card
78 type: bool
79 interfaces:
80 description: PoE configuration for ethernet interfaces
81 type: list
82 elements: dict
83 suboptions:
84 name:
85 description: Name of the interface
86 type: str
87 required: True
88 enabled:
89 description: enable PoE per port
90 type: bool
91 priority:
92 description:
93 - PoE port priority in power management algorithm.
94 - Priority could be used by a control mechanism
95 that prevents over current situations by disconnecting
96 ports with lower power priority first.
97 - currently only 'low', 'high' and 'critical' values are supported
98 type: str
99 choices: ['low', 'medium', 'high', 'critical']
100 detection:
101 description:
102 - Device detection mechanism performed by this PSE port.
103 - Legacy is capacitive detection scheme, which can be used alone or as a backup if other detection schemes fail.
104 - Those schemes are IEEE 802 standard schemes.
105 - None cannot be forcibly set by adminstrator.
106 - currently only 'dot3bt' and 'dot3bt+legacy' values are supported
107 type: str
108 choices: ['2pt-dot3af', '2pt-dot3af+legacy', '4pt-dot3af', '4pt-dot3af+legacy', 'dot3bt', 'dot3bt+legacy', 'legacy']
109 power_up_mode:
110 description:
111 - The mode configured for a PSE port to deliver high power.
112 - pre-dot3at means that a port is powered in the IEEE 802.3af mode initially, switched to the high-power IEEE 802.3at mode.
113 - dot3at means that a port is powered in the IEEE 802.3at mode.
114 - dot3bt, type3 and pre-dot3bt are to support 802.3bt interfaces.
115 - currently not supported on platforms.
116 type: str
117 choices: ['dot3af', 'dot3at', 'dot3bt', 'dot3bt-type3', 'dot3bt-type4', 'high-inrush', 'pre-dot3at', 'pre-dot3bt']
118 power_pairs:
119 description:
120 - PoE port power-pairs settings.
121 - currently not supported on platforms.
122 type: str
123 choices: ['signal', 'spare']
124 power_limit_type:
125 description:
126 - Controls the maximum power that a port can deliver.
127 - class-based means that the port power limit is as per the dot3af class of the powered device attached.
128 - user-defined means limit is specified by config.
129 - currently not supported on platforms.
130 type: str
131 choices: ['class-based', 'user-defined']
132 power_limit:
133 description:
134 - The configured maximum power this port can provide to an attached device measured in Milliwatts.
135 - Range is 0-99900 inclusive.
136 - currently not supported on platforms.
137 type: int
138 high_power:
139 description:
140 - Enables high power mode on a PSE port.
141 - currently not supported on platforms.
142 type: bool
143 disconnect_type:
144 description:
145 - PoE port disconnect type.
146 - currently not supported on platforms.
147 type: str
148 choices: ['ac', 'dc']
149 four_pair:
150 description:
151 - Enables four pair mode for port.
152 - currently not supported on platforms.
153 type: bool
154 use_spare_pair:
155 description:
156 - Enables spare pair power for port.
157 - currently not supported on platforms.
158 type: bool
159 power_classification:
160 description:
161 - PoE power-classification mode for port.
162 - currently not supported on platforms.
163 type: str
164 choices: ['normal', 'bypass']
165 state:
166 description:
167 - The state of the configuration after module completion
168 type: str
169 choices: ['merged', 'deleted', 'replaced', 'overridden']
170 default: merged
171 """
172
173 EXAMPLES = """
174 # Using "merged" state to add or change poe global settings
175 # Before state:
176 # config:
177 # global:
178 # auto_reset: false
179
180 # Example:
181 - name: "add poe global settings"
182 sonic_poe:
183 config:
184 global:
185 auto_reset: true
186 power_mgmt_model: 'class'
187 usage_threshold: 300
188 state: merged
189
190 # After state:
191 # config:
192 # global:
193 # auto_reset: true
194 # power_mgmt_model: 'class'
195 # usage_threshold: 300
196 # ------
197
198 # Using "merged" state to add cards
199 # Note that platform must support adding multiple cards to do this
200 # Before state:
201 # config:
202 # global:
203 # auto_reset: true
204
205 # Example:
206 - name: "add poe cards"
207 sonic_poe:
208 config:
209 cards:
210 - card_id: 0
211 usage_threshold: 39
212 state: merged
213
214 # After state:
215 # config:
216 # global:
217 # auto_reset: true
218 # cards:
219 # - card_id: 0
220 # usage_threshold: 39
221 # ------
222
223 # Using "merged" state to add or change card settings
224 # Before state:
225 # config:
226 # cards:
227 # - card_id: 0
228 # usage_threshold: 39
229
230 # Example:
231 - name: "add poe cards settings"
232 sonic_poe:
233 config:
234 cards:
235 - card_id: 0
236 usage_threshold: 60
237 power_mgmt_model: dymanic
238 state: merged
239
240 # After state:
241 # config:
242 # cards:
243 # - card_id: 0
244 # usage_threshold: 60
245 # power_mgmt_model: dymanic
246 # ------
247
248 # Using "merged" state to add interfaces
249 # Before state:
250 # config: {}
251
252 # Example:
253 - name: "add poe interfaces"
254 sonic_poe:
255 config:
256 interfaces:
257 - name: Ethernet0
258 enabled: true
259 state: merged
260
261 # After state:
262 # config:
263 # interfaces:
264 # - name: Ethernet0
265 # enabled: true
266 # ------
267
268 # Using "merged" state to add or change interface settings
269 # Before state:
270 # config:
271 # interfaces:
272 # - name: Ethernet0
273 # enabled: true
274 # disconnect_type: dc
275
276 # Example:
277 - name: "add poe interface settings"
278 sonic_poe:
279 config:
280 interfaces:
281 - name: Ethernet0
282 four_pair: true
283 high_power: true
284 detection: dot3bt
285 power_classification: normal
286 power_limit: 5000
287 power_limit_type: class-based
288 power_pairs: signal
289 power_up_mode: dot3bt
290 priority: medium
291 use_spare_pair: false
292 disconnect_type: ac
293 state: merged
294
295 # After state:
296 # config:
297 # interfaces:
298 # - name: Ethernet0
299 # four_pair: true
300 # high_power: true
301 # detection: dot3bt
302 # power_classification: normal
303 # power_limit: 5000
304 # power_limit_type: class-based
305 # power_pairs: signal
306 # power_up_mode: dot3bt
307 # priority: medium
308 # use_spare_pair: false
309 # disconnect_type: ac
310 # enabled: true
311 # ------
312
313
314 # Using "deleted" state to remove poe global settings
315 # Before state:
316 # config:
317 # global:
318 # auto_reset: true
319 # power_mgmt_model: 'class'
320 # usage_threshold: 300
321
322 # Example:
323 - name: "delete matching poe global settings"
324 sonic_poe:
325 config:
326 global:
327 auto_reset: false
328 usage_threshold: 300
329 state: deleted
330
331 # After state:
332 # config:
333 # global:
334 # power_mgmt_model: 'class'
335 # auto_reset: true
336 # ------
337
338 # Using "deleted" state to delete cards or card settings
339 # Note: to delete whole card, either need just the name or specify all current settings and values
340 # Before state:
341 # config:
342 # global:
343 # auto_reset: true
344 # cards:
345 # - card_id: 0
346 # usage_threshold: 39
347 # - card_id: 1
348 # auto_reset: true
349 # usage_threshold: 60
350 # power_mgmt_model: class
351 # - card_id: 2
352 # usage_threshold: 39
353 # power_mgmt_model: dymanic
354
355 # Example:
356 - name: "delete poe cards"
357 sonic_poe:
358 config:
359 cards:
360 - card_id: 0
361 - card_id: 1
362 auto_reset: true
363 usage_threshold: 60
364 power_mgmt_model: class
365 - card_id: 2
366 usage_threshold: 39
367 power_mgmt_model: static
368 state: deleted
369
370 # After state:
371 # config:
372 # global:
373 # auto_reset: true
374 # cards:
375 # - card_id: 2
376 # power_mgmt_model: dymanic
377 # ------
378
379 # Using "deleted" state to delete interfaces or interface settings
380 # Note: to delete whole interface, either need just the name or specify all current settings and values
381 # Before state:
382 # config:
383 # interfaces:
384 # - name: Ethernet0
385 # enabled: true
386 # - name: Ethernet1
387 # enabled: false
388 # four_pair: true
389 # - name: Ethernet2
390 # detection: 4pt-dot3af+legacy
391 # power_up_mode: dot3bt
392 # use_spare_pair: true
393
394 # Example:
395 - name: "delete poe interfaces"
396 sonic_poe:
397 config:
398 interfaces:
399 - name: Ethernet0
400 - name: Ethernet1
401 enabled: false
402 four_pair: true
403 - name: Ethernet2
404 detection: 4pt-dot3af+legacy
405 power_up_mode: pre-dot3at
406 state: deleted
407
408 # After state:
409 # config:
410 # interfaces:
411 # - name: Ethernet2
412 # power_up_mode: dot3bt
413 # use_spare_pair: true
414 # ------
415
416 # Using "deleted" state to clear all interfaces or cards
417 # Before state:
418 # config:
419 # cards:
420 # - card_id: 0
421 # usage_threshold: 39
422 # interfaces:
423 # - name: Ethernet0
424 # enabled: true
425
426 # Example:
427 - name: "clear poe interfaces and cards"
428 sonic_poe:
429 config:
430 interfaces: []
431 cards: []
432 state: deleted
433
434 # After state:
435 # config: {}
436 # ------
437
438 # Using "deleted" state to delete attributes of interfaces or cards
439 # Before state:
440 # config:
441 # cards:
442 # - card_id: 1
443 # auto_reset: true
444 # usage_threshold: 60
445 # interfaces:
446 # - name: Ethernet1
447 # enabled: false
448 # four_pair: true
449 # power_classification: normal
450
451 # Example:
452 - name: "clear poe interfaces and cards"
453 sonic_poe:
454 config:
455 interfaces:
456 - name: Ethernet1
457 four_pair: true
458 cards:
459 - card_id: 1
460 usage_threshold: 60
461 state: deleted
462
463 # After state:
464 # config:
465 # interfaces:
466 # - name: Ethernet1
467 # enabled: false
468 # power_classification: normal
469 # cards:
470 # - card_id: 1
471 # auto_reset: true
472 # ------
473
474
475 # Using "overridden" state to set poe config
476 # Before state:
477 # config:
478 # global:
479 # auto_reset: true
480 # power_mgmt_model: 'class'
481 # usage_threshold: 300
482 # interfaces:
483 # - name: Ethernet1
484 # power_classification: normal
485 # enabled: true
486 # cards:
487 # - card_id: 0
488 # usage_threshold: 60
489 # power_mgmt_model: dymanic
490
491 # Example:
492 - name: "overridden to exactly specified"
493 sonic_poe:
494 config:
495 global:
496 auto_reset: false
497 interfaces:
498 - name: Ethernet0
499 enabled: true
500 disconnect_type: ac
501 - name: Ethernet1
502 power_pairs: signal
503 state: overridden
504
505 # After state:
506 # config:
507 # global:
508 # auto_reset: false
509 # interfaces:
510 # - name: Ethernet0
511 # disconnect_type: ac
512 # enabled: true
513 # - name: Ethernet1
514 # power_pairs: signal
515 # ------
516
517
518 # Using "replaced" state to replace sections of poe config
519 # Before state:
520 # config:
521 # global:
522 # auto_reset: true
523 # power_mgmt_model: 'class'
524 # usage_threshold: 300
525 # interfaces:
526 # - name: Ethernet1
527 # power_classification: normal
528 # enabled: true
529 # - name: Ethernet0
530 # enabled: true
531 # power_limit_type: class-based
532 # cards:
533 # - card_id: 0
534 # usage_threshold: 60
535 # power_mgmt_model: dymanic
536
537 # Example:
538 - name: "replace sections of config to exactly specified"
539 sonic_poe:
540 config:
541 global:
542 auto_reset: false
543 interfaces:
544 - name: Ethernet0
545 enabled: true
546 disconnect_type: ac
547 state: repalced
548
549 # After state:
550 # config:
551 # global:
552 # auto_reset: false
553 # interfaces:
554 # - name: Ethernet0
555 # disconnect_type: ac
556 # enabled: true
557 # cards:
558 # - card_id: 0
559 # usage_threshold: 60
560 # power_mgmt_model: dymanic
561 # ------
562 """
563
564 RETURN = """
565 before:
566 description: The configuration prior to the module invocation.
567 returned: always
568 type: dict
569 sample: >
570 The configuration returned will always be in the same format
571 as the parameters above.
572 after:
573 description: The resulting configuration after module invocation.
574 returned: when changed
575 type: dict
576 sample: >
577 The configuration returned will always be in the same format
578 as the parameters above.
579 commands:
580 description: The set of commands pushed to the remote device.
581 returned: always
582 type: list
583 sample: ['command 1', 'command 2', 'command 3']
584 """
585
586
587 from ansible.module_utils.basic import AnsibleModule
588 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.poe.poe import PoeArgs
589 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.poe.poe import Poe
590
591
592 def main():
593 """
594 Main entry point for module execution
595
596 :returns: the result form module invocation
597 """
598 module = AnsibleModule(argument_spec=PoeArgs.argument_spec,
599 supports_check_mode=True)
600
601 result = Poe(module).execute_module()
602 module.exit_json(**result)
603
604
605 if __name__ == '__main__':
606 main()