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