diff options
author | George Liu <liuxiwei@inspur.com> | 2022-10-05 11:47:44 +0300 |
---|---|---|
committer | Lakshmi Yadlapati <lakshmiy@us.ibm.com> | 2023-06-13 17:18:48 +0300 |
commit | 34dfcb94afa2447965c7dd5b89274325ee2d0b88 (patch) | |
tree | c2f9b91d1943a4d687a741f4be4f4909588c0974 /redfish-core/lib/power_supply.hpp | |
parent | d4b054c15150535c8edaa1619a9e52c8148d7e19 (diff) | |
download | bmcweb-34dfcb94afa2447965c7dd5b89274325ee2d0b88.tar.xz |
Add Status information for Power Supply
This commit is to add PowerSupply State/Health status according to the
Redfish PowerSupply schema.
If the `xyz.openbmc_project.Inventory.Item`
interface does not exist, the state status property is set to
default "Present".
If the `xyz.openbmc_project.State.Decorator.OperationalStatus`
interface does not exist, the health status property is set to
default "OK".
ref: http://redfish.dmtf.org/schemas/v1/PowerSupply.v1_5_0.json
Code that updates the OperationalStatus for all the inventory
https://github.com/openbmc/openpower-vpd-parser/blob/ \
3fb026386546cfd288ab4f86156c9aa0ffa145d6/ibm_vpd_app.cpp#L620
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",
"Name": "powersupply0",
"Status": {
"Health": "OK"
"State": "Enabled"
}
}
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I121b665a4e605024644cc7c9392f88a71703481e
Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core/lib/power_supply.hpp')
-rw-r--r-- | redfish-core/lib/power_supply.hpp | 91 |
1 files changed, 83 insertions, 8 deletions
diff --git a/redfish-core/lib/power_supply.hpp b/redfish-core/lib/power_supply.hpp index ebc61c50ab..8360fb197c 100644 --- a/redfish-core/lib/power_supply.hpp +++ b/redfish-core/lib/power_supply.hpp @@ -6,6 +6,7 @@ #include "registries/privilege_registry.hpp" #include "utils/chassis_utils.hpp" +#include <boost/system/error_code.hpp> #include <boost/url/format.hpp> #include <memory> @@ -145,11 +146,10 @@ inline bool checkPowerSupplyId(const std::string& powerSupplyPath, return !(powerSupplyName.empty() || powerSupplyName != powerSupplyId); } -inline void - getValidPowerSupplyPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& validChassisPath, - const std::string& powerSupplyId, - std::function<void()>&& callback) +inline void getValidPowerSupplyPath( + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& validChassisPath, const std::string& powerSupplyId, + std::function<void(const std::string& powerSupplyPath)>&& callback) { std::string powerPath = validChassisPath + "/powered_by"; dbus::utility::getAssociationEndPoints( @@ -175,7 +175,7 @@ inline void { if (checkPowerSupplyId(endpoint, powerSupplyId)) { - callback(); + callback(endpoint); return; } } @@ -192,6 +192,58 @@ inline void } inline void + getPowerSupplyState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& service, const std::string& path) +{ + sdbusplus::asio::getProperty<bool>( + *crow::connections::systemBus, service, path, + "xyz.openbmc_project.Inventory.Item", "Present", + [asyncResp](const boost::system::error_code& ec, const bool value) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR << "DBUS response error for State " + << ec.value(); + messages::internalError(asyncResp->res); + } + return; + } + + if (!value) + { + asyncResp->res.jsonValue["Status"]["State"] = "Absent"; + } + }); +} + +inline void + getPowerSupplyHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& service, const std::string& path) +{ + sdbusplus::asio::getProperty<bool>( + *crow::connections::systemBus, service, path, + "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", + [asyncResp](const boost::system::error_code& ec, const bool value) { + if (ec) + { + if (ec.value() != EBADR) + { + BMCWEB_LOG_ERROR << "DBUS response error for Health " + << ec.value(); + messages::internalError(asyncResp->res); + } + return; + } + + if (!value) + { + asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; + } + }); +} + +inline void doPowerSupplyGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& chassisId, const std::string& powerSupplyId, @@ -205,7 +257,8 @@ inline void // Get the correct Path and Service that match the input parameters getValidPowerSupplyPath(asyncResp, *validChassisPath, powerSupplyId, - [asyncResp, chassisId, powerSupplyId]() { + [asyncResp, chassisId, powerSupplyId]( + const std::string& powerSupplyPath) { asyncResp->res.addHeader( boost::beast::http::field::link, "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby"); @@ -216,6 +269,28 @@ inline void asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies/{}", chassisId, powerSupplyId); + + asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; + asyncResp->res.jsonValue["Status"]["Health"] = "OK"; + + constexpr std::array<std::string_view, 1> interfaces = { + "xyz.openbmc_project.Inventory.Item.PowerSupply"}; + dbus::utility::getDbusObject( + powerSupplyPath, interfaces, + [asyncResp, + powerSupplyPath](const boost::system::error_code& ec, + const dbus::utility::MapperGetObject& object) { + if (ec || object.empty()) + { + messages::internalError(asyncResp->res); + return; + } + + getPowerSupplyState(asyncResp, object.begin()->first, + powerSupplyPath); + getPowerSupplyHealth(asyncResp, object.begin()->first, + powerSupplyPath); + }); }); } @@ -242,7 +317,7 @@ inline void // Get the correct Path and Service that match the input parameters getValidPowerSupplyPath(asyncResp, *validChassisPath, powerSupplyId, - [asyncResp]() { + [asyncResp](const std::string&) { asyncResp->res.addHeader( boost::beast::http::field::link, "</redfish/v1/JsonSchemas/PowerSupply/PowerSupply.json>; rel=describedby"); |