blob: d86e3c30db6fd57fcab5ff1679a38955a50248ca [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
Nan Zhouce05f6c2022-11-09 21:41:18 +000010#include <optional>
11#include <string>
12
Xiaochao Ma29739632021-03-02 15:53:13 +080013namespace redfish
14{
15
16inline void doThermalSubsystemCollection(
17 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
18 const std::string& chassisId,
19 const std::optional<std::string>& validChassisPath)
20{
21 if (!validChassisPath)
22 {
23 BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId;
24 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
25 return;
26 }
George Liu1aee7512022-11-16 11:12:21 +080027
28 asyncResp->res.addHeader(
29 boost::beast::http::field::link,
30 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
Xiaochao Ma29739632021-03-02 15:53:13 +080031 asyncResp->res.jsonValue["@odata.type"] =
32 "#ThermalSubsystem.v1_0_0.ThermalSubsystem";
33 asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
34 asyncResp->res.jsonValue["Id"] = "ThermalSubsystem";
35
36 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
37 "redfish", "v1", "Chassis", chassisId, "ThermalSubsystem");
38
39 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
40 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
41}
42
George Liu1aee7512022-11-16 11:12:21 +080043inline void handleThermalSubsystemCollectionHead(
Xiaochao Ma29739632021-03-02 15:53:13 +080044 App& app, const crow::Request& req,
45 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
George Liu1aee7512022-11-16 11:12:21 +080046 const std::string& chassisId)
Xiaochao Ma29739632021-03-02 15:53:13 +080047{
48 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
49 {
50 return;
51 }
George Liu1aee7512022-11-16 11:12:21 +080052
53 auto respHandler = [asyncResp, chassisId](
54 const std::optional<std::string>& validChassisPath) {
55 if (!validChassisPath)
56 {
57 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
58 return;
59 }
60 asyncResp->res.addHeader(
61 boost::beast::http::field::link,
62 "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
63 };
64 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
65 std::bind_front(respHandler));
66}
67
68inline void handleThermalSubsystemCollectionGet(
69 App& app, const crow::Request& req,
70 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
71 const std::string& chassisId)
72{
73 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
74 {
75 return;
76 }
Xiaochao Ma29739632021-03-02 15:53:13 +080077
78 redfish::chassis_utils::getValidChassisPath(
79 asyncResp, chassisId,
80 std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
81}
82
83inline void requestRoutesThermalSubsystem(App& app)
84{
85 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
George Liu1aee7512022-11-16 11:12:21 +080086 .privileges(redfish::privileges::headThermalSubsystem)
87 .methods(boost::beast::http::verb::head)(std::bind_front(
88 handleThermalSubsystemCollectionHead, std::ref(app)));
89
90 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
Xiaochao Ma29739632021-03-02 15:53:13 +080091 .privileges(redfish::privileges::getThermalSubsystem)
92 .methods(boost::beast::http::verb::get)(std::bind_front(
93 handleThermalSubsystemCollectionGet, std::ref(app)));
94}
95
96} // namespace redfish