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