Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/idrac_utils/info/powersupply.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Dell OpenManage Ansible Modules
4 # Version 9.12.0
5 # Copyright (C) 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
6
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
28 GET_IDRAC_POWER_SUPPLY_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1/PowerSubsystem/PowerSupplies"
29 NA = "Not Available"
30 RED_TYPE_MAPPING = {
31 "N+1": "2",
32 "Sparing": "4",
33 "Input Power Redundancy": "32768"
34 }
35
36
37 class IDRACPowerSupplyInfo(object):
38 def __init__(self, idrac):
39 self.idrac = idrac
40
41 def get_power_supply_links(self):
42 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_POWER_SUPPLY_DETAILS_URI)
43 power_supply_links_list = []
44 if response.status_code == 200:
45 members = response.json_data.get("Members")
46 for each in members:
47 power_supply_links_list.append(each.get("@odata.id"))
48 return power_supply_links_list
49
50 def get_red_type_set(self, response, output):
51 red_type_list = response.get("Oem", {}).\
52 get("Dell", {}).get("DellPowerSupplyView", {}).\
53 get("RedTypeOfSet")
54 if red_type_list:
55 mapped_red_type_list = []
56 for x in red_type_list:
57 if x is not None:
58 mapped_red_type_list.append(RED_TYPE_MAPPING.get(x, NA))
59 if len(mapped_red_type_list) > 0:
60 output["RedTypeOfSet"] = ",".join(mapped_red_type_list)
61 else:
62 output["RedTypeOfSet"] = NA
63 else:
64 output["RedTypeOfSet"] = NA
65
66 def get_power_supply_details(self, memory_link):
67 response = self.idrac.invoke_request(method='GET', uri=memory_link)
68 output = {}
69 if response.status_code == 200:
70 output["DetailedState"] = \
71 response.json_data.get("Oem", {}).get("Dell", {}).\
72 get("DellPowerSupplyView", {}).get("DetailedState", NA)
73 output["DeviceDescription"] = response.json_data.get("Oem", {}).\
74 get("Dell", {}).get("DellPowerSupplyView", {}).\
75 get("DeviceDescription", NA)
76 output["FQDD"] = response.json_data.get("Id", NA)
77 output["Key"] = response.json_data.get("Id", NA)
78 output["Name"] = response.json_data.get("Name", NA)
79 output["FirmwareVersion"] = \
80 response.json_data.get("FirmwareVersion", NA)
81 output["Model"] = response.json_data.get("Model", NA)
82 output["InputVoltage"] = NA
83 output["Manufacturer"] = \
84 response.json_data.get("Manufacturer", NA)
85 output["PartNumber"] = response.json_data.get("PartNumber", NA)
86 output["PowerSupplySensorState"] = NA
87 if response.json_data.get("Status", {}).get("Health") == "OK":
88 output["PrimaryStatus"] = "Healthy"
89 else:
90 output["PrimaryStatus"] = response.json_data.\
91 get("Status", {}).get("Health", NA)
92 output["RAIDState"] = NA
93 maxinputwatt = \
94 response.json_data.get("Oem", {}).get("Dell", {}).\
95 get("DellPowerSupplyView", {}).\
96 get("Range1MaxInputPowerWatts")
97 if maxinputwatt:
98 output["Range1MaxInputPower"] = str(maxinputwatt) + " W"
99 else:
100 output["Range1MaxInputPower"] = NA
101 output["RedMinNumberNeeded"] = \
102 response.json_data.get("Oem", {}).get("Dell", {}).\
103 get("DellPowerSupplyView", {}).get("RedMinNumberNeeded", NA)
104 output["SerialNumber"] = \
105 response.json_data.get("SerialNumber", NA)
106 if response.json_data.get("PowerCapacityWatts"):
107 output["TotalOutputPower"] = \
108 str(response.json_data.get("PowerCapacityWatts")) + " W"
109 else:
110 output["TotalOutputPower"] = NA
111 output["Type"] = response.json_data.get("PowerSupplyType", NA)
112 output["powerSupplyStateCapabilitiesUnique"] = \
113 response.json_data.get("Oem", {}).get("Dell", {}).\
114 get("DellPowerSupplyView", {}).\
115 get("powerSupplyStateCapabilitiesUnique", NA)
116 output["Redundancy"] = response.json_data.get("Oem", {}).\
117 get("Dell", {}).get("DellPowerSupplyView", {}).\
118 get("RedundancyStatus", NA)
119 self.get_red_type_set(response.json_data, output)
120 return output
121
122 def get_power_supply_info(self):
123 power_supply_output = []
124 power_supply_links_list = self.get_power_supply_links()
125 for each_link in power_supply_links_list:
126 power_supply_output.append(self.get_power_supply_details(each_link))
127 return power_supply_output