1a7210020SGeorge Liu #pragma once 2a7210020SGeorge Liu 3a7210020SGeorge Liu #include "app.hpp" 4a7210020SGeorge Liu #include "dbus_utility.hpp" 5a7210020SGeorge Liu #include "query.hpp" 6a7210020SGeorge Liu #include "registries/privilege_registry.hpp" 7a7210020SGeorge Liu #include "utils/chassis_utils.hpp" 8*2b45fb3bSGeorge Liu #include "utils/dbus_utils.hpp" 9*2b45fb3bSGeorge Liu #include "utils/json_utils.hpp" 10a7210020SGeorge Liu 1134dfcb94SGeorge Liu #include <boost/system/error_code.hpp> 12ef4c65b7SEd Tanous #include <boost/url/format.hpp> 13ef4c65b7SEd Tanous 14a7210020SGeorge Liu #include <memory> 15a7210020SGeorge Liu #include <optional> 16a7210020SGeorge Liu #include <string> 17a7210020SGeorge Liu 18a7210020SGeorge Liu namespace redfish 19a7210020SGeorge Liu { 20a7210020SGeorge Liu 2100ef5dc6SGeorge Liu inline void 2200ef5dc6SGeorge Liu updatePowerSupplyList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2300ef5dc6SGeorge Liu const std::string& chassisId, 2400ef5dc6SGeorge Liu const std::string& powerSupplyPath) 25a7210020SGeorge Liu { 2600ef5dc6SGeorge Liu std::string powerSupplyName = 2700ef5dc6SGeorge Liu sdbusplus::message::object_path(powerSupplyPath).filename(); 2800ef5dc6SGeorge Liu if (powerSupplyName.empty()) 2900ef5dc6SGeorge Liu { 3000ef5dc6SGeorge Liu return; 3100ef5dc6SGeorge Liu } 3200ef5dc6SGeorge Liu 3300ef5dc6SGeorge Liu nlohmann::json item = nlohmann::json::object(); 3400ef5dc6SGeorge Liu item["@odata.id"] = boost::urls::format( 3500ef5dc6SGeorge Liu "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies/{}", chassisId, 3600ef5dc6SGeorge Liu powerSupplyName); 3700ef5dc6SGeorge Liu 3800ef5dc6SGeorge Liu nlohmann::json& powerSupplyList = asyncResp->res.jsonValue["Members"]; 3900ef5dc6SGeorge Liu powerSupplyList.emplace_back(std::move(item)); 4000ef5dc6SGeorge Liu asyncResp->res.jsonValue["Members@odata.count"] = powerSupplyList.size(); 41a7210020SGeorge Liu } 42a7210020SGeorge Liu 43a7210020SGeorge Liu inline void 44a7210020SGeorge Liu doPowerSupplyCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 45a7210020SGeorge Liu const std::string& chassisId, 46a7210020SGeorge Liu const std::optional<std::string>& validChassisPath) 47a7210020SGeorge Liu { 48a7210020SGeorge Liu if (!validChassisPath) 49a7210020SGeorge Liu { 50a7210020SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 51a7210020SGeorge Liu return; 52a7210020SGeorge Liu } 53a7210020SGeorge Liu 54a7210020SGeorge Liu asyncResp->res.addHeader( 55a7210020SGeorge Liu boost::beast::http::field::link, 56a7210020SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby"); 57a7210020SGeorge Liu asyncResp->res.jsonValue["@odata.type"] = 58a7210020SGeorge Liu "#PowerSupplyCollection.PowerSupplyCollection"; 59a7210020SGeorge Liu asyncResp->res.jsonValue["Name"] = "Power Supply Collection"; 60ef4c65b7SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 61ef4c65b7SEd Tanous "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId); 62a7210020SGeorge Liu asyncResp->res.jsonValue["Description"] = 63a7210020SGeorge Liu "The collection of PowerSupply resource instances."; 647a2bb2c9SGeorge Liu asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 657a2bb2c9SGeorge Liu asyncResp->res.jsonValue["Members@odata.count"] = 0; 66a7210020SGeorge Liu 67a7210020SGeorge Liu std::string powerPath = *validChassisPath + "/powered_by"; 68a7210020SGeorge Liu dbus::utility::getAssociationEndPoints( 69a7210020SGeorge Liu powerPath, [asyncResp, chassisId]( 70a7210020SGeorge Liu const boost::system::error_code& ec, 71a7210020SGeorge Liu const dbus::utility::MapperEndPoints& endpoints) { 72a7210020SGeorge Liu if (ec) 73a7210020SGeorge Liu { 74a7210020SGeorge Liu if (ec.value() != EBADR) 75a7210020SGeorge Liu { 76a7210020SGeorge Liu BMCWEB_LOG_ERROR << "DBUS response error" << ec.value(); 77a7210020SGeorge Liu messages::internalError(asyncResp->res); 78a7210020SGeorge Liu } 79a7210020SGeorge Liu return; 80a7210020SGeorge Liu } 81a7210020SGeorge Liu 82a7210020SGeorge Liu for (const auto& endpoint : endpoints) 83a7210020SGeorge Liu { 84a7210020SGeorge Liu updatePowerSupplyList(asyncResp, chassisId, endpoint); 85a7210020SGeorge Liu } 86a7210020SGeorge Liu }); 87a7210020SGeorge Liu } 88a7210020SGeorge Liu 89a7210020SGeorge Liu inline void handlePowerSupplyCollectionHead( 90a7210020SGeorge Liu App& app, const crow::Request& req, 91a7210020SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 92a7210020SGeorge Liu const std::string& chassisId) 93a7210020SGeorge Liu { 94a7210020SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 95a7210020SGeorge Liu { 96a7210020SGeorge Liu return; 97a7210020SGeorge Liu } 98a7210020SGeorge Liu 99a7210020SGeorge Liu redfish::chassis_utils::getValidChassisPath( 100a7210020SGeorge Liu asyncResp, chassisId, 101a7210020SGeorge Liu [asyncResp, 102a7210020SGeorge Liu chassisId](const std::optional<std::string>& validChassisPath) { 103a7210020SGeorge Liu if (!validChassisPath) 104a7210020SGeorge Liu { 105a7210020SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 106a7210020SGeorge Liu return; 107a7210020SGeorge Liu } 108a7210020SGeorge Liu asyncResp->res.addHeader( 109a7210020SGeorge Liu boost::beast::http::field::link, 110a7210020SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupplyCollection/PowerSupplyCollection.json>; rel=describedby"); 111a7210020SGeorge Liu }); 112a7210020SGeorge Liu } 113a7210020SGeorge Liu 114a7210020SGeorge Liu inline void handlePowerSupplyCollectionGet( 115a7210020SGeorge Liu App& app, const crow::Request& req, 116a7210020SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 117a7210020SGeorge Liu const std::string& chassisId) 118a7210020SGeorge Liu { 119a7210020SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 120a7210020SGeorge Liu { 121a7210020SGeorge Liu return; 122a7210020SGeorge Liu } 123a7210020SGeorge Liu 124a7210020SGeorge Liu redfish::chassis_utils::getValidChassisPath( 125a7210020SGeorge Liu asyncResp, chassisId, 126a7210020SGeorge Liu std::bind_front(doPowerSupplyCollection, asyncResp, chassisId)); 127a7210020SGeorge Liu } 128a7210020SGeorge Liu 129a7210020SGeorge Liu inline void requestRoutesPowerSupplyCollection(App& app) 130a7210020SGeorge Liu { 131a7210020SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/") 132a7210020SGeorge Liu .privileges(redfish::privileges::headPowerSupplyCollection) 133a7210020SGeorge Liu .methods(boost::beast::http::verb::head)( 134a7210020SGeorge Liu std::bind_front(handlePowerSupplyCollectionHead, std::ref(app))); 135a7210020SGeorge Liu 136a7210020SGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/") 137a7210020SGeorge Liu .privileges(redfish::privileges::getPowerSupplyCollection) 138a7210020SGeorge Liu .methods(boost::beast::http::verb::get)( 139a7210020SGeorge Liu std::bind_front(handlePowerSupplyCollectionGet, std::ref(app))); 140a7210020SGeorge Liu } 141a7210020SGeorge Liu 14200ef5dc6SGeorge Liu inline bool checkPowerSupplyId(const std::string& powerSupplyPath, 14300ef5dc6SGeorge Liu const std::string& powerSupplyId) 14400ef5dc6SGeorge Liu { 14500ef5dc6SGeorge Liu std::string powerSupplyName = 14600ef5dc6SGeorge Liu sdbusplus::message::object_path(powerSupplyPath).filename(); 14700ef5dc6SGeorge Liu 14800ef5dc6SGeorge Liu return !(powerSupplyName.empty() || powerSupplyName != powerSupplyId); 14900ef5dc6SGeorge Liu } 15000ef5dc6SGeorge Liu 15134dfcb94SGeorge Liu inline void getValidPowerSupplyPath( 15234dfcb94SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 15334dfcb94SGeorge Liu const std::string& validChassisPath, const std::string& powerSupplyId, 15434dfcb94SGeorge Liu std::function<void(const std::string& powerSupplyPath)>&& callback) 15500ef5dc6SGeorge Liu { 15600ef5dc6SGeorge Liu std::string powerPath = validChassisPath + "/powered_by"; 15700ef5dc6SGeorge Liu dbus::utility::getAssociationEndPoints( 15800ef5dc6SGeorge Liu powerPath, [asyncResp, powerSupplyId, callback{std::move(callback)}]( 15900ef5dc6SGeorge Liu const boost::system::error_code& ec, 16000ef5dc6SGeorge Liu const dbus::utility::MapperEndPoints& endpoints) { 16100ef5dc6SGeorge Liu if (ec) 16200ef5dc6SGeorge Liu { 16300ef5dc6SGeorge Liu if (ec.value() != EBADR) 16400ef5dc6SGeorge Liu { 16500ef5dc6SGeorge Liu BMCWEB_LOG_ERROR 16600ef5dc6SGeorge Liu << "DBUS response error for getAssociationEndPoints" 16700ef5dc6SGeorge Liu << ec.value(); 16800ef5dc6SGeorge Liu messages::internalError(asyncResp->res); 16900ef5dc6SGeorge Liu return; 17000ef5dc6SGeorge Liu } 17100ef5dc6SGeorge Liu messages::resourceNotFound(asyncResp->res, "PowerSupplies", 17200ef5dc6SGeorge Liu powerSupplyId); 17300ef5dc6SGeorge Liu return; 17400ef5dc6SGeorge Liu } 17500ef5dc6SGeorge Liu 17600ef5dc6SGeorge Liu for (const auto& endpoint : endpoints) 17700ef5dc6SGeorge Liu { 17800ef5dc6SGeorge Liu if (checkPowerSupplyId(endpoint, powerSupplyId)) 17900ef5dc6SGeorge Liu { 18034dfcb94SGeorge Liu callback(endpoint); 18100ef5dc6SGeorge Liu return; 18200ef5dc6SGeorge Liu } 18300ef5dc6SGeorge Liu } 18400ef5dc6SGeorge Liu 18500ef5dc6SGeorge Liu if (!endpoints.empty()) 18600ef5dc6SGeorge Liu { 18700ef5dc6SGeorge Liu BMCWEB_LOG_WARNING << "Power supply not found: " 18800ef5dc6SGeorge Liu << powerSupplyId; 18900ef5dc6SGeorge Liu messages::resourceNotFound(asyncResp->res, "PowerSupplies", 19000ef5dc6SGeorge Liu powerSupplyId); 19100ef5dc6SGeorge Liu return; 19200ef5dc6SGeorge Liu } 19300ef5dc6SGeorge Liu }); 19400ef5dc6SGeorge Liu } 19500ef5dc6SGeorge Liu 19600ef5dc6SGeorge Liu inline void 19734dfcb94SGeorge Liu getPowerSupplyState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 19834dfcb94SGeorge Liu const std::string& service, const std::string& path) 19934dfcb94SGeorge Liu { 20034dfcb94SGeorge Liu sdbusplus::asio::getProperty<bool>( 20134dfcb94SGeorge Liu *crow::connections::systemBus, service, path, 20234dfcb94SGeorge Liu "xyz.openbmc_project.Inventory.Item", "Present", 20334dfcb94SGeorge Liu [asyncResp](const boost::system::error_code& ec, const bool value) { 20434dfcb94SGeorge Liu if (ec) 20534dfcb94SGeorge Liu { 20634dfcb94SGeorge Liu if (ec.value() != EBADR) 20734dfcb94SGeorge Liu { 20834dfcb94SGeorge Liu BMCWEB_LOG_ERROR << "DBUS response error for State " 20934dfcb94SGeorge Liu << ec.value(); 21034dfcb94SGeorge Liu messages::internalError(asyncResp->res); 21134dfcb94SGeorge Liu } 21234dfcb94SGeorge Liu return; 21334dfcb94SGeorge Liu } 21434dfcb94SGeorge Liu 21534dfcb94SGeorge Liu if (!value) 21634dfcb94SGeorge Liu { 21734dfcb94SGeorge Liu asyncResp->res.jsonValue["Status"]["State"] = "Absent"; 21834dfcb94SGeorge Liu } 21934dfcb94SGeorge Liu }); 22034dfcb94SGeorge Liu } 22134dfcb94SGeorge Liu 22234dfcb94SGeorge Liu inline void 22334dfcb94SGeorge Liu getPowerSupplyHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 22434dfcb94SGeorge Liu const std::string& service, const std::string& path) 22534dfcb94SGeorge Liu { 22634dfcb94SGeorge Liu sdbusplus::asio::getProperty<bool>( 22734dfcb94SGeorge Liu *crow::connections::systemBus, service, path, 22834dfcb94SGeorge Liu "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", 22934dfcb94SGeorge Liu [asyncResp](const boost::system::error_code& ec, const bool value) { 23034dfcb94SGeorge Liu if (ec) 23134dfcb94SGeorge Liu { 23234dfcb94SGeorge Liu if (ec.value() != EBADR) 23334dfcb94SGeorge Liu { 23434dfcb94SGeorge Liu BMCWEB_LOG_ERROR << "DBUS response error for Health " 23534dfcb94SGeorge Liu << ec.value(); 23634dfcb94SGeorge Liu messages::internalError(asyncResp->res); 23734dfcb94SGeorge Liu } 23834dfcb94SGeorge Liu return; 23934dfcb94SGeorge Liu } 24034dfcb94SGeorge Liu 24134dfcb94SGeorge Liu if (!value) 24234dfcb94SGeorge Liu { 24334dfcb94SGeorge Liu asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; 24434dfcb94SGeorge Liu } 24534dfcb94SGeorge Liu }); 24634dfcb94SGeorge Liu } 24734dfcb94SGeorge Liu 24834dfcb94SGeorge Liu inline void 249*2b45fb3bSGeorge Liu getPowerSupplyAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 250*2b45fb3bSGeorge Liu const std::string& service, const std::string& path) 251*2b45fb3bSGeorge Liu { 252*2b45fb3bSGeorge Liu sdbusplus::asio::getAllProperties( 253*2b45fb3bSGeorge Liu *crow::connections::systemBus, service, path, 254*2b45fb3bSGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Asset", 255*2b45fb3bSGeorge Liu [asyncResp](const boost::system::error_code& ec, 256*2b45fb3bSGeorge Liu const dbus::utility::DBusPropertiesMap& propertiesList) { 257*2b45fb3bSGeorge Liu if (ec) 258*2b45fb3bSGeorge Liu { 259*2b45fb3bSGeorge Liu if (ec.value() != EBADR) 260*2b45fb3bSGeorge Liu { 261*2b45fb3bSGeorge Liu BMCWEB_LOG_ERROR << "DBUS response error for Asset " 262*2b45fb3bSGeorge Liu << ec.value(); 263*2b45fb3bSGeorge Liu messages::internalError(asyncResp->res); 264*2b45fb3bSGeorge Liu } 265*2b45fb3bSGeorge Liu return; 266*2b45fb3bSGeorge Liu } 267*2b45fb3bSGeorge Liu 268*2b45fb3bSGeorge Liu const std::string* partNumber = nullptr; 269*2b45fb3bSGeorge Liu const std::string* serialNumber = nullptr; 270*2b45fb3bSGeorge Liu const std::string* manufacturer = nullptr; 271*2b45fb3bSGeorge Liu const std::string* model = nullptr; 272*2b45fb3bSGeorge Liu const std::string* sparePartNumber = nullptr; 273*2b45fb3bSGeorge Liu 274*2b45fb3bSGeorge Liu const bool success = sdbusplus::unpackPropertiesNoThrow( 275*2b45fb3bSGeorge Liu dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", 276*2b45fb3bSGeorge Liu partNumber, "SerialNumber", serialNumber, "Manufacturer", 277*2b45fb3bSGeorge Liu manufacturer, "Model", model, "SparePartNumber", sparePartNumber); 278*2b45fb3bSGeorge Liu 279*2b45fb3bSGeorge Liu if (!success) 280*2b45fb3bSGeorge Liu { 281*2b45fb3bSGeorge Liu messages::internalError(asyncResp->res); 282*2b45fb3bSGeorge Liu return; 283*2b45fb3bSGeorge Liu } 284*2b45fb3bSGeorge Liu 285*2b45fb3bSGeorge Liu if (partNumber != nullptr) 286*2b45fb3bSGeorge Liu { 287*2b45fb3bSGeorge Liu asyncResp->res.jsonValue["PartNumber"] = *partNumber; 288*2b45fb3bSGeorge Liu } 289*2b45fb3bSGeorge Liu 290*2b45fb3bSGeorge Liu if (serialNumber != nullptr) 291*2b45fb3bSGeorge Liu { 292*2b45fb3bSGeorge Liu asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; 293*2b45fb3bSGeorge Liu } 294*2b45fb3bSGeorge Liu 295*2b45fb3bSGeorge Liu if (manufacturer != nullptr) 296*2b45fb3bSGeorge Liu { 297*2b45fb3bSGeorge Liu asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; 298*2b45fb3bSGeorge Liu } 299*2b45fb3bSGeorge Liu 300*2b45fb3bSGeorge Liu if (model != nullptr) 301*2b45fb3bSGeorge Liu { 302*2b45fb3bSGeorge Liu asyncResp->res.jsonValue["Model"] = *model; 303*2b45fb3bSGeorge Liu } 304*2b45fb3bSGeorge Liu 305*2b45fb3bSGeorge Liu // SparePartNumber is optional on D-Bus so skip if it is empty 306*2b45fb3bSGeorge Liu if (sparePartNumber != nullptr && !sparePartNumber->empty()) 307*2b45fb3bSGeorge Liu { 308*2b45fb3bSGeorge Liu asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; 309*2b45fb3bSGeorge Liu } 310*2b45fb3bSGeorge Liu }); 311*2b45fb3bSGeorge Liu } 312*2b45fb3bSGeorge Liu 313*2b45fb3bSGeorge Liu inline void 31400ef5dc6SGeorge Liu doPowerSupplyGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 31500ef5dc6SGeorge Liu const std::string& chassisId, 31600ef5dc6SGeorge Liu const std::string& powerSupplyId, 31700ef5dc6SGeorge Liu const std::optional<std::string>& validChassisPath) 31800ef5dc6SGeorge Liu { 31900ef5dc6SGeorge Liu if (!validChassisPath) 32000ef5dc6SGeorge Liu { 32100ef5dc6SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 32200ef5dc6SGeorge Liu return; 32300ef5dc6SGeorge Liu } 32400ef5dc6SGeorge Liu 32500ef5dc6SGeorge Liu // Get the correct Path and Service that match the input parameters 32600ef5dc6SGeorge Liu getValidPowerSupplyPath(asyncResp, *validChassisPath, powerSupplyId, 32734dfcb94SGeorge Liu [asyncResp, chassisId, powerSupplyId]( 32834dfcb94SGeorge Liu const std::string& powerSupplyPath) { 32900ef5dc6SGeorge Liu asyncResp->res.addHeader( 33000ef5dc6SGeorge Liu boost::beast::http::field::link, 33100ef5dc6SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby"); 33200ef5dc6SGeorge Liu asyncResp->res.jsonValue["@odata.type"] = 33300ef5dc6SGeorge Liu "#PowerSupply.v1_5_0.PowerSupply"; 33400ef5dc6SGeorge Liu asyncResp->res.jsonValue["Name"] = "Power Supply"; 33500ef5dc6SGeorge Liu asyncResp->res.jsonValue["Id"] = powerSupplyId; 33600ef5dc6SGeorge Liu asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 33700ef5dc6SGeorge Liu "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies/{}", chassisId, 33800ef5dc6SGeorge Liu powerSupplyId); 33934dfcb94SGeorge Liu 34034dfcb94SGeorge Liu asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 34134dfcb94SGeorge Liu asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 34234dfcb94SGeorge Liu 34334dfcb94SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 34434dfcb94SGeorge Liu "xyz.openbmc_project.Inventory.Item.PowerSupply"}; 34534dfcb94SGeorge Liu dbus::utility::getDbusObject( 34634dfcb94SGeorge Liu powerSupplyPath, interfaces, 34734dfcb94SGeorge Liu [asyncResp, 34834dfcb94SGeorge Liu powerSupplyPath](const boost::system::error_code& ec, 34934dfcb94SGeorge Liu const dbus::utility::MapperGetObject& object) { 35034dfcb94SGeorge Liu if (ec || object.empty()) 35134dfcb94SGeorge Liu { 35234dfcb94SGeorge Liu messages::internalError(asyncResp->res); 35334dfcb94SGeorge Liu return; 35434dfcb94SGeorge Liu } 35534dfcb94SGeorge Liu 35634dfcb94SGeorge Liu getPowerSupplyState(asyncResp, object.begin()->first, 35734dfcb94SGeorge Liu powerSupplyPath); 35834dfcb94SGeorge Liu getPowerSupplyHealth(asyncResp, object.begin()->first, 35934dfcb94SGeorge Liu powerSupplyPath); 360*2b45fb3bSGeorge Liu getPowerSupplyAsset(asyncResp, object.begin()->first, 361*2b45fb3bSGeorge Liu powerSupplyPath); 36234dfcb94SGeorge Liu }); 36300ef5dc6SGeorge Liu }); 36400ef5dc6SGeorge Liu } 36500ef5dc6SGeorge Liu 36600ef5dc6SGeorge Liu inline void 36700ef5dc6SGeorge Liu handlePowerSupplyHead(App& app, const crow::Request& req, 36800ef5dc6SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 36900ef5dc6SGeorge Liu const std::string& chassisId, 37000ef5dc6SGeorge Liu const std::string& powerSupplyId) 37100ef5dc6SGeorge Liu { 37200ef5dc6SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 37300ef5dc6SGeorge Liu { 37400ef5dc6SGeorge Liu return; 37500ef5dc6SGeorge Liu } 37600ef5dc6SGeorge Liu 37700ef5dc6SGeorge Liu redfish::chassis_utils::getValidChassisPath( 37800ef5dc6SGeorge Liu asyncResp, chassisId, 37900ef5dc6SGeorge Liu [asyncResp, chassisId, 38000ef5dc6SGeorge Liu powerSupplyId](const std::optional<std::string>& validChassisPath) { 38100ef5dc6SGeorge Liu if (!validChassisPath) 38200ef5dc6SGeorge Liu { 38300ef5dc6SGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 38400ef5dc6SGeorge Liu return; 38500ef5dc6SGeorge Liu } 38600ef5dc6SGeorge Liu 38700ef5dc6SGeorge Liu // Get the correct Path and Service that match the input parameters 38800ef5dc6SGeorge Liu getValidPowerSupplyPath(asyncResp, *validChassisPath, powerSupplyId, 38934dfcb94SGeorge Liu [asyncResp](const std::string&) { 39000ef5dc6SGeorge Liu asyncResp->res.addHeader( 39100ef5dc6SGeorge Liu boost::beast::http::field::link, 39200ef5dc6SGeorge Liu "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby"); 39300ef5dc6SGeorge Liu }); 39400ef5dc6SGeorge Liu }); 39500ef5dc6SGeorge Liu } 39600ef5dc6SGeorge Liu 39700ef5dc6SGeorge Liu inline void 39800ef5dc6SGeorge Liu handlePowerSupplyGet(App& app, const crow::Request& req, 39900ef5dc6SGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 40000ef5dc6SGeorge Liu const std::string& chassisId, 40100ef5dc6SGeorge Liu const std::string& powerSupplyId) 40200ef5dc6SGeorge Liu { 40300ef5dc6SGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 40400ef5dc6SGeorge Liu { 40500ef5dc6SGeorge Liu return; 40600ef5dc6SGeorge Liu } 40700ef5dc6SGeorge Liu 40800ef5dc6SGeorge Liu redfish::chassis_utils::getValidChassisPath( 40900ef5dc6SGeorge Liu asyncResp, chassisId, 41000ef5dc6SGeorge Liu std::bind_front(doPowerSupplyGet, asyncResp, chassisId, powerSupplyId)); 41100ef5dc6SGeorge Liu } 41200ef5dc6SGeorge Liu 41300ef5dc6SGeorge Liu inline void requestRoutesPowerSupply(App& app) 41400ef5dc6SGeorge Liu { 41500ef5dc6SGeorge Liu BMCWEB_ROUTE( 41600ef5dc6SGeorge Liu app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/<str>/") 41700ef5dc6SGeorge Liu .privileges(redfish::privileges::headPowerSupply) 41800ef5dc6SGeorge Liu .methods(boost::beast::http::verb::head)( 41900ef5dc6SGeorge Liu std::bind_front(handlePowerSupplyHead, std::ref(app))); 42000ef5dc6SGeorge Liu 42100ef5dc6SGeorge Liu BMCWEB_ROUTE( 42200ef5dc6SGeorge Liu app, "/redfish/v1/Chassis/<str>/PowerSubsystem/PowerSupplies/<str>/") 42300ef5dc6SGeorge Liu .privileges(redfish::privileges::getPowerSupply) 42400ef5dc6SGeorge Liu .methods(boost::beast::http::verb::get)( 42500ef5dc6SGeorge Liu std::bind_front(handlePowerSupplyGet, std::ref(app))); 42600ef5dc6SGeorge Liu } 42700ef5dc6SGeorge Liu 428a7210020SGeorge Liu } // namespace redfish 429