blob: 81407bd1c8feccf7b93d455ecea2ef6a68947a30 [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 Tanous539d8c62024-06-19 14:38:27 -07006#include "generated/enums/resource.hpp"
Nan Zhouce05f6c2022-11-09 21:41:18 +00007#include "logging.hpp"
Xiaochao Ma29739632021-03-02 15:53:13 +08008#include "query.hpp"
9#include "registries/privilege_registry.hpp"
10#include "utils/chassis_utils.hpp"
11#include "utils/json_utils.hpp"
12
Ed Tanousef4c65b2023-04-24 15:28:50 -070013#include <boost/url/format.hpp>
14
Nan Zhouce05f6c2022-11-09 21:41:18 +000015#include <optional>
16#include <string>
17
Xiaochao Ma29739632021-03-02 15:53:13 +080018namespace redfish
19{
20
21inline 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 Tanous62598e32023-07-17 17:06:25 -070028 BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080029 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
30 return;
31 }
George Liu1aee7512022-11-16 11:12:21 +080032
33 asyncResp->res.addHeader(
34 boost::beast::http::field::link,
35 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
Xiaochao Ma29739632021-03-02 15:53:13 +080036 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 Tanousef4c65b2023-04-24 15:28:50 -070041 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
42 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080043
George Liu9516f412022-09-29 17:21:41 +080044 asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
45 "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
46
zhanghch055ae1f7f2021-03-08 19:04:35 +080047 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
48 boost::urls::format(
49 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
50 chassisId);
51
Ed Tanous539d8c62024-06-19 14:38:27 -070052 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
53 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Xiaochao Ma29739632021-03-02 15:53:13 +080054}
55
George Liu1aee7512022-11-16 11:12:21 +080056inline void handleThermalSubsystemCollectionHead(
Xiaochao Ma29739632021-03-02 15:53:13 +080057 App& app, const crow::Request& req,
58 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
George Liu1aee7512022-11-16 11:12:21 +080059 const std::string& chassisId)
Xiaochao Ma29739632021-03-02 15:53:13 +080060{
61 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
62 {
63 return;
64 }
George Liu1aee7512022-11-16 11:12:21 +080065
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
81inline 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 Ma29739632021-03-02 15:53:13 +080090
91 redfish::chassis_utils::getValidChassisPath(
92 asyncResp, chassisId,
93 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
94}
95
96inline void requestRoutesThermalSubsystem(App& app)
97{
98 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
George Liu1aee7512022-11-16 11:12:21 +080099 .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 Ma29739632021-03-02 15:53:13 +0800104 .privileges(redfish::privileges::getThermalSubsystem)
105 .methods(boost::beast::http::verb::get)(std::bind_front(
106 handleThermalSubsystemCollectionGet, std::ref(app)));
107}
108
109} // namespace redfish