12973963eSXiaochao Ma #pragma once
22973963eSXiaochao Ma
32973963eSXiaochao Ma #include "app.hpp"
4ce05f6c4SNan Zhou #include "logging.hpp"
52973963eSXiaochao Ma #include "query.hpp"
62973963eSXiaochao Ma #include "registries/privilege_registry.hpp"
72973963eSXiaochao Ma #include "utils/chassis_utils.hpp"
82973963eSXiaochao Ma #include "utils/json_utils.hpp"
92973963eSXiaochao Ma
10ef4c65b7SEd Tanous #include <boost/url/format.hpp>
11ef4c65b7SEd Tanous
12ce05f6c4SNan Zhou #include <optional>
13ce05f6c4SNan Zhou #include <string>
14ce05f6c4SNan Zhou
152973963eSXiaochao Ma namespace redfish
162973963eSXiaochao Ma {
172973963eSXiaochao Ma
doThermalSubsystemCollection(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId,const std::optional<std::string> & validChassisPath)182973963eSXiaochao Ma inline void doThermalSubsystemCollection(
192973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
202973963eSXiaochao Ma const std::string& chassisId,
212973963eSXiaochao Ma const std::optional<std::string>& validChassisPath)
222973963eSXiaochao Ma {
232973963eSXiaochao Ma if (!validChassisPath)
242973963eSXiaochao Ma {
2562598e31SEd Tanous BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
262973963eSXiaochao Ma messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
272973963eSXiaochao Ma return;
282973963eSXiaochao Ma }
291aee751cSGeorge Liu
301aee751cSGeorge Liu asyncResp->res.addHeader(
311aee751cSGeorge Liu boost::beast::http::field::link,
321aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
332973963eSXiaochao Ma asyncResp->res.jsonValue["@odata.type"] =
342973963eSXiaochao Ma "#ThermalSubsystem.v1_0_0.ThermalSubsystem";
352973963eSXiaochao Ma asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
362973963eSXiaochao Ma asyncResp->res.jsonValue["Id"] = "ThermalSubsystem";
372973963eSXiaochao Ma
38ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
39ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
402973963eSXiaochao Ma
419516f41fSGeorge Liu asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
429516f41fSGeorge Liu "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
439516f41fSGeorge Liu
44*5ae1f7f3Szhanghch05 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
45*5ae1f7f3Szhanghch05 boost::urls::format(
46*5ae1f7f3Szhanghch05 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
47*5ae1f7f3Szhanghch05 chassisId);
48*5ae1f7f3Szhanghch05
492973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
502973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["Health"] = "OK";
512973963eSXiaochao Ma }
522973963eSXiaochao Ma
handleThermalSubsystemCollectionHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)531aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead(
542973963eSXiaochao Ma App& app, const crow::Request& req,
552973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
561aee751cSGeorge Liu const std::string& chassisId)
572973963eSXiaochao Ma {
582973963eSXiaochao Ma if (!redfish::setUpRedfishRoute(app, req, asyncResp))
592973963eSXiaochao Ma {
602973963eSXiaochao Ma return;
612973963eSXiaochao Ma }
621aee751cSGeorge Liu
631aee751cSGeorge Liu auto respHandler = [asyncResp, chassisId](
641aee751cSGeorge Liu const std::optional<std::string>& validChassisPath) {
651aee751cSGeorge Liu if (!validChassisPath)
661aee751cSGeorge Liu {
671aee751cSGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
681aee751cSGeorge Liu return;
691aee751cSGeorge Liu }
701aee751cSGeorge Liu asyncResp->res.addHeader(
711aee751cSGeorge Liu boost::beast::http::field::link,
721aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
731aee751cSGeorge Liu };
741aee751cSGeorge Liu redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
751aee751cSGeorge Liu std::bind_front(respHandler));
761aee751cSGeorge Liu }
771aee751cSGeorge Liu
handleThermalSubsystemCollectionGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)781aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet(
791aee751cSGeorge Liu App& app, const crow::Request& req,
801aee751cSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
811aee751cSGeorge Liu const std::string& chassisId)
821aee751cSGeorge Liu {
831aee751cSGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp))
841aee751cSGeorge Liu {
851aee751cSGeorge Liu return;
861aee751cSGeorge Liu }
872973963eSXiaochao Ma
882973963eSXiaochao Ma redfish::chassis_utils::getValidChassisPath(
892973963eSXiaochao Ma asyncResp, chassisId,
902973963eSXiaochao Ma std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
912973963eSXiaochao Ma }
922973963eSXiaochao Ma
requestRoutesThermalSubsystem(App & app)932973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app)
942973963eSXiaochao Ma {
952973963eSXiaochao Ma BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
961aee751cSGeorge Liu .privileges(redfish::privileges::headThermalSubsystem)
971aee751cSGeorge Liu .methods(boost::beast::http::verb::head)(std::bind_front(
981aee751cSGeorge Liu handleThermalSubsystemCollectionHead, std::ref(app)));
991aee751cSGeorge Liu
1001aee751cSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
1012973963eSXiaochao Ma .privileges(redfish::privileges::getThermalSubsystem)
1022973963eSXiaochao Ma .methods(boost::beast::http::verb::get)(std::bind_front(
1032973963eSXiaochao Ma handleThermalSubsystemCollectionGet, std::ref(app)));
1042973963eSXiaochao Ma }
1052973963eSXiaochao Ma
1062973963eSXiaochao Ma } // namespace redfish
107