From 2b45fb3b8bd8684886a6ba3249183be0f541d592 Mon Sep 17 00:00:00 2001 From: George Liu Date: Wed, 5 Oct 2022 17:00:00 +0800 Subject: Add asset information for PowerSupply This commit is to add asset information according to the Redfish PowerSupply schema. If the `xyz.openbmc_project.Inventory.Decorator.Asset` interface does not exist, the asset information property is not displayed. ref: http://redfish.dmtf.org/schemas/v1/PowerSupply.v1_5_0.json Tested: Validator passes curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/Chassis/chassis/PowerSubsystem/ PowerSupplies/powersupply0 { "@odata.id": "/redfish/v1/Chassis/chassis/PowerSubsystem/ PowerSupplies/powersupply0", "@odata.type": "#PowerSupply.v1_5_0.PowerSupply", "Id": "powersupply0", "Manufacturer": "", "Model": "51E9", "Name": "powersupply0", "PartNumber": "03KP466", "SerialNumber": "YL10KY26E073", "SparePartNumber": "03FP378", "Status": { "Health": "OK" } } Signed-off-by: George Liu Change-Id: I83f1a9375f83e3470089cb2b5207db9665cc69df --- Redfish.md | 5 +++ redfish-core/lib/power_supply.hpp | 69 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) 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 #include @@ -243,6 +245,71 @@ inline void }); } +inline void + getPowerSupplyAsset(const std::shared_ptr& 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& asyncResp, const std::string& chassisId, @@ -290,6 +357,8 @@ inline void powerSupplyPath); getPowerSupplyHealth(asyncResp, object.begin()->first, powerSupplyPath); + getPowerSupplyAsset(asyncResp, object.begin()->first, + powerSupplyPath); }); }); } -- cgit v1.2.3