1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #pragma once
4
5 #include "app.hpp"
6 #include "generated/enums/resource.hpp"
7 #include "logging.hpp"
8 #include "query.hpp"
9 #include "registries/privilege_registry.hpp"
10 #include "utils/chassis_utils.hpp"
11 #include "utils/json_utils.hpp"
12
13 #include <boost/url/format.hpp>
14
15 #include <optional>
16 #include <string>
17
18 namespace redfish
19 {
20
doThermalSubsystemCollection(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId,const std::optional<std::string> & validChassisPath)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 {
28 BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
29 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
30 return;
31 }
32
33 asyncResp->res.addHeader(
34 boost::beast::http::field::link,
35 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
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
41 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
42 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
43
44 asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
45 "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
46
47 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
48 boost::urls::format(
49 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
50 chassisId);
51
52 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
53 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
54 }
55
handleThermalSubsystemCollectionHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)56 inline void handleThermalSubsystemCollectionHead(
57 App& app, const crow::Request& req,
58 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
59 const std::string& chassisId)
60 {
61 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
62 {
63 return;
64 }
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
handleThermalSubsystemCollectionGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)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 }
90
91 redfish::chassis_utils::getValidChassisPath(
92 asyncResp, chassisId,
93 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
94 }
95
requestRoutesThermalSubsystem(App & app)96 inline void requestRoutesThermalSubsystem(App& app)
97 {
98 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
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/")
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
110