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