diff options
-rw-r--r-- | Redfish.md | 5 | ||||
-rw-r--r-- | redfish-core/lib/power_supply.hpp | 69 |
2 files changed, 74 insertions, 0 deletions
diff --git a/Redfish.md b/Redfish.md index 75121d9f9c..d74d3e961c 100644 --- a/Redfish.md +++ b/Redfish.md @@ -379,6 +379,11 @@ Fields common to all schemas ##### PowerSupply +- Manufacturer +- Model +- PartNumber +- SerialNumber +- SparePartNumber - Status ### /redfish/v1/EventService/ diff --git a/redfish-core/lib/power_supply.hpp b/redfish-core/lib/power_supply.hpp index 8360fb197c..aa88e09988 100644 --- a/redfish-core/lib/power_supply.hpp +++ b/redfish-core/lib/power_supply.hpp @@ -5,6 +5,8 @@ #include "query.hpp" #include "registries/privilege_registry.hpp" #include "utils/chassis_utils.hpp" +#include "utils/dbus_utils.hpp" +#include "utils/json_utils.hpp" #include <boost/system/error_code.hpp> #include <boost/url/format.hpp> @@ -244,6 +246,71 @@ inline void } inline void + getPowerSupplyAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& service, const std::string& path) +{ + sdbusplus::asio::getAllProperties( + *crow::connections::systemBus, service, path, + "xyz.openbmc_project.Inventory.Decorator.Asset", + [asyncResp](const boost::system::error_code& ec, + const dbus::utility::DBusPropertiesMap& propertiesList) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR << "DBUS response error for Asset " + << ec.value(); + messages::internalError(asyncResp->res); + } + return; + } + + const std::string* partNumber = nullptr; + const std::string* serialNumber = nullptr; + const std::string* manufacturer = nullptr; + const std::string* model = nullptr; + const std::string* sparePartNumber = nullptr; + + const bool success = sdbusplus::unpackPropertiesNoThrow( + dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", + partNumber, "SerialNumber", serialNumber, "Manufacturer", + manufacturer, "Model", model, "SparePartNumber", sparePartNumber); + + if (!success) + { + messages::internalError(asyncResp->res); + return; + } + + if (partNumber != nullptr) + { + asyncResp->res.jsonValue["PartNumber"] = *partNumber; + } + + if (serialNumber != nullptr) + { + asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; + } + + if (manufacturer != nullptr) + { + asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; + } + + if (model != nullptr) + { + asyncResp->res.jsonValue["Model"] = *model; + } + + // SparePartNumber is optional on D-Bus so skip if it is empty + if (sparePartNumber != nullptr && !sparePartNumber->empty()) + { + asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; + } + }); +} + +inline void doPowerSupplyGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& chassisId, const std::string& powerSupplyId, @@ -290,6 +357,8 @@ inline void powerSupplyPath); getPowerSupplyHealth(asyncResp, object.begin()->first, powerSupplyPath); + getPowerSupplyAsset(asyncResp, object.begin()->first, + powerSupplyPath); }); }); } |