Add asset information for Fan
This commit is to add asset information according to the Redfish Fan
schema.
If the `xyz.openbmc_project.Inventory.Decorator.Asset` interface does
not exist, the asset information property is not displayed.
ref: https://redfish.dmtf.org/schemas/v1/Fan.v1_3_0.json
Tested: Validator passes
'''
1. doGet method to get Fan asset information
curl -k https://${bmc}/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0
{
"@odata.id": "/redfish/v1/Chassis/chassis/ThermalSubsystem/Fans/fan0",
"@odata.type": "#Fan.v1_3_0.Fan",
"Id": "fan0",
"Manufacturer": "Delta",
"Model": "7B5F",
"Name": "Fan",
"PartNumber": "02YK323",
"SerialNumber": "YL12JP1C1234",
"SparePartNumber": "02YK323",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
'''
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I1840f2b372fea57ba6e5c499ba21c968f0005695
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/lib/fan.hpp b/redfish-core/lib/fan.hpp
index fb2ba20..0acb762 100644
--- a/redfish-core/lib/fan.hpp
+++ b/redfish-core/lib/fan.hpp
@@ -278,6 +278,63 @@
});
}
+inline void getFanAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& fanPath, const std::string& service)
+{
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, service, fanPath,
+ "xyz.openbmc_project.Inventory.Decorator.Asset",
+ [fanPath, asyncResp{asyncResp}](
+ const boost::system::error_code& ec,
+ const dbus::utility::DBusPropertiesMap& assetList) {
+ if (ec)
+ {
+ if (ec.value() != EBADR)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error for Properties"
+ << ec.value();
+ messages::internalError(asyncResp->res);
+ }
+ return;
+ }
+ const std::string* manufacturer = nullptr;
+ const std::string* model = nullptr;
+ const std::string* partNumber = nullptr;
+ const std::string* serialNumber = nullptr;
+ const std::string* sparePartNumber = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), assetList, "Manufacturer",
+ manufacturer, "Model", model, "PartNumber", partNumber,
+ "SerialNumber", serialNumber, "SparePartNumber", sparePartNumber);
+ if (!success)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ if (manufacturer != nullptr)
+ {
+ asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
+ }
+ if (model != nullptr)
+ {
+ asyncResp->res.jsonValue["Model"] = *model;
+ }
+ if (partNumber != nullptr)
+ {
+ asyncResp->res.jsonValue["PartNumber"] = *partNumber;
+ }
+ if (serialNumber != nullptr)
+ {
+ asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
+ }
+ if (sparePartNumber != nullptr && !sparePartNumber->empty())
+ {
+ asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
+ }
+ });
+}
+
inline void
afterGetValidFanPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& chassisId, const std::string& fanId,
@@ -286,6 +343,7 @@
addFanCommonProperties(asyncResp->res, chassisId, fanId);
getFanState(asyncResp, fanPath, service);
getFanHealth(asyncResp, fanPath, service);
+ getFanAsset(asyncResp, fanPath, service);
}
inline void doFanGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,