1*a7210020SGeorge Liu #pragma once 2*a7210020SGeorge Liu 3*a7210020SGeorge Liu #include "app.hpp" 4*a7210020SGeorge Liu #include "dbus_utility.hpp" 5*a7210020SGeorge Liu #include "query.hpp" 6*a7210020SGeorge Liu #include "registries/privilege_registry.hpp" 7*a7210020SGeorge Liu #include "utils/chassis_utils.hpp" 8*a7210020SGeorge Liu 9*a7210020SGeorge Liu #include <memory> 10*a7210020SGeorge Liu #include <optional> 11*a7210020SGeorge Liu #include <string> 12*a7210020SGeorge Liu 13*a7210020SGeorge Liu namespace redfish 14*a7210020SGeorge Liu { 15*a7210020SGeorge Liu 16*a7210020SGeorge Liu inline void updatePowerSupplyList( 17*a7210020SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& /* asyncResp */, 18*a7210020SGeorge Liu const std::string& /* chassisId */, 19*a7210020SGeorge Liu const std::string& /* powerSupplyPath */) 20*a7210020SGeorge Liu { 21*a7210020SGeorge Liu // TODO In order for the validator to pass, the Members property will be 22*a7210020SGeorge Liu // implemented on the next commit 23*a7210020SGeorge Liu } 24*a7210020SGeorge Liu 25*a7210020SGeorge Liu inline void 26*a7210020SGeorge Liu doPowerSupplyCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 27*a7210020SGeorge Liu const std::string& chassisId, 28*a7210020SGeorge Liu const std::optional<std::string>& validChassisPath) 29*a7210020SGeorge Liu { 30*a7210020SGeorge Liu if (!validChassisPath) 31*a7210020SGeorge Liu { 32*a7210020SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 33*a7210020SGeorge Liu return; 34*a7210020SGeorge Liu } 35*a7210020SGeorge Liu 36*a7210020SGeorge Liu asyncResp->res.addHeader( 37*a7210020SGeorge Liu boost::beast::http::field::link, 38*a7210020SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby"); 39*a7210020SGeorge Liu asyncResp->res.jsonValue["@odata.type"] = 40*a7210020SGeorge Liu "#PowerSupplyCollection.PowerSupplyCollection"; 41*a7210020SGeorge Liu asyncResp->res.jsonValue["Name"] = "Power Supply Collection"; 42*a7210020SGeorge Liu asyncResp->res.jsonValue["@odata.id"] = 43*a7210020SGeorge Liu crow::utility::urlFromPieces("redfish", "v1", "Chassis", chassisId, 44*a7210020SGeorge Liu "PowerSubsystem", "PowerSupplies"); 45*a7210020SGeorge Liu asyncResp->res.jsonValue["Description"] = 46*a7210020SGeorge Liu "The collection of PowerSupply resource instances."; 47*a7210020SGeorge Liu 48*a7210020SGeorge Liu std::string powerPath = *validChassisPath + "/powered_by"; 49*a7210020SGeorge Liu dbus::utility::getAssociationEndPoints( 50*a7210020SGeorge Liu powerPath, [asyncResp, chassisId]( 51*a7210020SGeorge Liu const boost::system::error_code& ec, 52*a7210020SGeorge Liu const dbus::utility::MapperEndPoints& endpoints) { 53*a7210020SGeorge Liu if (ec) 54*a7210020SGeorge Liu { 55*a7210020SGeorge Liu if (ec.value() != EBADR) 56*a7210020SGeorge Liu { 57*a7210020SGeorge Liu BMCWEB_LOG_ERROR << "DBUS response error" << ec.value(); 58*a7210020SGeorge Liu messages::internalError(asyncResp->res); 59*a7210020SGeorge Liu } 60*a7210020SGeorge Liu return; 61*a7210020SGeorge Liu } 62*a7210020SGeorge Liu 63*a7210020SGeorge Liu for (const auto& endpoint : endpoints) 64*a7210020SGeorge Liu { 65*a7210020SGeorge Liu updatePowerSupplyList(asyncResp, chassisId, endpoint); 66*a7210020SGeorge Liu } 67*a7210020SGeorge Liu }); 68*a7210020SGeorge Liu } 69*a7210020SGeorge Liu 70*a7210020SGeorge Liu inline void handlePowerSupplyCollectionHead( 71*a7210020SGeorge Liu App& app, const crow::Request& req, 72*a7210020SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 73*a7210020SGeorge Liu const std::string& chassisId) 74*a7210020SGeorge Liu { 75*a7210020SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 76*a7210020SGeorge Liu { 77*a7210020SGeorge Liu return; 78*a7210020SGeorge Liu } 79*a7210020SGeorge Liu 80*a7210020SGeorge Liu redfish::chassis_utils::getValidChassisPath( 81*a7210020SGeorge Liu asyncResp, chassisId, 82*a7210020SGeorge Liu [asyncResp, 83*a7210020SGeorge Liu chassisId](const std::optional<std::string>& validChassisPath) { 84*a7210020SGeorge Liu if (!validChassisPath) 85*a7210020SGeorge Liu { 86*a7210020SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 87*a7210020SGeorge Liu return; 88*a7210020SGeorge Liu } 89*a7210020SGeorge Liu asyncResp->res.addHeader( 90*a7210020SGeorge Liu boost::beast::http::field::link, 91*a7210020SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby"); 92*a7210020SGeorge Liu }); 93*a7210020SGeorge Liu } 94*a7210020SGeorge Liu 95*a7210020SGeorge Liu inline void handlePowerSupplyCollectionGet( 96*a7210020SGeorge Liu App& app, const crow::Request& req, 97*a7210020SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 98*a7210020SGeorge Liu const std::string& chassisId) 99*a7210020SGeorge Liu { 100*a7210020SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 101*a7210020SGeorge Liu { 102*a7210020SGeorge Liu return; 103*a7210020SGeorge Liu } 104*a7210020SGeorge Liu 105*a7210020SGeorge Liu redfish::chassis_utils::getValidChassisPath( 106*a7210020SGeorge Liu asyncResp, chassisId, 107*a7210020SGeorge Liu std::bind_front(doPowerSupplyCollection, asyncResp, chassisId)); 108*a7210020SGeorge Liu } 109*a7210020SGeorge Liu 110*a7210020SGeorge Liu inline void requestRoutesPowerSupplyCollection(App& app) 111*a7210020SGeorge Liu { 112*a7210020SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/") 113*a7210020SGeorge Liu .privileges(redfish::privileges::headPowerSupplyCollection) 114*a7210020SGeorge Liu .methods(boost::beast::http::verb::head)( 115*a7210020SGeorge Liu std::bind_front(handlePowerSupplyCollectionHead, std::ref(app))); 116*a7210020SGeorge Liu 117*a7210020SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/") 118*a7210020SGeorge Liu .privileges(redfish::privileges::getPowerSupplyCollection) 119*a7210020SGeorge Liu .methods(boost::beast::http::verb::get)( 120*a7210020SGeorge Liu std::bind_front(handlePowerSupplyCollectionGet, std::ref(app))); 121*a7210020SGeorge Liu } 122*a7210020SGeorge Liu 123*a7210020SGeorge Liu } // namespace redfish 124