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 10*ef4c65b7SEd Tanous #include <boost/url/format.hpp> 11*ef4c65b7SEd Tanous 12ce05f6c4SNan Zhou #include <optional> 13ce05f6c4SNan Zhou #include <string> 14ce05f6c4SNan Zhou 152973963eSXiaochao Ma namespace redfish 162973963eSXiaochao Ma { 172973963eSXiaochao Ma 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 { 25a7405d5fSGunnar Mills 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 38*ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 39*ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId); 402973963eSXiaochao Ma 412973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 422973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 432973963eSXiaochao Ma } 442973963eSXiaochao Ma 451aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead( 462973963eSXiaochao Ma App& app, const crow::Request& req, 472973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 481aee751cSGeorge Liu const std::string& chassisId) 492973963eSXiaochao Ma { 502973963eSXiaochao Ma if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 512973963eSXiaochao Ma { 522973963eSXiaochao Ma return; 532973963eSXiaochao Ma } 541aee751cSGeorge Liu 551aee751cSGeorge Liu auto respHandler = [asyncResp, chassisId]( 561aee751cSGeorge Liu const std::optional<std::string>& validChassisPath) { 571aee751cSGeorge Liu if (!validChassisPath) 581aee751cSGeorge Liu { 591aee751cSGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 601aee751cSGeorge Liu return; 611aee751cSGeorge Liu } 621aee751cSGeorge Liu asyncResp->res.addHeader( 631aee751cSGeorge Liu boost::beast::http::field::link, 641aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); 651aee751cSGeorge Liu }; 661aee751cSGeorge Liu redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 671aee751cSGeorge Liu std::bind_front(respHandler)); 681aee751cSGeorge Liu } 691aee751cSGeorge Liu 701aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet( 711aee751cSGeorge Liu App& app, const crow::Request& req, 721aee751cSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 731aee751cSGeorge Liu const std::string& chassisId) 741aee751cSGeorge Liu { 751aee751cSGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 761aee751cSGeorge Liu { 771aee751cSGeorge Liu return; 781aee751cSGeorge Liu } 792973963eSXiaochao Ma 802973963eSXiaochao Ma redfish::chassis_utils::getValidChassisPath( 812973963eSXiaochao Ma asyncResp, chassisId, 822973963eSXiaochao Ma std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId)); 832973963eSXiaochao Ma } 842973963eSXiaochao Ma 852973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app) 862973963eSXiaochao Ma { 872973963eSXiaochao Ma BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 881aee751cSGeorge Liu .privileges(redfish::privileges::headThermalSubsystem) 891aee751cSGeorge Liu .methods(boost::beast::http::verb::head)(std::bind_front( 901aee751cSGeorge Liu handleThermalSubsystemCollectionHead, std::ref(app))); 911aee751cSGeorge Liu 921aee751cSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 932973963eSXiaochao Ma .privileges(redfish::privileges::getThermalSubsystem) 942973963eSXiaochao Ma .methods(boost::beast::http::verb::get)(std::bind_front( 952973963eSXiaochao Ma handleThermalSubsystemCollectionGet, std::ref(app))); 962973963eSXiaochao Ma } 972973963eSXiaochao Ma 982973963eSXiaochao Ma } // namespace redfish 99