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