Add State information for PCIeDevice
This commit is to add state information according to the Redfish
PCIeDevice schema. Default state is "Enabled".
ref: https://redfish.dmtf.org/schemas/v1/PCIeDevice.v1_9_0.json
Tested: Validator passed
'''
curl -k https://$bmc/redfish/v1/Systems/system/PCIeDevices/pcie_card8
{
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card8",
"@odata.type": "#PCIeDevice.v1_9_0.PCIeDevice",
"Id": "pcie_card8",
"Manufacturer": "",
"Model": "6B87",
"Name": "PCIe Device",
"PCIeFunctions": {
"@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card8/PCIeFunctions"
},
"PCIeInterface": {
"LanesInUse": -1
},
"PartNumber": "03FL194",
"SerialNumber": "Y131UF09S00J",
"Slot": {
"Location": {
"PartLocation": {
"ServiceLabel": "U78DB.ND0.WZS0018-P0-C8"
}
}
},
"SparePartNumber": "03FL195",
"Status": {
"Health": "OK",
"State": "Enabled"
}
}
'''
Change-Id: Ibee01345c81c2e824fc2387c4f27e421b3f4c507
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp
index 45625f7..2754216 100644
--- a/redfish-core/lib/pcie.hpp
+++ b/redfish-core/lib/pcie.hpp
@@ -217,6 +217,31 @@
return std::nullopt;
}
+inline void getPCIeDeviceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& pcieDevicePath,
+ const std::string& service)
+{
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, service, pcieDevicePath,
+ "xyz.openbmc_project.Inventory.Item", "Present",
+ [aResp](const boost::system::error_code& ec, const bool value) {
+ if (ec)
+ {
+ if (ec.value() != EBADR)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error for State";
+ messages::internalError(aResp->res);
+ }
+ return;
+ }
+
+ if (!value)
+ {
+ aResp->res.jsonValue["Status"]["State"] = "Absent";
+ }
+ });
+}
+
inline void getPCIeDeviceAsset(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const std::string& pcieDevicePath,
const std::string& service)
@@ -371,6 +396,7 @@
"redfish", "v1", "Systems", "system", "PCIeDevices", pcieDeviceId);
aResp->res.jsonValue["Name"] = "PCIe Device";
aResp->res.jsonValue["Id"] = pcieDeviceId;
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
}
inline void handlePCIeDeviceGet(App& app, const crow::Request& req,
@@ -394,6 +420,7 @@
const std::string& service) {
addPCIeDeviceCommonProperties(aResp, pcieDeviceId);
getPCIeDeviceAsset(aResp, pcieDevicePath, service);
+ getPCIeDeviceState(aResp, pcieDevicePath, service);
getPCIeDeviceProperties(
aResp, pcieDevicePath, service,
[aResp, pcieDeviceId](