Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "app.hpp" |
Nan Zhou | ce05f6c | 2022-11-09 21:41:18 +0000 | [diff] [blame] | 4 | #include "logging.hpp" |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 5 | #include "query.hpp" |
| 6 | #include "registries/privilege_registry.hpp" |
| 7 | #include "utils/chassis_utils.hpp" |
| 8 | #include "utils/json_utils.hpp" |
| 9 | |
Nan Zhou | ce05f6c | 2022-11-09 21:41:18 +0000 | [diff] [blame] | 10 | #include <optional> |
| 11 | #include <string> |
| 12 | |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 13 | namespace redfish |
| 14 | { |
| 15 | |
| 16 | inline void doThermalSubsystemCollection( |
| 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 | { |
| 23 | BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId; |
| 24 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 25 | return; |
| 26 | } |
George Liu | 1aee751 | 2022-11-16 11:12:21 +0800 | [diff] [blame] | 27 | |
| 28 | asyncResp->res.addHeader( |
| 29 | boost::beast::http::field::link, |
| 30 | "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 31 | asyncResp->res.jsonValue["@odata.type"] = |
| 32 | "#ThermalSubsystem.v1_0_0.ThermalSubsystem"; |
| 33 | asyncResp->res.jsonValue["Name"] = "Thermal Subsystem"; |
| 34 | asyncResp->res.jsonValue["Id"] = "ThermalSubsystem"; |
| 35 | |
| 36 | asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( |
| 37 | "redfish", "v1", "Chassis", chassisId, "ThermalSubsystem"); |
| 38 | |
| 39 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 40 | asyncResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 41 | } |
| 42 | |
George Liu | 1aee751 | 2022-11-16 11:12:21 +0800 | [diff] [blame] | 43 | inline void handleThermalSubsystemCollectionHead( |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 44 | App& app, const crow::Request& req, |
| 45 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
George Liu | 1aee751 | 2022-11-16 11:12:21 +0800 | [diff] [blame] | 46 | const std::string& chassisId) |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 47 | { |
| 48 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 49 | { |
| 50 | return; |
| 51 | } |
George Liu | 1aee751 | 2022-11-16 11:12:21 +0800 | [diff] [blame] | 52 | |
| 53 | auto respHandler = [asyncResp, chassisId]( |
| 54 | const std::optional<std::string>& validChassisPath) { |
| 55 | if (!validChassisPath) |
| 56 | { |
| 57 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 58 | return; |
| 59 | } |
| 60 | asyncResp->res.addHeader( |
| 61 | boost::beast::http::field::link, |
| 62 | "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); |
| 63 | }; |
| 64 | redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, |
| 65 | std::bind_front(respHandler)); |
| 66 | } |
| 67 | |
| 68 | inline void handleThermalSubsystemCollectionGet( |
| 69 | App& app, const crow::Request& req, |
| 70 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 71 | const std::string& chassisId) |
| 72 | { |
| 73 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 74 | { |
| 75 | return; |
| 76 | } |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 77 | |
| 78 | redfish::chassis_utils::getValidChassisPath( |
| 79 | asyncResp, chassisId, |
| 80 | std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId)); |
| 81 | } |
| 82 | |
| 83 | inline void requestRoutesThermalSubsystem(App& app) |
| 84 | { |
| 85 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") |
George Liu | 1aee751 | 2022-11-16 11:12:21 +0800 | [diff] [blame] | 86 | .privileges(redfish::privileges::headThermalSubsystem) |
| 87 | .methods(boost::beast::http::verb::head)(std::bind_front( |
| 88 | handleThermalSubsystemCollectionHead, std::ref(app))); |
| 89 | |
| 90 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 91 | .privileges(redfish::privileges::getThermalSubsystem) |
| 92 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 93 | handleThermalSubsystemCollectionGet, std::ref(app))); |
| 94 | } |
| 95 | |
| 96 | } // namespace redfish |