Redfish: Add Chassis PowerState call
Make a call to /xyz/openbmc_project/state/chassis0 to get the
chassis PowerState.
Very similiar to how we get the System PowerState
https://github.com/openbmc/bmcweb/blob/abf2add6a35aaf42ba60c4ae955a4d8925b13b19/redfish-core/lib/systems.hpp#L471
Resolves openbmc/bmcweb#27
Tested: Loaded this on a Witherspoon and power on/off. Saw correct
PowerState.
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Change-Id: I9dd008a902098f1872560d985249375a2d317f25
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index d24e641..f78789a 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -24,6 +24,50 @@
{
/**
+ * @brief Retrieves chassis state properties over dbus
+ *
+ * @param[in] aResp - Shared pointer for completing asynchronous calls.
+ *
+ * @return None.
+ */
+void getChassisState(std::shared_ptr<AsyncResp> aResp)
+{
+ crow::connections::systemBus->async_method_call(
+ [aResp{std::move(aResp)}](
+ const boost::system::error_code ec,
+ const std::variant<std::string> &chassisState) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ const std::string *s = std::get_if<std::string>(&chassisState);
+ BMCWEB_LOG_DEBUG << "Chassis state: " << *s;
+ if (s != nullptr)
+ {
+ // Verify Chassis State
+ if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
+ }
+ else if (*s ==
+ "xyz.openbmc_project.State.Chassis.PowerState.Off")
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
+ }
+ }
+ },
+ "xyz.openbmc_project.State.Chassis",
+ "/xyz/openbmc_project/state/chassis0",
+ "org.freedesktop.DBus.Properties", "Get",
+ "xyz.openbmc_project.State.Chassis", "CurrentPowerState");
+}
+
+/**
* DBus types primitives for several generic DBus interfaces
* TODO(Pawel) consider move this to separate file into boost::dbus
*/
@@ -241,7 +285,6 @@
"/redfish/v1/$metadata#Chassis.Chassis";
res.jsonValue["Name"] = "Chassis Collection";
res.jsonValue["ChassisType"] = "RackMount";
- res.jsonValue["PowerState"] = "On";
auto asyncResp = std::make_shared<AsyncResp>(res);
crow::connections::systemBus->async_method_call(
@@ -330,6 +373,7 @@
{{"@odata.id", "/redfish/v1/Systems/system"}}};
asyncResp->res.jsonValue["Links"]["ManagedBy"] = {
{{"@odata.id", "/redfish/v1/Managers/bmc"}}};
+ getChassisState(asyncResp);
},
connectionName, path, "org.freedesktop.DBus.Properties",
"GetAll",