Add a Hypervisor Computer System Option
Today to determine if the hypervisor computer system resource should be
added to the System Collection a call to the Settings Manager is made.
Based on discussion in
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/73203 and to help the
multihost stuff move forward, lets move this hypervisor under a meson
option which any company that needs can enable. I think IBM is the only
one who uses this so the risk of breaking someone should be small.
One day hope to converge at some point, this probably doesn't happen
until after the multihost stuff goes in.
This is also better for implementations that don't have this backend
because now routes like
/redfish/v1/Systems/hypervisor/EthernetInterfaces/ aren't put out. I.e.
a call to /redfish/v1/Systems/hypervisor/EthernetInterfaces/ is now
going to return 404 instead of 500 on systems without this backend
support.
Tested: Enabled this and see the hypervisor system. Without this enabled
do not see the hypervisor system. No new validator errors either way.
Change-Id: Ie05e6644dd6f640cf8225f96becb99b9c2d0de20
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index af1aaf9..1660e3b 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -709,42 +709,24 @@
inline void handleHypervisorSystemGet(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
- sdbusplus::asio::getProperty<std::string>(
- *crow::connections::systemBus, "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/network/hypervisor",
- "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
- [asyncResp](const boost::system::error_code& ec,
- const std::string& /*hostName*/) {
- if (ec)
- {
- messages::resourceNotFound(asyncResp->res, "System",
- "hypervisor");
- return;
- }
- BMCWEB_LOG_DEBUG("Hypervisor is available");
-
- asyncResp->res.jsonValue["@odata.type"] =
- "#ComputerSystem.v1_6_0.ComputerSystem";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/hypervisor";
- asyncResp->res.jsonValue["Description"] = "Hypervisor";
- asyncResp->res.jsonValue["Name"] = "Hypervisor";
- asyncResp->res.jsonValue["Id"] = "hypervisor";
- asyncResp->res.jsonValue["SystemType"] =
- computer_system::SystemType::OS;
- nlohmann::json::array_t managedBy;
- nlohmann::json::object_t manager;
- manager["@odata.id"] = boost::urls::format(
- "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
- managedBy.emplace_back(std::move(manager));
- asyncResp->res.jsonValue["Links"]["ManagedBy"] =
- std::move(managedBy);
- asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
- "/redfish/v1/Systems/hypervisor/EthernetInterfaces";
- getHypervisorState(asyncResp);
- getHypervisorActions(asyncResp);
- // TODO: Add "SystemType" : "hypervisor"
- });
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ComputerSystem.v1_6_0.ComputerSystem";
+ asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/hypervisor";
+ asyncResp->res.jsonValue["Description"] = "Hypervisor";
+ asyncResp->res.jsonValue["Name"] = "Hypervisor";
+ asyncResp->res.jsonValue["Id"] = "hypervisor";
+ asyncResp->res.jsonValue["SystemType"] = computer_system::SystemType::OS;
+ nlohmann::json::array_t managedBy;
+ nlohmann::json::object_t manager;
+ manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
+ BMCWEB_REDFISH_MANAGER_URI_NAME);
+ managedBy.emplace_back(std::move(manager));
+ asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
+ asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
+ "/redfish/v1/Systems/hypervisor/EthernetInterfaces";
+ getHypervisorState(asyncResp);
+ getHypervisorActions(asyncResp);
+ // TODO: Add "SystemType" : "hypervisor"
}
inline void handleHypervisorEthernetInterfacePatch(
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index b87be5f..f90bb83 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -2827,35 +2827,16 @@
system["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}",
BMCWEB_REDFISH_SYSTEM_URI_NAME);
ifaceArray.emplace_back(std::move(system));
- sdbusplus::asio::getProperty<std::string>(
- *crow::connections::systemBus, "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/network/hypervisor",
- "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
- [asyncResp](const boost::system::error_code& ec2,
- const std::string& /*hostName*/) {
- if (ec2)
- {
- return;
- }
- auto val = asyncResp->res.jsonValue.find("Members@odata.count");
- if (val == asyncResp->res.jsonValue.end())
- {
- BMCWEB_LOG_CRITICAL("Count wasn't found??");
- return;
- }
- int64_t* count = val->get_ptr<int64_t*>();
- if (count == nullptr)
- {
- BMCWEB_LOG_CRITICAL("Count wasn't found??");
- return;
- }
- *count = *count + 1;
- BMCWEB_LOG_DEBUG("Hypervisor is available");
- nlohmann::json& ifaceArray2 = asyncResp->res.jsonValue["Members"];
- nlohmann::json::object_t hypervisor;
- hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
- ifaceArray2.emplace_back(std::move(hypervisor));
- });
+
+ if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
+ {
+ BMCWEB_LOG_DEBUG("Hypervisor is available");
+ asyncResp->res.jsonValue["Members@odata.count"] = 2;
+
+ nlohmann::json::object_t hypervisor;
+ hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
+ ifaceArray.emplace_back(std::move(hypervisor));
+ }
}
/**
@@ -3043,10 +3024,13 @@
return;
}
- if (systemName == "hypervisor")
+ if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
{
- handleHypervisorSystemGet(asyncResp);
- return;
+ if (systemName == "hypervisor")
+ {
+ handleHypervisorSystemGet(asyncResp);
+ return;
+ }
}
if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
@@ -3424,10 +3408,13 @@
return;
}
- if (systemName == "hypervisor")
+ if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
{
- handleHypervisorResetActionGet(asyncResp);
- return;
+ if (systemName == "hypervisor")
+ {
+ handleHypervisorResetActionGet(asyncResp);
+ return;
+ }
}
if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
diff --git a/redfish-core/src/redfish.cpp b/redfish-core/src/redfish.cpp
index e1e5ff1..e81691f 100644
--- a/redfish-core/src/redfish.cpp
+++ b/redfish-core/src/redfish.cpp
@@ -220,7 +220,10 @@
requestRoutesFabricAdapterCollection(app);
requestRoutesSubmitTestEvent(app);
- requestRoutesHypervisorSystems(app);
+ if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
+ {
+ requestRoutesHypervisorSystems(app);
+ }
requestRoutesTelemetryService(app);
requestRoutesMetricReportDefinitionCollection(app);