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