Add Location information for FabricAdapter
This commit is to add location information according to the Redfish
FabricAdapter schema. If the
`xyz.openbmc_project.Inventory.Decorator.LocationCode` interface does
not exist, the location information property is not displayed.
ref: http://redfish.dmtf.org/schemas/v1/FabricAdapter.v1_4_0.json
Tested: Validator passes
```
curl -k https://$bmc/redfish/v1/Systems/system/FabricAdapters/disk_backplane0
{
"@odata.id": "/redfish/v1/Systems/system/FabricAdapters/disk_backplane0",
"@odata.type": "#FabricAdapter.v1_4_0.FabricAdapter",
"Id": "disk_backplane0",
"Location": {
"PartLocation": {
"ServiceLabel": "U78DA.ND0.WZS0042-P1"
}
},
"Name": "Fabric Adapter"
}
```
Change-Id: I0dad37dce06e4727057d9821b5c40c71db004ee6
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/lib/fabric_adapters.hpp b/redfish-core/lib/fabric_adapters.hpp
index a1e273a..5cfd0b5 100644
--- a/redfish-core/lib/fabric_adapters.hpp
+++ b/redfish-core/lib/fabric_adapters.hpp
@@ -25,7 +25,7 @@
if (ec.value() == boost::system::errc::io_error)
{
- messages::resourceNotFound(res, "#FabricAdapter.v1_0_0.FabricAdapter",
+ messages::resourceNotFound(res, "#FabricAdapter.v1_4_0.FabricAdapter",
adapterId);
return;
}
@@ -34,18 +34,47 @@
messages::internalError(res);
}
+inline void
+ getFabricAdapterLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& serviceName,
+ const std::string& fabricAdapterPath)
+{
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, serviceName, fabricAdapterPath,
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
+ [aResp](const boost::system::error_code ec,
+ const std::string& property) {
+ if (ec)
+ {
+ if (ec.value() != EBADR)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error for Location";
+ messages::internalError(aResp->res);
+ }
+ return;
+ }
+
+ aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
+ property;
+ });
+}
+
inline void doAdapterGet(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const std::string& systemName,
- const std::string& adapterId)
+ const std::string& adapterId,
+ const std::string& fabricAdapterPath,
+ const std::string& serviceName)
{
aResp->res.addHeader(
boost::beast::http::field::link,
"</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
- aResp->res.jsonValue["@odata.type"] = "#FabricAdapter.v1_0_0.FabricAdapter";
+ aResp->res.jsonValue["@odata.type"] = "#FabricAdapter.v1_4_0.FabricAdapter";
aResp->res.jsonValue["Name"] = "Fabric Adapter";
aResp->res.jsonValue["Id"] = adapterId;
aResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
"redfish", "v1", "Systems", systemName, "FabricAdapters", adapterId);
+
+ getFabricAdapterLocation(aResp, serviceName, fabricAdapterPath);
}
inline bool checkFabricAdapterId(const std::string& adapterPath,
@@ -107,8 +136,10 @@
getValidFabricAdapterPath(
adapterId, systemName, aResp,
- [aResp, systemName, adapterId](const std::string&, const std::string&) {
- doAdapterGet(aResp, systemName, adapterId);
+ [aResp, systemName, adapterId](const std::string& fabricAdapterPath,
+ const std::string& serviceName) {
+ doAdapterGet(aResp, systemName, adapterId, fabricAdapterPath,
+ serviceName);
});
}