177b36437SChicago Duan #pragma once 277b36437SChicago Duan 377b36437SChicago Duan #include "app.hpp" 4ca9e6be6SNan Zhou #include "logging.hpp" 577b36437SChicago Duan #include "query.hpp" 677b36437SChicago Duan #include "registries/privilege_registry.hpp" 777b36437SChicago Duan #include "utils/chassis_utils.hpp" 877b36437SChicago Duan 9*ef4c65b7SEd Tanous #include <boost/url/format.hpp> 10*ef4c65b7SEd Tanous 1177b36437SChicago Duan #include <memory> 1277b36437SChicago Duan #include <optional> 1377b36437SChicago Duan #include <string> 1477b36437SChicago Duan 1577b36437SChicago Duan namespace redfish 1677b36437SChicago Duan { 1777b36437SChicago Duan 1877b36437SChicago Duan inline void doPowerSubsystemCollection( 1977b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2077b36437SChicago Duan const std::string& chassisId, 2177b36437SChicago Duan const std::optional<std::string>& validChassisPath) 2277b36437SChicago Duan { 2377b36437SChicago Duan if (!validChassisPath) 2477b36437SChicago Duan { 2577b36437SChicago Duan messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 2677b36437SChicago Duan return; 2777b36437SChicago Duan } 2877b36437SChicago Duan 292ea468a0SGeorge Liu asyncResp->res.addHeader( 302ea468a0SGeorge Liu boost::beast::http::field::link, 312ea468a0SGeorge Liu "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 3277b36437SChicago Duan asyncResp->res.jsonValue["@odata.type"] = 3377b36437SChicago Duan "#PowerSubsystem.v1_1_0.PowerSubsystem"; 3477b36437SChicago Duan asyncResp->res.jsonValue["Name"] = "Power Subsystem"; 3577b36437SChicago Duan asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; 36*ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 37*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId); 3877b36437SChicago Duan asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 3977b36437SChicago Duan asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 40a7210020SGeorge Liu asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] = 41*ef4c65b7SEd Tanous boost::urls::format( 42*ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId); 432ea468a0SGeorge Liu } 4477b36437SChicago Duan 452ea468a0SGeorge Liu inline void handlePowerSubsystemCollectionHead( 462ea468a0SGeorge Liu App& app, const crow::Request& req, 472ea468a0SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 482ea468a0SGeorge Liu const std::string& chassisId) 492ea468a0SGeorge Liu { 502ea468a0SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 512ea468a0SGeorge Liu { 522ea468a0SGeorge Liu return; 532ea468a0SGeorge Liu } 542ea468a0SGeorge Liu 552ea468a0SGeorge Liu auto respHandler = [asyncResp, chassisId]( 562ea468a0SGeorge Liu const std::optional<std::string>& validChassisPath) { 572ea468a0SGeorge Liu if (!validChassisPath) 582ea468a0SGeorge Liu { 592ea468a0SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 602ea468a0SGeorge Liu return; 612ea468a0SGeorge Liu } 6277b36437SChicago Duan asyncResp->res.addHeader( 6377b36437SChicago Duan boost::beast::http::field::link, 6477b36437SChicago Duan "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 652ea468a0SGeorge Liu }; 662ea468a0SGeorge Liu redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 672ea468a0SGeorge Liu std::move(respHandler)); 6877b36437SChicago Duan } 6977b36437SChicago Duan 7077b36437SChicago Duan inline void handlePowerSubsystemCollectionGet( 7177b36437SChicago Duan App& app, const crow::Request& req, 7277b36437SChicago Duan const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 7377b36437SChicago Duan const std::string& chassisId) 7477b36437SChicago Duan { 7577b36437SChicago Duan if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 7677b36437SChicago Duan { 7777b36437SChicago Duan return; 7877b36437SChicago Duan } 7977b36437SChicago Duan 8077b36437SChicago Duan redfish::chassis_utils::getValidChassisPath( 8177b36437SChicago Duan asyncResp, chassisId, 8277b36437SChicago Duan std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId)); 8377b36437SChicago Duan } 8477b36437SChicago Duan 8577b36437SChicago Duan inline void requestRoutesPowerSubsystem(App& app) 8677b36437SChicago Duan { 8777b36437SChicago Duan BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 882ea468a0SGeorge Liu .privileges(redfish::privileges::headPowerSubsystem) 892ea468a0SGeorge Liu .methods(boost::beast::http::verb::head)( 902ea468a0SGeorge Liu std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app))); 912ea468a0SGeorge Liu 922ea468a0SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 9377b36437SChicago Duan .privileges(redfish::privileges::getPowerSubsystem) 9477b36437SChicago Duan .methods(boost::beast::http::verb::get)( 9577b36437SChicago Duan std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); 9677b36437SChicago Duan } 9777b36437SChicago Duan 9877b36437SChicago Duan } // namespace redfish 99