xref: /openbmc/bmcweb/features/redfish/lib/thermal_subsystem.hpp (revision 539d8c6bc399e516d39bcaa18262cf206f4c1035)
12973963eSXiaochao Ma #pragma once
22973963eSXiaochao Ma 
32973963eSXiaochao Ma #include "app.hpp"
4*539d8c6bSEd Tanous #include "generated/enums/resource.hpp"
5ce05f6c4SNan Zhou #include "logging.hpp"
62973963eSXiaochao Ma #include "query.hpp"
72973963eSXiaochao Ma #include "registries/privilege_registry.hpp"
82973963eSXiaochao Ma #include "utils/chassis_utils.hpp"
92973963eSXiaochao Ma #include "utils/json_utils.hpp"
102973963eSXiaochao Ma 
11ef4c65b7SEd Tanous #include <boost/url/format.hpp>
12ef4c65b7SEd Tanous 
13ce05f6c4SNan Zhou #include <optional>
14ce05f6c4SNan Zhou #include <string>
15ce05f6c4SNan Zhou 
162973963eSXiaochao Ma namespace redfish
172973963eSXiaochao Ma {
182973963eSXiaochao Ma 
192973963eSXiaochao Ma inline void doThermalSubsystemCollection(
202973963eSXiaochao Ma     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
212973963eSXiaochao Ma     const std::string& chassisId,
222973963eSXiaochao Ma     const std::optional<std::string>& validChassisPath)
232973963eSXiaochao Ma {
242973963eSXiaochao Ma     if (!validChassisPath)
252973963eSXiaochao Ma     {
2662598e31SEd Tanous         BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
272973963eSXiaochao Ma         messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
282973963eSXiaochao Ma         return;
292973963eSXiaochao Ma     }
301aee751cSGeorge Liu 
311aee751cSGeorge Liu     asyncResp->res.addHeader(
321aee751cSGeorge Liu         boost::beast::http::field::link,
331aee751cSGeorge Liu         "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
342973963eSXiaochao Ma     asyncResp->res.jsonValue["@odata.type"] =
352973963eSXiaochao Ma         "#ThermalSubsystem.v1_0_0.ThermalSubsystem";
362973963eSXiaochao Ma     asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
372973963eSXiaochao Ma     asyncResp->res.jsonValue["Id"] = "ThermalSubsystem";
382973963eSXiaochao Ma 
39ef4c65b7SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
40ef4c65b7SEd Tanous         "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
412973963eSXiaochao Ma 
429516f41fSGeorge Liu     asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
439516f41fSGeorge Liu         "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
449516f41fSGeorge Liu 
455ae1f7f3Szhanghch05     asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] =
465ae1f7f3Szhanghch05         boost::urls::format(
475ae1f7f3Szhanghch05             "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics",
485ae1f7f3Szhanghch05             chassisId);
495ae1f7f3Szhanghch05 
50*539d8c6bSEd Tanous     asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
51*539d8c6bSEd Tanous     asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
522973963eSXiaochao Ma }
532973963eSXiaochao Ma 
541aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead(
552973963eSXiaochao Ma     App& app, const crow::Request& req,
562973963eSXiaochao Ma     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
571aee751cSGeorge Liu     const std::string& chassisId)
582973963eSXiaochao Ma {
592973963eSXiaochao Ma     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
602973963eSXiaochao Ma     {
612973963eSXiaochao Ma         return;
622973963eSXiaochao Ma     }
631aee751cSGeorge Liu 
641aee751cSGeorge Liu     auto respHandler = [asyncResp, chassisId](
651aee751cSGeorge Liu                            const std::optional<std::string>& validChassisPath) {
661aee751cSGeorge Liu         if (!validChassisPath)
671aee751cSGeorge Liu         {
681aee751cSGeorge Liu             messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
691aee751cSGeorge Liu             return;
701aee751cSGeorge Liu         }
711aee751cSGeorge Liu         asyncResp->res.addHeader(
721aee751cSGeorge Liu             boost::beast::http::field::link,
731aee751cSGeorge Liu             "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
741aee751cSGeorge Liu     };
751aee751cSGeorge Liu     redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
761aee751cSGeorge Liu                                                 std::bind_front(respHandler));
771aee751cSGeorge Liu }
781aee751cSGeorge Liu 
791aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet(
801aee751cSGeorge Liu     App& app, const crow::Request& req,
811aee751cSGeorge Liu     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
821aee751cSGeorge Liu     const std::string& chassisId)
831aee751cSGeorge Liu {
841aee751cSGeorge Liu     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
851aee751cSGeorge Liu     {
861aee751cSGeorge Liu         return;
871aee751cSGeorge Liu     }
882973963eSXiaochao Ma 
892973963eSXiaochao Ma     redfish::chassis_utils::getValidChassisPath(
902973963eSXiaochao Ma         asyncResp, chassisId,
912973963eSXiaochao Ma         std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
922973963eSXiaochao Ma }
932973963eSXiaochao Ma 
942973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app)
952973963eSXiaochao Ma {
962973963eSXiaochao Ma     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
971aee751cSGeorge Liu         .privileges(redfish::privileges::headThermalSubsystem)
981aee751cSGeorge Liu         .methods(boost::beast::http::verb::head)(std::bind_front(
991aee751cSGeorge Liu             handleThermalSubsystemCollectionHead, std::ref(app)));
1001aee751cSGeorge Liu 
1011aee751cSGeorge Liu     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
1022973963eSXiaochao Ma         .privileges(redfish::privileges::getThermalSubsystem)
1032973963eSXiaochao Ma         .methods(boost::beast::http::verb::get)(std::bind_front(
1042973963eSXiaochao Ma             handleThermalSubsystemCollectionGet, std::ref(app)));
1052973963eSXiaochao Ma }
1062973963eSXiaochao Ma 
1072973963eSXiaochao Ma } // namespace redfish
108