Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "app.hpp" |
Nan Zhou | ca9e6be | 2022-11-08 17:28:35 +0000 | [diff] [blame] | 4 | #include "logging.hpp" |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 5 | #include "query.hpp" |
| 6 | #include "registries/privilege_registry.hpp" |
| 7 | #include "utils/chassis_utils.hpp" |
| 8 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 9 | #include <boost/url/format.hpp> |
| 10 | |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <optional> |
| 13 | #include <string> |
| 14 | |
| 15 | namespace redfish |
| 16 | { |
| 17 | |
| 18 | inline void doPowerSubsystemCollection( |
| 19 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 20 | const std::string& chassisId, |
| 21 | const std::optional<std::string>& validChassisPath) |
| 22 | { |
| 23 | if (!validChassisPath) |
| 24 | { |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 25 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 26 | return; |
| 27 | } |
| 28 | |
George Liu | 2ea468a | 2022-10-26 13:52:47 +0800 | [diff] [blame] | 29 | asyncResp->res.addHeader( |
| 30 | boost::beast::http::field::link, |
| 31 | "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 32 | asyncResp->res.jsonValue["@odata.type"] = |
| 33 | "#PowerSubsystem.v1_1_0.PowerSubsystem"; |
| 34 | asyncResp->res.jsonValue["Name"] = "Power Subsystem"; |
| 35 | asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 36 | asyncResp->res.jsonValue["@odata.id"] = |
| 37 | boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId); |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 38 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 39 | asyncResp->res.jsonValue["Status"]["Health"] = "OK"; |
George Liu | a721002 | 2022-10-05 15:44:11 +0800 | [diff] [blame] | 40 | asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 41 | boost::urls::format( |
| 42 | "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId); |
George Liu | 2ea468a | 2022-10-26 13:52:47 +0800 | [diff] [blame] | 43 | } |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 44 | |
George Liu | 2ea468a | 2022-10-26 13:52:47 +0800 | [diff] [blame] | 45 | inline void handlePowerSubsystemCollectionHead( |
| 46 | App& app, const crow::Request& req, |
| 47 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 48 | const std::string& chassisId) |
| 49 | { |
| 50 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 51 | { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | auto respHandler = [asyncResp, chassisId]( |
| 56 | const std::optional<std::string>& validChassisPath) { |
| 57 | if (!validChassisPath) |
| 58 | { |
| 59 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 60 | return; |
| 61 | } |
| 62 | asyncResp->res.addHeader( |
| 63 | boost::beast::http::field::link, |
| 64 | "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); |
| 65 | }; |
| 66 | redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, |
| 67 | std::move(respHandler)); |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | inline void handlePowerSubsystemCollectionGet( |
| 71 | App& app, const crow::Request& req, |
| 72 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 73 | const std::string& chassisId) |
| 74 | { |
| 75 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 76 | { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | redfish::chassis_utils::getValidChassisPath( |
| 81 | asyncResp, chassisId, |
| 82 | std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId)); |
| 83 | } |
| 84 | |
| 85 | inline void requestRoutesPowerSubsystem(App& app) |
| 86 | { |
| 87 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") |
George Liu | 2ea468a | 2022-10-26 13:52:47 +0800 | [diff] [blame] | 88 | .privileges(redfish::privileges::headPowerSubsystem) |
| 89 | .methods(boost::beast::http::verb::head)( |
| 90 | std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app))); |
| 91 | |
| 92 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 93 | .privileges(redfish::privileges::getPowerSubsystem) |
| 94 | .methods(boost::beast::http::verb::get)( |
| 95 | std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); |
| 96 | } |
| 97 | |
| 98 | } // namespace redfish |