blob: 6528a55fc64922842d0030b6dcbd457e9cd5e88e [file] [log] [blame]
Xiaochao Ma29739632021-03-02 15:53:13 +08001#pragma once
2
3#include "app.hpp"
Nan Zhouce05f6c2022-11-09 21:41:18 +00004#include "logging.hpp"
Xiaochao Ma29739632021-03-02 15:53:13 +08005#include "query.hpp"
6#include "registries/privilege_registry.hpp"
7#include "utils/chassis_utils.hpp"
8#include "utils/json_utils.hpp"
9
Ed Tanousef4c65b2023-04-24 15:28:50 -070010#include <boost/url/format.hpp>
11
Nan Zhouce05f6c2022-11-09 21:41:18 +000012#include <optional>
13#include <string>
14
Xiaochao Ma29739632021-03-02 15:53:13 +080015namespace redfish
16{
17
18inline void doThermalSubsystemCollection(
19 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
20 const std::string& chassisId,
21 const std::optional<std::string>& validChassisPath)
22{
23 if (!validChassisPath)
24 {
Gunnar Millsa7405d52023-02-22 13:23:23 -060025 BMCWEB_LOG_WARNING << "Not a valid chassis ID" << chassisId;
Xiaochao Ma29739632021-03-02 15:53:13 +080026 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
27 return;
28 }
George Liu1aee7512022-11-16 11:12:21 +080029
30 asyncResp->res.addHeader(
31 boost::beast::http::field::link,
32 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
Xiaochao Ma29739632021-03-02 15:53:13 +080033 asyncResp->res.jsonValue["@odata.type"] =
34 "#ThermalSubsystem.v1_0_0.ThermalSubsystem";
35 asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
36 asyncResp->res.jsonValue["Id"] = "ThermalSubsystem";
37
Ed Tanousef4c65b2023-04-24 15:28:50 -070038 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
39 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +080040
41 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
42 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
43}
44
George Liu1aee7512022-11-16 11:12:21 +080045inline void handleThermalSubsystemCollectionHead(
Xiaochao Ma29739632021-03-02 15:53:13 +080046 App& app, const crow::Request& req,
47 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
George Liu1aee7512022-11-16 11:12:21 +080048 const std::string& chassisId)
Xiaochao Ma29739632021-03-02 15:53:13 +080049{
50 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
51 {
52 return;
53 }
George Liu1aee7512022-11-16 11:12:21 +080054
55 auto respHandler = [asyncResp, chassisId](
56 const std::optional<std::string>& validChassisPath) {
57 if (!validChassisPath)
58 {
59 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
60 return;
61 }
62 asyncResp->res.addHeader(
63 boost::beast::http::field::link,
64 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
65 };
66 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
67 std::bind_front(respHandler));
68}
69
70inline void handleThermalSubsystemCollectionGet(
71 App& app, const crow::Request& req,
72 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
73 const std::string& chassisId)
74{
75 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
76 {
77 return;
78 }
Xiaochao Ma29739632021-03-02 15:53:13 +080079
80 redfish::chassis_utils::getValidChassisPath(
81 asyncResp, chassisId,
82 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
83}
84
85inline void requestRoutesThermalSubsystem(App& app)
86{
87 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
George Liu1aee7512022-11-16 11:12:21 +080088 .privileges(redfish::privileges::headThermalSubsystem)
89 .methods(boost::beast::http::verb::head)(std::bind_front(
90 handleThermalSubsystemCollectionHead, std::ref(app)));
91
92 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
Xiaochao Ma29739632021-03-02 15:53:13 +080093 .privileges(redfish::privileges::getThermalSubsystem)
94 .methods(boost::beast::http::verb::get)(std::bind_front(
95 handleThermalSubsystemCollectionGet, std::ref(app)));
96}
97
98} // namespace redfish