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