blob: 9574228b197018e2c32bc1c72c81cf30c172ec07 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Xiaochao Ma29739632021-03-02 15:53:13 +08003#pragma once
4
5#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
7#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07008#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "http_request.hpp"
Nan Zhouce05f6c2022-11-09 21:41:18 +000010#include "logging.hpp"
Xiaochao Ma29739632021-03-02 15:53:13 +080011#include "query.hpp"
12#include "registries/privilege_registry.hpp"
13#include "utils/chassis_utils.hpp"
Xiaochao Ma29739632021-03-02 15:53:13 +080014
Ed Tanousd7857202025-01-28 15:32:26 -080015#include <boost/beast/http/field.hpp>
16#include <boost/beast/http/verb.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070017#include <boost/url/format.hpp>
18
Ed Tanousd7857202025-01-28 15:32:26 -080019#include <functional>
20#include <memory>
Nan Zhouce05f6c2022-11-09 21:41:18 +000021#include <optional>
22#include <string>
23
Xiaochao Ma29739632021-03-02 15:53:13 +080024namespace redfish
25{
26
27inline 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 Tanous62598e32023-07-17 17:06:25 -070034 BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080035 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
36 return;
37 }
George Liu1aee7512022-11-16 11:12:21 +080038
39 asyncResp->res.addHeader(
40 boost::beast::http::field::link,
41 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
Xiaochao Ma29739632021-03-02 15:53:13 +080042 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 Tanousef4c65b2023-04-24 15:28:50 -070047 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
48 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080049
George Liu9516f412022-09-29 17:21:41 +080050 asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
51 "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
52
zhanghch055ae1f7f2021-03-08 19:04:35 +080053 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
54 boost::urls::format(
55 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
56 chassisId);
57
Ed Tanous539d8c62024-06-19 14:38:27 -070058 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
59 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Xiaochao Ma29739632021-03-02 15:53:13 +080060}
61
George Liu1aee7512022-11-16 11:12:21 +080062inline void handleThermalSubsystemCollectionHead(
Xiaochao Ma29739632021-03-02 15:53:13 +080063 App& app, const crow::Request& req,
64 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
George Liu1aee7512022-11-16 11:12:21 +080065 const std::string& chassisId)
Xiaochao Ma29739632021-03-02 15:53:13 +080066{
67 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
68 {
69 return;
70 }
George Liu1aee7512022-11-16 11:12:21 +080071
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
87inline 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 Ma29739632021-03-02 15:53:13 +080096
97 redfish::chassis_utils::getValidChassisPath(
98 asyncResp, chassisId,
99 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
100}
101
102inline void requestRoutesThermalSubsystem(App& app)
103{
104 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
George Liu1aee7512022-11-16 11:12:21 +0800105 .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 Ma29739632021-03-02 15:53:13 +0800110 .privileges(redfish::privileges::getThermalSubsystem)
111 .methods(boost::beast::http::verb::get)(std::bind_front(
112 handleThermalSubsystemCollectionGet, std::ref(app)));
113}
114
115} // namespace redfish