1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 32973963eSXiaochao Ma #pragma once 42973963eSXiaochao Ma 52973963eSXiaochao Ma #include "app.hpp" 6539d8c6bSEd Tanous #include "generated/enums/resource.hpp" 7ce05f6c4SNan Zhou #include "logging.hpp" 82973963eSXiaochao Ma #include "query.hpp" 92973963eSXiaochao Ma #include "registries/privilege_registry.hpp" 102973963eSXiaochao Ma #include "utils/chassis_utils.hpp" 112973963eSXiaochao Ma #include "utils/json_utils.hpp" 122973963eSXiaochao Ma 13ef4c65b7SEd Tanous #include <boost/url/format.hpp> 14ef4c65b7SEd Tanous 15ce05f6c4SNan Zhou #include <optional> 16ce05f6c4SNan Zhou #include <string> 17ce05f6c4SNan Zhou 182973963eSXiaochao Ma namespace redfish 192973963eSXiaochao Ma { 202973963eSXiaochao Ma 212973963eSXiaochao Ma inline void doThermalSubsystemCollection( 222973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 232973963eSXiaochao Ma const std::string& chassisId, 242973963eSXiaochao Ma const std::optional<std::string>& validChassisPath) 252973963eSXiaochao Ma { 262973963eSXiaochao Ma if (!validChassisPath) 272973963eSXiaochao Ma { 2862598e31SEd Tanous BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId); 292973963eSXiaochao Ma messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 302973963eSXiaochao Ma return; 312973963eSXiaochao Ma } 321aee751cSGeorge Liu 331aee751cSGeorge Liu asyncResp->res.addHeader( 341aee751cSGeorge Liu boost::beast::http::field::link, 351aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); 362973963eSXiaochao Ma asyncResp->res.jsonValue["@odata.type"] = 372973963eSXiaochao Ma "#ThermalSubsystem.v1_0_0.ThermalSubsystem"; 382973963eSXiaochao Ma asyncResp->res.jsonValue["Name"] = "Thermal Subsystem"; 392973963eSXiaochao Ma asyncResp->res.jsonValue["Id"] = "ThermalSubsystem"; 402973963eSXiaochao Ma 41ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 42ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId); 432973963eSXiaochao Ma 449516f41fSGeorge Liu asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format( 459516f41fSGeorge Liu "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId); 469516f41fSGeorge Liu 475ae1f7f3Szhanghch05 asyncResp->res.jsonValue["ThermalMetrics"]["@odata.id"] = 485ae1f7f3Szhanghch05 boost::urls::format( 495ae1f7f3Szhanghch05 "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics", 505ae1f7f3Szhanghch05 chassisId); 515ae1f7f3Szhanghch05 52539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; 53539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; 542973963eSXiaochao Ma } 552973963eSXiaochao Ma 561aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead( 572973963eSXiaochao Ma App& app, const crow::Request& req, 582973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 591aee751cSGeorge Liu const std::string& chassisId) 602973963eSXiaochao Ma { 612973963eSXiaochao Ma if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 622973963eSXiaochao Ma { 632973963eSXiaochao Ma return; 642973963eSXiaochao Ma } 651aee751cSGeorge Liu 661aee751cSGeorge Liu auto respHandler = [asyncResp, chassisId]( 671aee751cSGeorge Liu const std::optional<std::string>& validChassisPath) { 681aee751cSGeorge Liu if (!validChassisPath) 691aee751cSGeorge Liu { 701aee751cSGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 711aee751cSGeorge Liu return; 721aee751cSGeorge Liu } 731aee751cSGeorge Liu asyncResp->res.addHeader( 741aee751cSGeorge Liu boost::beast::http::field::link, 751aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); 761aee751cSGeorge Liu }; 771aee751cSGeorge Liu redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 781aee751cSGeorge Liu std::bind_front(respHandler)); 791aee751cSGeorge Liu } 801aee751cSGeorge Liu 811aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet( 821aee751cSGeorge Liu App& app, const crow::Request& req, 831aee751cSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 841aee751cSGeorge Liu const std::string& chassisId) 851aee751cSGeorge Liu { 861aee751cSGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 871aee751cSGeorge Liu { 881aee751cSGeorge Liu return; 891aee751cSGeorge Liu } 902973963eSXiaochao Ma 912973963eSXiaochao Ma redfish::chassis_utils::getValidChassisPath( 922973963eSXiaochao Ma asyncResp, chassisId, 932973963eSXiaochao Ma std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId)); 942973963eSXiaochao Ma } 952973963eSXiaochao Ma 962973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app) 972973963eSXiaochao Ma { 982973963eSXiaochao Ma BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 991aee751cSGeorge Liu .privileges(redfish::privileges::headThermalSubsystem) 1001aee751cSGeorge Liu .methods(boost::beast::http::verb::head)(std::bind_front( 1011aee751cSGeorge Liu handleThermalSubsystemCollectionHead, std::ref(app))); 1021aee751cSGeorge Liu 1031aee751cSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 1042973963eSXiaochao Ma .privileges(redfish::privileges::getThermalSubsystem) 1052973963eSXiaochao Ma .methods(boost::beast::http::verb::get)(std::bind_front( 1062973963eSXiaochao Ma handleThermalSubsystemCollectionGet, std::ref(app))); 1072973963eSXiaochao Ma } 1082973963eSXiaochao Ma 1092973963eSXiaochao Ma } // namespace redfish 110