blob: 26ea26c93cd9cb9d14455a26741ec2db987aba0f [file] [log] [blame]
George Liua7210022022-10-05 15:44:11 +08001#pragma once
2
3#include "app.hpp"
4#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07005#include "generated/enums/resource.hpp"
George Liua7210022022-10-05 15:44:11 +08006#include "query.hpp"
7#include "registries/privilege_registry.hpp"
8#include "utils/chassis_utils.hpp"
George Liu2b45fb32022-10-05 17:00:00 +08009#include "utils/dbus_utils.hpp"
10#include "utils/json_utils.hpp"
George Liua7210022022-10-05 15:44:11 +080011
George Liu34dfcb92022-10-05 16:47:44 +080012#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070013#include <boost/url/format.hpp>
14
George Liua7210022022-10-05 15:44:11 +080015#include <memory>
16#include <optional>
17#include <string>
18
19namespace redfish
20{
21
Lakshmi Yadlapati788fe6c2023-06-21 14:39:08 -050022static constexpr std::array<std::string_view, 1> powerSupplyInterface = {
23 "xyz.openbmc_project.Inventory.Item.PowerSupply"};
24
25inline void updatePowerSupplyList(
26 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
27 const std::string& chassisId,
28 const dbus::utility::MapperGetSubTreePathsResponse& powerSupplyPaths)
George Liua7210022022-10-05 15:44:11 +080029{
George Liu00ef5dc2022-10-05 16:27:52 +080030 nlohmann::json& powerSupplyList = asyncResp->res.jsonValue["Members"];
Lakshmi Yadlapati788fe6c2023-06-21 14:39:08 -050031 for (const std::string& powerSupplyPath : powerSupplyPaths)
32 {
33 std::string powerSupplyName =
34 sdbusplus::message::object_path(powerSupplyPath).filename();
35 if (powerSupplyName.empty())
36 {
37 continue;
38 }
39
40 nlohmann::json item = nlohmann::json::object();
41 item["@odata.id"] = boost::urls::format(
42 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies/{}", chassisId,
43 powerSupplyName);
44
45 powerSupplyList.emplace_back(std::move(item));
46 }
George Liu00ef5dc2022-10-05 16:27:52 +080047 asyncResp->res.jsonValue["Members@odata.count"] = powerSupplyList.size();
George Liua7210022022-10-05 15:44:11 +080048}
49
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -050050inline void doPowerSupplyCollection(
51 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
52 const std::string& chassisId, const boost::system::error_code& ec,
53 const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths)
George Liua7210022022-10-05 15:44:11 +080054{
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -050055 if (ec)
George Liua7210022022-10-05 15:44:11 +080056 {
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -050057 if (ec.value() != EBADR)
58 {
59 BMCWEB_LOG_ERROR("DBUS response error{}", ec.value());
60 messages::internalError(asyncResp->res);
61 }
George Liua7210022022-10-05 15:44:11 +080062 return;
63 }
George Liua7210022022-10-05 15:44:11 +080064 asyncResp->res.addHeader(
65 boost::beast::http::field::link,
66 "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby");
67 asyncResp->res.jsonValue["@odata.type"] =
68 "#PowerSupplyCollection.PowerSupplyCollection";
69 asyncResp->res.jsonValue["Name"] = "Power Supply Collection";
Ed Tanousef4c65b2023-04-24 15:28:50 -070070 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
71 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId);
George Liua7210022022-10-05 15:44:11 +080072 asyncResp->res.jsonValue["Description"] =
73 "The collection of PowerSupply resource instances.";
George Liu7a2bb2c2023-04-11 10:44:33 +080074 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
75 asyncResp->res.jsonValue["Members@odata.count"] = 0;
George Liua7210022022-10-05 15:44:11 +080076
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -050077 updatePowerSupplyList(asyncResp, chassisId, subtreePaths);
George Liua7210022022-10-05 15:44:11 +080078}
79
80inline void handlePowerSupplyCollectionHead(
81 App& app, const crow::Request& req,
82 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
83 const std::string& chassisId)
84{
85 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
86 {
87 return;
88 }
89
90 redfish::chassis_utils::getValidChassisPath(
91 asyncResp, chassisId,
92 [asyncResp,
93 chassisId](const std::optional<std::string>& validChassisPath) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040094 if (!validChassisPath)
95 {
96 messages::resourceNotFound(asyncResp->res, "Chassis",
97 chassisId);
98 return;
99 }
100 asyncResp->res.addHeader(
101 boost::beast::http::field::link,
102 "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby");
103 });
George Liua7210022022-10-05 15:44:11 +0800104}
105
106inline void handlePowerSupplyCollectionGet(
107 App& app, const crow::Request& req,
108 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
109 const std::string& chassisId)
110{
111 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
112 {
113 return;
114 }
115
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500116 constexpr std::array<std::string_view, 2> chasisInterfaces = {
117 "xyz.openbmc_project.Inventory.Item.Board",
118 "xyz.openbmc_project.Inventory.Item.Chassis"};
119 const std::string reqpath = "/xyz/openbmc_project/inventory";
120
121 dbus::utility::getAssociatedSubTreePathsById(
122 chassisId, reqpath, chasisInterfaces, "powered_by",
123 powerSupplyInterface,
124 [asyncResp, chassisId](
125 const boost::system::error_code& ec,
126 const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths) {
127 doPowerSupplyCollection(asyncResp, chassisId, ec, subtreePaths);
128 });
George Liua7210022022-10-05 15:44:11 +0800129}
130
131inline void requestRoutesPowerSupplyCollection(App& app)
132{
133 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/")
134 .privileges(redfish::privileges::headPowerSupplyCollection)
135 .methods(boost::beast::http::verb::head)(
136 std::bind_front(handlePowerSupplyCollectionHead, std::ref(app)));
137
138 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/")
139 .privileges(redfish::privileges::getPowerSupplyCollection)
140 .methods(boost::beast::http::verb::get)(
141 std::bind_front(handlePowerSupplyCollectionGet, std::ref(app)));
142}
143
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500144inline void afterGetValidPowerSupplyPath(
145 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
146 const std::string& powerSupplyId, const boost::system::error_code& ec,
147 const dbus::utility::MapperGetSubTreeResponse& subtree,
148 const std::function<void(const std::string& powerSupplyPath,
149 const std::string& service)>& callback)
George Liu00ef5dc2022-10-05 16:27:52 +0800150{
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500151 if (ec)
152 {
153 if (ec.value() != EBADR)
154 {
155 BMCWEB_LOG_ERROR("DBUS response error{}", ec.value());
156 messages::internalError(asyncResp->res);
157 }
158 return;
159 }
160 for (const auto& [objectPath, service] : subtree)
161 {
162 sdbusplus::message::object_path path(objectPath);
163 if (path == powerSupplyId)
164 {
165 callback(path, service.begin()->first);
166 return;
167 }
168 }
George Liu00ef5dc2022-10-05 16:27:52 +0800169
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500170 BMCWEB_LOG_WARNING("Power supply not found: {}", powerSupplyId);
171 messages::resourceNotFound(asyncResp->res, "PowerSupplies", powerSupplyId);
George Liu00ef5dc2022-10-05 16:27:52 +0800172}
173
George Liu34dfcb92022-10-05 16:47:44 +0800174inline void getValidPowerSupplyPath(
175 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500176 const std::string& chassisId, const std::string& powerSupplyId,
177 std::function<void(const std::string& powerSupplyPath,
178 const std::string& service)>&& callback)
George Liu00ef5dc2022-10-05 16:27:52 +0800179{
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500180 constexpr std::array<std::string_view, 2> chasisInterfaces = {
181 "xyz.openbmc_project.Inventory.Item.Board",
182 "xyz.openbmc_project.Inventory.Item.Chassis"};
183 const std::string reqpath = "/xyz/openbmc_project/inventory";
184
185 dbus::utility::getAssociatedSubTreeById(
186 chassisId, reqpath, chasisInterfaces, "powered_by",
Lakshmi Yadlapati788fe6c2023-06-21 14:39:08 -0500187 powerSupplyInterface,
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500188 [asyncResp, chassisId, powerSupplyId, callback{std::move(callback)}](
Lakshmi Yadlapati788fe6c2023-06-21 14:39:08 -0500189 const boost::system::error_code& ec,
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500190 const dbus::utility::MapperGetSubTreeResponse& subtree) {
191 afterGetValidPowerSupplyPath(asyncResp, powerSupplyId, ec, subtree,
192 callback);
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400193 });
George Liu00ef5dc2022-10-05 16:27:52 +0800194}
195
196inline void
George Liu34dfcb92022-10-05 16:47:44 +0800197 getPowerSupplyState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
198 const std::string& service, const std::string& path)
199{
200 sdbusplus::asio::getProperty<bool>(
201 *crow::connections::systemBus, service, path,
202 "xyz.openbmc_project.Inventory.Item", "Present",
203 [asyncResp](const boost::system::error_code& ec, const bool value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400204 if (ec)
George Liu34dfcb92022-10-05 16:47:44 +0800205 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400206 if (ec.value() != EBADR)
207 {
208 BMCWEB_LOG_ERROR("DBUS response error for State {}",
209 ec.value());
210 messages::internalError(asyncResp->res);
211 }
212 return;
George Liu34dfcb92022-10-05 16:47:44 +0800213 }
George Liu34dfcb92022-10-05 16:47:44 +0800214
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400215 if (!value)
216 {
217 asyncResp->res.jsonValue["Status"]["State"] =
218 resource::State::Absent;
219 }
220 });
George Liu34dfcb92022-10-05 16:47:44 +0800221}
222
223inline void
224 getPowerSupplyHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
225 const std::string& service, const std::string& path)
226{
227 sdbusplus::asio::getProperty<bool>(
228 *crow::connections::systemBus, service, path,
229 "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
230 [asyncResp](const boost::system::error_code& ec, const bool value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400231 if (ec)
George Liu34dfcb92022-10-05 16:47:44 +0800232 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400233 if (ec.value() != EBADR)
234 {
235 BMCWEB_LOG_ERROR("DBUS response error for Health {}",
236 ec.value());
237 messages::internalError(asyncResp->res);
238 }
239 return;
George Liu34dfcb92022-10-05 16:47:44 +0800240 }
George Liu34dfcb92022-10-05 16:47:44 +0800241
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400242 if (!value)
243 {
244 asyncResp->res.jsonValue["Status"]["Health"] =
245 resource::Health::Critical;
246 }
247 });
George Liu34dfcb92022-10-05 16:47:44 +0800248}
249
250inline void
George Liu2b45fb32022-10-05 17:00:00 +0800251 getPowerSupplyAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
252 const std::string& service, const std::string& path)
253{
254 sdbusplus::asio::getAllProperties(
255 *crow::connections::systemBus, service, path,
256 "xyz.openbmc_project.Inventory.Decorator.Asset",
257 [asyncResp](const boost::system::error_code& ec,
258 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400259 if (ec)
George Liu2b45fb32022-10-05 17:00:00 +0800260 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400261 if (ec.value() != EBADR)
262 {
263 BMCWEB_LOG_ERROR("DBUS response error for Asset {}",
264 ec.value());
265 messages::internalError(asyncResp->res);
266 }
267 return;
George Liu2b45fb32022-10-05 17:00:00 +0800268 }
George Liu2b45fb32022-10-05 17:00:00 +0800269
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400270 const std::string* partNumber = nullptr;
271 const std::string* serialNumber = nullptr;
272 const std::string* manufacturer = nullptr;
273 const std::string* model = nullptr;
274 const std::string* sparePartNumber = nullptr;
George Liu2b45fb32022-10-05 17:00:00 +0800275
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400276 const bool success = sdbusplus::unpackPropertiesNoThrow(
277 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
278 partNumber, "SerialNumber", serialNumber, "Manufacturer",
279 manufacturer, "Model", model, "SparePartNumber",
280 sparePartNumber);
George Liu2b45fb32022-10-05 17:00:00 +0800281
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400282 if (!success)
283 {
284 messages::internalError(asyncResp->res);
285 return;
286 }
George Liu2b45fb32022-10-05 17:00:00 +0800287
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400288 if (partNumber != nullptr)
289 {
290 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
291 }
George Liu2b45fb32022-10-05 17:00:00 +0800292
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400293 if (serialNumber != nullptr)
294 {
295 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
296 }
George Liu2b45fb32022-10-05 17:00:00 +0800297
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400298 if (manufacturer != nullptr)
299 {
300 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
301 }
George Liu2b45fb32022-10-05 17:00:00 +0800302
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400303 if (model != nullptr)
304 {
305 asyncResp->res.jsonValue["Model"] = *model;
306 }
George Liu2b45fb32022-10-05 17:00:00 +0800307
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400308 // SparePartNumber is optional on D-Bus so skip if it is empty
309 if (sparePartNumber != nullptr && !sparePartNumber->empty())
310 {
311 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
312 }
313 });
George Liu2b45fb32022-10-05 17:00:00 +0800314}
315
George Liua0dba872022-10-05 17:03:20 +0800316inline void getPowerSupplyFirmwareVersion(
317 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
318 const std::string& service, const std::string& path)
319{
320 sdbusplus::asio::getProperty<std::string>(
321 *crow::connections::systemBus, service, path,
322 "xyz.openbmc_project.Software.Version", "Version",
323 [asyncResp](const boost::system::error_code& ec,
324 const std::string& value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400325 if (ec)
George Liua0dba872022-10-05 17:03:20 +0800326 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400327 if (ec.value() != EBADR)
328 {
329 BMCWEB_LOG_ERROR(
330 "DBUS response error for FirmwareVersion {}",
331 ec.value());
332 messages::internalError(asyncResp->res);
333 }
334 return;
George Liua0dba872022-10-05 17:03:20 +0800335 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400336 asyncResp->res.jsonValue["FirmwareVersion"] = value;
337 });
George Liua0dba872022-10-05 17:03:20 +0800338}
339
George Liu2b45fb32022-10-05 17:00:00 +0800340inline void
George Liu44845e52022-10-05 17:09:21 +0800341 getPowerSupplyLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
342 const std::string& service, const std::string& path)
343{
344 sdbusplus::asio::getProperty<std::string>(
345 *crow::connections::systemBus, service, path,
346 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
347 [asyncResp](const boost::system::error_code& ec,
348 const std::string& value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400349 if (ec)
George Liu44845e52022-10-05 17:09:21 +0800350 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400351 if (ec.value() != EBADR)
352 {
353 BMCWEB_LOG_ERROR("DBUS response error for Location {}",
354 ec.value());
355 messages::internalError(asyncResp->res);
356 }
357 return;
George Liu44845e52022-10-05 17:09:21 +0800358 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400359 asyncResp->res
360 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = value;
361 });
George Liu44845e52022-10-05 17:09:21 +0800362}
363
George Liuddceee02022-10-06 08:57:11 +0800364inline void handleGetEfficiencyResponse(
365 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
366 const boost::system::error_code& ec, uint32_t value)
367{
368 if (ec)
369 {
370 if (ec.value() != EBADR)
371 {
Ed Tanous62598e32023-07-17 17:06:25 -0700372 BMCWEB_LOG_ERROR("DBUS response error for DeratingFactor {}",
373 ec.value());
George Liuddceee02022-10-06 08:57:11 +0800374 messages::internalError(asyncResp->res);
375 }
376 return;
377 }
378 // The PDI default value is 0, if it hasn't been set leave off
379 if (value == 0)
380 {
381 return;
382 }
383
384 nlohmann::json::array_t efficiencyRatings;
385 nlohmann::json::object_t efficiencyPercent;
386 efficiencyPercent["EfficiencyPercent"] = value;
387 efficiencyRatings.emplace_back(std::move(efficiencyPercent));
388 asyncResp->res.jsonValue["EfficiencyRatings"] =
389 std::move(efficiencyRatings);
390}
391
392inline void handlePowerSupplyAttributesSubTreeResponse(
393 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
394 const boost::system::error_code& ec,
395 const dbus::utility::MapperGetSubTreeResponse& subtree)
396{
397 if (ec)
398 {
399 if (ec.value() != EBADR)
400 {
Ed Tanous62598e32023-07-17 17:06:25 -0700401 BMCWEB_LOG_ERROR("DBUS response error for EfficiencyPercent {}",
402 ec.value());
George Liuddceee02022-10-06 08:57:11 +0800403 messages::internalError(asyncResp->res);
404 }
405 return;
406 }
407
408 if (subtree.empty())
409 {
Ed Tanous62598e32023-07-17 17:06:25 -0700410 BMCWEB_LOG_DEBUG("Can't find Power Supply Attributes!");
George Liuddceee02022-10-06 08:57:11 +0800411 return;
412 }
413
414 if (subtree.size() != 1)
415 {
Ed Tanous62598e32023-07-17 17:06:25 -0700416 BMCWEB_LOG_ERROR(
417 "Unexpected number of paths returned by getSubTree: {}",
418 subtree.size());
George Liuddceee02022-10-06 08:57:11 +0800419 messages::internalError(asyncResp->res);
420 return;
421 }
422
423 const auto& [path, serviceMap] = *subtree.begin();
424 const auto& [service, interfaces] = *serviceMap.begin();
425 sdbusplus::asio::getProperty<uint32_t>(
426 *crow::connections::systemBus, service, path,
427 "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor",
428 [asyncResp](const boost::system::error_code& ec1, uint32_t value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400429 handleGetEfficiencyResponse(asyncResp, ec1, value);
430 });
George Liuddceee02022-10-06 08:57:11 +0800431}
432
433inline void
434 getEfficiencyPercent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
435{
436 constexpr std::array<std::string_view, 1> efficiencyIntf = {
437 "xyz.openbmc_project.Control.PowerSupplyAttributes"};
438
439 dbus::utility::getSubTree(
440 "/xyz/openbmc_project", 0, efficiencyIntf,
441 [asyncResp](const boost::system::error_code& ec,
442 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400443 handlePowerSupplyAttributesSubTreeResponse(asyncResp, ec, subtree);
444 });
George Liuddceee02022-10-06 08:57:11 +0800445}
446
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400447inline void doPowerSupplyGet(
448 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
449 const std::string& chassisId, const std::string& powerSupplyId,
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500450 const std::string& powerSupplyPath, const std::string& service)
George Liu00ef5dc2022-10-05 16:27:52 +0800451{
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500452 asyncResp->res.addHeader(
453 boost::beast::http::field::link,
454 "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby");
455 asyncResp->res.jsonValue["@odata.type"] = "#PowerSupply.v1_5_0.PowerSupply";
456 asyncResp->res.jsonValue["Name"] = "Power Supply";
457 asyncResp->res.jsonValue["Id"] = powerSupplyId;
458 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
459 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies/{}", chassisId,
460 powerSupplyId);
George Liu00ef5dc2022-10-05 16:27:52 +0800461
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500462 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
463 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
George Liu34dfcb92022-10-05 16:47:44 +0800464
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500465 getPowerSupplyState(asyncResp, service, powerSupplyPath);
466 getPowerSupplyHealth(asyncResp, service, powerSupplyPath);
467 getPowerSupplyAsset(asyncResp, service, powerSupplyPath);
468 getPowerSupplyFirmwareVersion(asyncResp, service, powerSupplyPath);
469 getPowerSupplyLocation(asyncResp, service, powerSupplyPath);
470 getEfficiencyPercent(asyncResp);
George Liu00ef5dc2022-10-05 16:27:52 +0800471}
472
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400473inline void handlePowerSupplyHead(
474 App& app, const crow::Request& req,
475 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
476 const std::string& chassisId, const std::string& powerSupplyId)
George Liu00ef5dc2022-10-05 16:27:52 +0800477{
478 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
479 {
480 return;
481 }
482
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500483 // Get the correct Path and Service that match the input parameters
484 getValidPowerSupplyPath(
485 asyncResp, chassisId, powerSupplyId,
486 [asyncResp](const std::string&, const std::string&) {
487 asyncResp->res.addHeader(
488 boost::beast::http::field::link,
489 "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby");
George Liu00ef5dc2022-10-05 16:27:52 +0800490 });
George Liu00ef5dc2022-10-05 16:27:52 +0800491}
492
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400493inline void handlePowerSupplyGet(
494 App& app, const crow::Request& req,
495 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
496 const std::string& chassisId, const std::string& powerSupplyId)
George Liu00ef5dc2022-10-05 16:27:52 +0800497{
498 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
499 {
500 return;
501 }
Lakshmi Yadlapati3e42a322024-06-26 18:28:06 -0500502 getValidPowerSupplyPath(
503 asyncResp, chassisId, powerSupplyId,
George Liu00ef5dc2022-10-05 16:27:52 +0800504 std::bind_front(doPowerSupplyGet, asyncResp, chassisId, powerSupplyId));
505}
506
507inline void requestRoutesPowerSupply(App& app)
508{
509 BMCWEB_ROUTE(
510 app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/<str>/")
511 .privileges(redfish::privileges::headPowerSupply)
512 .methods(boost::beast::http::verb::head)(
513 std::bind_front(handlePowerSupplyHead, std::ref(app)));
514
515 BMCWEB_ROUTE(
516 app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/<str>/")
517 .privileges(redfish::privileges::getPowerSupply)
518 .methods(boost::beast::http::verb::get)(
519 std::bind_front(handlePowerSupplyGet, std::ref(app)));
520}
521
George Liua7210022022-10-05 15:44:11 +0800522} // namespace redfish