Skip to content

Commit

Permalink
Introducing systems_utils.hpp and getSystemCollectionMembers
Browse files Browse the repository at this point in the history
This change introduces a new a function similar to getCollectionMembers
but specific to computerSystem discovery. Since more
functionality will be added soon to support multi host redfish
and in general request handling with the long term goal not using
hardcoded URIs anymore, a new utility header for systems.hpp is being
introduced in this patch that will hold the rest of the incoming
definitions.

getSystemCollectionMembers supports multi host platforms like
yosemite4 or bletchley. Currently we have to distinguish between single
and multi host platforms and unfortunately handle both separate
from each other, thus cannot use the generic getCollectionMembers from
collection.hpp. However, this should change sometime in the future.
It should be mentioned, that functionalitywise the newly introduced
function shares almost all of the code used in getCollectionMembers from
collection.hpp. Only simplification has been done, since this function
only serves a single usecase.

Testing: To test the functionality, requests have been manually made
to check the response for both, single and multi host emulated in qemu.
For the multi host platform a yosemite4 image with 8 emulated eeproms
has been used, single host was performed on the same image with only 1
emulated eeprom that EM would probe against to identify an available
host.

"single host"
{
  "@odata.id": "/redfish/v1/Systems",
  "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
  "Members": [
    {
      "@odata.id": "/redfish/v1/Systems/system"
    }
  ],
  "[email protected]": 1,
  "Name": "Computer System Collection"
}

multi host
{
  "@odata.id": "/redfish/v1/Systems",
  "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
  "Members": [
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_1"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_2"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_3"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_4"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_5"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_6"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_7"
},
{
  "@odata.id": "/redfish/v1/Systems/Yosemite_4_Sentinel_Dome_T1_Slot_8"
}
  ],
  "[email protected]": 8,
  "Name": "Computer System Collection"
}%

Change-Id: I82d59487b7c17b22cd638acd8f687f31c96ca156
Signed-off-by: Oliver Brewka <[email protected]>
  • Loading branch information
Oliver Brewka committed Nov 30, 2024
1 parent 2185dde commit 545871e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 23 deletions.
110 changes: 110 additions & 0 deletions redfish-core/include/utils/systems_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once

#include "async_resp.hpp"
#include "dbus_utility.hpp"
#include "error_messages.hpp"
#include "human_sort.hpp"

#include <boost/url/format.hpp>

#include <string_view>

namespace redfish
{

inline void handleSystemCollectionMembers(
const std::shared_ptr<bmcweb::AsyncResp>& 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["[email protected]"] = 0;
return;
}

if (ec)
{
BMCWEB_LOG_DEBUG("DBUS response error {}", ec.value());
messages::internalError(asyncResp->res);
return;
}

nlohmann::json& membersArray = asyncResp->res.jsonValue["Members"];
membersArray = nlohmann::json::array();

if (objects.size() == 1)
{
asyncResp->res.jsonValue["[email protected]"] = 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["[email protected]"] = 2;

nlohmann::json::object_t hypervisor;
hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
membersArray.emplace_back(std::move(hypervisor));
}

return;
}

std::vector<std::string> pathNames;
for (const auto& object : objects)
{
sdbusplus::message::object_path path(object);
std::string leaf = path.filename();
// ManagedHost interface is implemented on both, Board and Chassis
// configuration for yv4. Filter out the Chassis ones.
if (leaf.empty() || (leaf.find("Chassis") != std::string::npos))
{
continue;
}
pathNames.push_back(leaf);
}
std::ranges::sort(pathNames, AlphanumLess<std::string>());

for (const std::string& l : pathNames)
{
boost::urls::url url("/redfish/v1/Systems");
crow::utility::appendUrlPieces(url, l);
nlohmann::json::object_t member;
member["@odata.id"] = std::move(url);
membersArray.emplace_back(std::move(member));
}
asyncResp->res.jsonValue["[email protected]"] = membersArray.size();
}

/**
* @brief Populate the system collection members from a GetSubTreePaths search
* of inventory
*
* @param[i,o] asyncResp Async response object
* @param[i] collectionPath Redfish collection path which is used for the
* Members Redfish Path
* @param[i] interfaces List of interfaces to constrain the GetSubTree search
* @param[in] subtree D-Bus base path to constrain search to.
* @param[in] jsonKeyName Key name in which the collection members will be
* stored.
*
* @return void
*/
inline void getSystemCollectionMembers(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
constexpr std::array<std::string_view, 1> 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
25 changes: 2 additions & 23 deletions redfish-core/lib/systems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ limitations under the License.
#include "utils/json_utils.hpp"
#include "utils/pcie_util.hpp"
#include "utils/sw_utils.hpp"
#include "utils/systems_utils.hpp"
#include "utils/time_utils.hpp"

#include <boost/asio/error.hpp>
Expand Down Expand Up @@ -2814,29 +2815,7 @@ inline void handleComputerSystemCollectionGet(
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 (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
{
asyncResp->res.jsonValue["[email protected]"] = 0;
// Option currently returns no systems. TBD
return;
}
asyncResp->res.jsonValue["[email protected]"] = 1;
nlohmann::json::object_t system;
system["@odata.id"] = boost::urls::format("/redfish/v1/Systems/{}",
BMCWEB_REDFISH_SYSTEM_URI_NAME);
ifaceArray.emplace_back(std::move(system));

if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM)
{
BMCWEB_LOG_DEBUG("Hypervisor is available");
asyncResp->res.jsonValue["[email protected]"] = 2;

nlohmann::json::object_t hypervisor;
hypervisor["@odata.id"] = "/redfish/v1/Systems/hypervisor";
ifaceArray.emplace_back(std::move(hypervisor));
}
getSystemCollectionMembers(asyncResp);
}

/**
Expand Down

0 comments on commit 545871e

Please sign in to comment.