From 3fe4d5cca464ff7696236fe42acf64637e9126d9 Mon Sep 17 00:00:00 2001 From: John Edward Broadbent Date: Fri, 6 May 2022 14:42:35 -0700 Subject: redfish: Add the percent lifeleft to drive The property known as "PredictedMediaLifeLeftPercent" was not implemented in bmcweb. This change adds that property to bmcweb, and exposes the value of PredictedMediaLifeLeftPercent to redfish clients. More information about the interface can be found at the link below, or in yaml/xyz/openbmc_project/Inventory/Item/Drive.interface.yaml. https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/47657/10/yaml/xyz/openbmc_project/Inventory/Item/Drive.interface.yaml#31 Tested: Redfish Validator did not show any errors from this change. $ wget -qO- http://localhost:80/redfish/v1/Chassis/DC_SCM/Drives/mmcblk0 { "@odata.context": "/redfish/v1/$metadata#Drive.Drive", "@odata.id": "/redfish/v1/Chassis/Drives/mmcblk0", "@odata.type": "#Drive.v1_7_0.Drive", "CapacityBytes": 15634268160, "EncryptionStatus": "Unencrypted", "Id": "mmcblk0", "Links": { "Chassis": "Enabled" }, "Name": "mmcblk0", "PredictedMediaLifeLeftPercent": 100, "Status": { "State": "Enabled" } } Signed-off-by: John Edward Broadbent Change-Id: I360ce393707ba7a876810fc80f8a2d6fb484759c --- redfish-core/lib/storage.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp index 51635ce10f..30b679deea 100644 --- a/redfish-core/lib/storage.hpp +++ b/redfish-core/lib/storage.hpp @@ -467,6 +467,24 @@ inline void } asyncResp->res.jsonValue["Protocol"] = *proto; } + else if (propertyName == "PredictedMediaLifeLeftPercent") + { + const uint8_t* lifeLeft = + std::get_if(&property.second); + if (lifeLeft == nullptr) + { + BMCWEB_LOG_ERROR + << "Illegal property: PredictedMediaLifeLeftPercent"; + messages::internalError(asyncResp->res); + return; + } + // 255 means reading the value is not supported + if (*lifeLeft != 255) + { + asyncResp->res.jsonValue["PredictedMediaLifeLeftPercent"] = + *lifeLeft; + } + } } }); } -- cgit v1.2.3