Add an option flag for multi-computersystem
A number of discussions have occurred, and it's clear that
multi-computer system is not a transition that can be done in a single
series of commits, and needs to be done incrementally over time. This
commit adds the initial option for multi-computer system support, with
an option flag that can be enabled when the new behavior is desired.
This is to prevent needing a long-lived fork.
This option operatates such that if enabled, all ComputerSystem route
options will now return 404. This is to allow the redfish service
validator to pass, and to be used for incremental development. As the
routes are moved over, they will be enabled, and service validator
re-run.
Per the description in the meson options, this option flag, and all code
beneath of it will be removed on 9/1/23. The expectation is that by
this date, given the appropriate level of effort in implementation,
there will be no code remaining under that option flag. After this
date, code beneath this option flag will be removed.
Tested: No functional changes without option.
With option enabled, /redfish/v1/Systems produces no entries.
Spot check of various routes returns 404.
Redfish service validator passes.
Change-Id: I3b58642cb76d61df668076c2e0f1e7bed110ae25
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 86730a5..26905bf 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -2833,28 +2833,46 @@
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
asyncResp->res.jsonValue["Name"] = "Computer System Collection";
+ nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
+ ifaceArray = nlohmann::json::array();
+ if constexpr (bmcwebEnableMultiHost)
+ {
+ asyncResp->res.jsonValue["Members@odata.count"] = 0;
+ // Option currently returns no systems. TBD
+ return;
+ }
+ asyncResp->res.jsonValue["Members@odata.count"] = 1;
+ nlohmann::json::object_t system;
+ system["@odata.id"] = "/redfish/v1/Systems/system";
+ 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*/) {
- nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"];
- ifaceArray = nlohmann::json::array();
- auto& count = asyncResp->res.jsonValue["Members@odata.count"];
-
- nlohmann::json::object_t system;
- system["@odata.id"] = "/redfish/v1/Systems/system";
- ifaceArray.emplace_back(std::move(system));
- count = ifaceArray.size();
- if (!ec2)
+ if (ec2)
{
- BMCWEB_LOG_DEBUG << "Hypervisor is available";
- nlohmann::json::object_t hypervisor;
- hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
- ifaceArray.emplace_back(std::move(hypervisor));
- count = ifaceArray.size();
+ return;
}
+ auto val = asyncResp->res.jsonValue.find("Members@odata.count");
+ if (val == asyncResp->res.jsonValue.end())
+ {
+ BMCWEB_LOG_CRITICAL << "Count wasn't found??";
+ return;
+ }
+ uint64_t* count = val->get_ptr<uint64_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));
});
});
}
@@ -2933,16 +2951,29 @@
* Function handles POST method request.
* Analyzes POST body message before sends Reset request data to D-Bus.
*/
- BMCWEB_ROUTE(app,
- "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/")
.privileges(redfish::privileges::postComputerSystem)
.methods(boost::beast::http::verb::post)(
[&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemId) {
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
return;
}
+ if constexpr (bmcwebEnableMultiHost)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemId);
+ return;
+ }
+ if (systemId != "system")
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemId);
+ return;
+ }
std::string resetType;
if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
resetType))
@@ -3041,7 +3072,8 @@
inline void handleComputerSystemCollectionHead(
App& app, const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& /*systemName*/)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
@@ -3094,7 +3126,7 @@
*/
inline void requestRoutesSystems(App& app)
{
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/")
.privileges(redfish::privileges::headComputerSystem)
.methods(boost::beast::http::verb::head)(
std::bind_front(handleComputerSystemCollectionHead, std::ref(app)));
@@ -3112,6 +3144,14 @@
return;
}
+ if constexpr (bmcwebEnableMultiHost)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+
if (systemName == "hypervisor")
{
handleHypervisorSystemGet(asyncResp);
@@ -3261,6 +3301,13 @@
{
return;
}
+ if constexpr (bmcwebEnableMultiHost)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
if (systemName != "system")
{
messages::resourceNotFound(asyncResp->res, "ComputerSystem",
@@ -3386,7 +3433,8 @@
inline void handleSystemCollectionResetActionHead(
crow::App& app, const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& /*systemId*/)
{
if (!redfish::setUpRedfishRoute(app, req, asyncResp))
{
@@ -3403,7 +3451,7 @@
*/
inline void requestRoutesSystemResetActionInfo(App& app)
{
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/ResetActionInfo/")
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/")
.privileges(redfish::privileges::headActionInfo)
.methods(boost::beast::http::verb::head)(std::bind_front(
handleSystemCollectionResetActionHead, std::ref(app)));
@@ -3420,6 +3468,13 @@
{
return;
}
+ if constexpr (bmcwebEnableMultiHost)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
if (systemName == "hypervisor")
{