summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Liu <liuxiwei@inspur.com>2022-10-05 12:00:00 +0300
committerLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-06-14 21:29:32 +0300
commit2b45fb3b8bd8684886a6ba3249183be0f541d592 (patch)
tree4f4e1ca125fba5a2a1c729801a4f9d8f09543dd0
parenta115d87f837f06a2a61646bd3cc5304c09956ef4 (diff)
downloadbmcweb-2b45fb3b8bd8684886a6ba3249183be0f541d592.tar.xz
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 <liuxiwei@inspur.com> Change-Id: I83f1a9375f83e3470089cb2b5207db9665cc69df
-rw-r--r--Redfish.md5
-rw-r--r--redfish-core/lib/power_supply.hpp69
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);
});
});
}