blob: 5365cb5a159823e7223bac051353e04f89d1465a [file] [log] [blame]
Xiaochao Ma29739632021-03-02 15:53:13 +08001#pragma once
2
3#include "app.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07004#include "generated/enums/resource.hpp"
Nan Zhouce05f6c2022-11-09 21:41:18 +00005#include "logging.hpp"
Xiaochao Ma29739632021-03-02 15:53:13 +08006#include "query.hpp"
7#include "registries/privilege_registry.hpp"
8#include "utils/chassis_utils.hpp"
9#include "utils/json_utils.hpp"
10
Ed Tanousef4c65b2023-04-24 15:28:50 -070011#include <boost/url/format.hpp>
12
Nan Zhouce05f6c2022-11-09 21:41:18 +000013#include <optional>
14#include <string>
15
Xiaochao Ma29739632021-03-02 15:53:13 +080016namespace redfish
17{
18
19inline 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 Tanous62598e32023-07-17 17:06:25 -070026 BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080027 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
28 return;
29 }
George Liu1aee7512022-11-16 11:12:21 +080030
31 asyncResp->res.addHeader(
32 boost::beast::http::field::link,
33 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
Xiaochao Ma29739632021-03-02 15:53:13 +080034 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 Tanousef4c65b2023-04-24 15:28:50 -070039 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
40 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080041
George Liu9516f412022-09-29 17:21:41 +080042 asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
43 "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
44
zhanghch055ae1f7f2021-03-08 19:04:35 +080045 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
46 boost::urls::format(
47 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
48 chassisId);
49
Ed Tanous539d8c62024-06-19 14:38:27 -070050 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
51 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Xiaochao Ma29739632021-03-02 15:53:13 +080052}
53
George Liu1aee7512022-11-16 11:12:21 +080054inline void handleThermalSubsystemCollectionHead(
Xiaochao Ma29739632021-03-02 15:53:13 +080055 App& app, const crow::Request& req,
56 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
George Liu1aee7512022-11-16 11:12:21 +080057 const std::string& chassisId)
Xiaochao Ma29739632021-03-02 15:53:13 +080058{
59 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
60 {
61 return;
62 }
George Liu1aee7512022-11-16 11:12:21 +080063
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
79inline 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 Ma29739632021-03-02 15:53:13 +080088
89 redfish::chassis_utils::getValidChassisPath(
90 asyncResp, chassisId,
91 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
92}
93
94inline void requestRoutesThermalSubsystem(App& app)
95{
96 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
George Liu1aee7512022-11-16 11:12:21 +080097 .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 Ma29739632021-03-02 15:53:13 +0800102 .privileges(redfish::privileges::getThermalSubsystem)
103 .methods(boost::beast::http::verb::get)(std::bind_front(
104 handleThermalSubsystemCollectionGet, std::ref(app)));
105}
106
107} // namespace redfish