Skip to content

Commit 3a93bbb

Browse files
author
Oliver Brewka
committed
WIP: managers.hpp - support for multi-host
This change adds multi-host support in manager.hpp. Mainly returning all valid redfish links for the ManagerForServers array. In addition we opt out of calling getMainChassisId when on multi-host. Needs more clarification what exactly should be returned for that, if anything. Testing: TBD Change-Id: Ia73cabc23cd87128a59df5c7b16af0bf87462925 Signed-off-by: Oliver Brewka <mox669.dev@gmail.com>
1 parent 1a8d3b3 commit 3a93bbb

File tree

1 file changed

+69
-18
lines changed

1 file changed

+69
-18
lines changed

redfish-core/lib/managers.hpp

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "redfish.hpp"
2121
#include "redfish_util.hpp"
2222
#include "registries/privilege_registry.hpp"
23+
#include "utility.hpp"
2324
#include "utils/dbus_utils.hpp"
2425
#include "utils/json_utils.hpp"
2526
#include "utils/sw_utils.hpp"
@@ -695,6 +696,49 @@ inline void requestRoutesManager(App& app)
695696
asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
696697
std::move(managerForServers);
697698
}
699+
else
700+
{
701+
// multi-host bmc manages multiple hosts
702+
constexpr std::array<std::string_view, 1> interfaces{
703+
"xyz.openbmc_project.Inventory.Decorator.ManagedHost"};
704+
dbus::utility::getSubTree(
705+
"/xyz/openbmc_project/inventory", 0, interfaces,
706+
[asyncResp](const boost::system::error_code& ec,
707+
const dbus::utility::MapperGetSubTreeResponse&
708+
subtree) {
709+
if (ec)
710+
{
711+
if (ec.value() == boost::system::errc::io_error)
712+
{
713+
// TODO 03/07/25-15:45 olek: proper error
714+
// return
715+
return;
716+
}
717+
718+
BMCWEB_LOG_ERROR(
719+
"DBus method call failed with error {}",
720+
ec.value());
721+
messages::internalError(asyncResp->res);
722+
return;
723+
}
724+
725+
nlohmann::json::array_t managerForServers;
726+
for (const auto& [path, serviceMap] : subtree)
727+
{
728+
boost::urls::url url("/redfish/v1/Systems");
729+
std::string systemId =
730+
sdbusplus::message::object_path(path)
731+
.filename();
732+
crow::utility::appendUrlPieces(url, systemId);
733+
BMCWEB_LOG_DEBUG("Got url: {}", url);
734+
nlohmann::json::object_t member;
735+
member["@odata.id"] = std::move(url);
736+
managerForServers.emplace_back(member);
737+
}
738+
asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
739+
std::move(managerForServers);
740+
});
741+
}
698742

699743
sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
700744
"FirmwareVersion", true);
@@ -708,22 +752,29 @@ inline void requestRoutesManager(App& app)
708752
"/redfish/v1/Managers/{}/ManagerDiagnosticData",
709753
BMCWEB_REDFISH_MANAGER_URI_NAME);
710754

711-
getMainChassisId(asyncResp, [](const std::string& chassisId,
712-
const std::shared_ptr<
713-
bmcweb::AsyncResp>& aRsp) {
714-
aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] =
715-
1;
716-
nlohmann::json::array_t managerForChassis;
717-
nlohmann::json::object_t managerObj;
718-
boost::urls::url chassiUrl =
719-
boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
720-
managerObj["@odata.id"] = chassiUrl;
721-
managerForChassis.emplace_back(std::move(managerObj));
722-
aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
723-
std::move(managerForChassis);
724-
aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
725-
chassiUrl;
726-
});
755+
// Chassis is currently not supported on multi-host. Excluded here
756+
// for Redfish Service Validator to pass. TBD
757+
if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
758+
{
759+
getMainChassisId(
760+
asyncResp,
761+
[](const std::string& chassisId,
762+
const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
763+
aRsp->res.jsonValue["Links"]
764+
["ManagerForChassis@odata.count"] =
765+
1;
766+
nlohmann::json::array_t managerForChassis;
767+
nlohmann::json::object_t managerObj;
768+
boost::urls::url chassiUrl = boost::urls::format(
769+
"/redfish/v1/Chassis/{}", chassisId);
770+
managerObj["@odata.id"] = chassiUrl;
771+
managerForChassis.emplace_back(std::move(managerObj));
772+
aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
773+
std::move(managerForChassis);
774+
aRsp->res.jsonValue["Links"]["ManagerInChassis"]
775+
["@odata.id"] = chassiUrl;
776+
});
777+
}
727778

728779
dbus::utility::getProperty<double>(
729780
"org.freedesktop.systemd1", "/org/freedesktop/systemd1",
@@ -942,8 +993,8 @@ inline void requestRoutesManagerCollection(App& app)
942993
{
943994
return;
944995
}
945-
// Collections don't include the static data added by SubRoute
946-
// because it has a duplicate entry for members
996+
// Collections don't include the static data added by
997+
// SubRoute because it has a duplicate entry for members
947998
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
948999
asyncResp->res.jsonValue["@odata.type"] =
9491000
"#ManagerCollection.ManagerCollection";

0 commit comments

Comments
 (0)