#pragma once #include "bmcweb_config.h" #include "async_resp.hpp" #include "dbus_utility.hpp" #include "error_messages.hpp" #include "human_sort.hpp" #include "logging.hpp" #include "utility.hpp" #include #include #include #include #include #include #include #include #include #include #include namespace redfish { inline void handleSystemCollectionMembers( const std::shared_ptr& asyncResp, const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& objects) { if (ec == boost::system::errc::io_error) { asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); asyncResp->res.jsonValue["Members@odata.count"] = 0; return; } if (ec) { BMCWEB_LOG_ERROR("DBUS response error {}", ec.value()); messages::internalError(asyncResp->res); return; } nlohmann::json& membersArray = asyncResp->res.jsonValue["Members"]; membersArray = nlohmann::json::array(); // consider an empty result as single-host, since single-host systems // do not populate the ManagedHost dbus interface if (objects.empty()) { asyncResp->res.jsonValue["Members@odata.count"] = 1; nlohmann::json::object_t system; system["@odata.id"] = boost::urls::format( "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); membersArray.emplace_back(std::move(system)); 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"; membersArray.emplace_back(std::move(hypervisor)); } return; } std::vector pathNames; for (const auto& object : objects) { sdbusplus::message::object_path path(object); std::string leaf = path.filename(); if (leaf.empty()) { continue; } pathNames.emplace_back(leaf); } std::ranges::sort(pathNames, AlphanumLess()); for (const std::string& systemName : pathNames) { boost::urls::url url("/redfish/v1/Systems"); crow::utility::appendUrlPieces(url, systemName); nlohmann::json::object_t member; member["@odata.id"] = std::move(url); membersArray.emplace_back(std::move(member)); } asyncResp->res.jsonValue["Members@odata.count"] = membersArray.size(); } /** * @brief Populate the system collection members from a GetSubTreePaths search * of the inventory based of the ManagedHost dbus interface * * @param[i] asyncResp Async response object * * @return None */ inline void getSystemCollectionMembers( const std::shared_ptr& asyncResp) { constexpr std::array interfaces{ "xyz.openbmc_project.Inventory.Decorator.ManagedHost", }; BMCWEB_LOG_DEBUG("Get system collection members for /redfish/v1/Systems"); dbus::utility::getSubTreePaths( "/xyz/openbmc_project/inventory", 0, interfaces, std::bind_front(handleSystemCollectionMembers, asyncResp)); } } // namespace redfish