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