summaryrefslogtreecommitdiff
path: root/redfish-core/lib/hypervisor_system.hpp
diff options
context:
space:
mode:
authorAndrew Geissler <geissonator@yahoo.com>2021-02-08 22:08:05 +0300
committerAndrew Geissler <geissonator@yahoo.com>2021-02-25 01:11:29 +0300
commitcc0bb6f29171b8afb09bd663767ba36793110d5d (patch)
tree702648cba51efa06d74a30dc4b6acde89ae194e7 /redfish-core/lib/hypervisor_system.hpp
parentfeaf15005555a3099c7f22a7e3d16c99ccb40e72 (diff)
downloadbmcweb-cc0bb6f29171b8afb09bd663767ba36793110d5d.tar.xz
hypervisor: add state support
phosphor-state-manager support a new optional package, phosphor-state-manager-hypervisor. IBM plans to include this package on their system to monitor and control the hypervisor firmware running on the system. Since this package is optional, this patch set is written to just ignore any errors associated with the package and not report hypervior state in these cases. Tested: - Verified when phosphor-hypervisor-state-manager package is not installed that Redfish API returns same info it does currently - Verified when phosphor-hypervisor-state-manager was installed that the hypervisor state was returned correctly. - The redfish validator was run on the final patch in this series Change-Id: I3843914894ded9494f92b96714c1f88a5deb5ec3 Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Diffstat (limited to 'redfish-core/lib/hypervisor_system.hpp')
-rw-r--r--redfish-core/lib/hypervisor_system.hpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 10b16f9656..4ec88fd51f 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -15,6 +15,85 @@ namespace redfish
{
/**
+ * @brief Retrieves hypervisor state properties over dbus
+ *
+ * The hypervisor state object is optional so this function will only set the
+ * state variables if the object is found
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls.
+ *
+ * @return None.
+ */
+inline void getHypervisorState(const std::shared_ptr<AsyncResp>& aResp)
+{
+ BMCWEB_LOG_DEBUG << "Get hypervisor state information.";
+ crow::connections::systemBus->async_method_call(
+ [aResp](const boost::system::error_code ec,
+ const std::variant<std::string>& hostState) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ // This is an optional D-Bus object so just return if
+ // error occurs
+ return;
+ }
+
+ const std::string* s = std::get_if<std::string>(&hostState);
+ if (s == nullptr)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ BMCWEB_LOG_DEBUG << "Hypervisor state: " << *s;
+ // Verify Host State
+ if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
+ }
+ else if (*s == "xyz.openbmc_project.State.Host.HostState."
+ "Quiesced")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Quiesced";
+ }
+ else if (*s == "xyz.openbmc_project.State.Host.HostState."
+ "Standby")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
+ }
+ else if (*s == "xyz.openbmc_project.State.Host.HostState."
+ "TransitioningToRunning")
+ {
+ aResp->res.jsonValue["PowerState"] = "PoweringOn";
+ aResp->res.jsonValue["Status"]["State"] = "Starting";
+ }
+ else if (*s == "xyz.openbmc_project.State.Host.HostState."
+ "TransitioningToOff")
+ {
+ aResp->res.jsonValue["PowerState"] = "PoweringOff";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
+ }
+ else if (*s == "xyz.openbmc_project.State.Host.HostState.Off")
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] = "Disabled";
+ }
+ else
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+ },
+ "xyz.openbmc_project.State.Hypervisor",
+ "/xyz/openbmc_project/state/hypervisor0",
+ "org.freedesktop.DBus.Properties", "Get",
+ "xyz.openbmc_project.State.Host", "CurrentHostState");
+}
+
+/**
* Hypervisor Systems derived class for delivering Computer Systems Schema.
*/
class HypervisorSystem : public Node
@@ -62,6 +141,7 @@ class HypervisorSystem : public Node
asyncResp->res.jsonValue["EthernetInterfaces"] = {
{"@odata.id", "/redfish/v1/Systems/hypervisor/"
"EthernetInterfaces"}};
+ getHypervisorState(asyncResp);
// TODO: Add "SystemType" : "hypervisor"
},
"xyz.openbmc_project.Settings",