Skip to content

Commit 02f6ff1

Browse files
committed
Chassis Collection: Use getCollectionMembers
Improves code reuse. Tested: Validator passes. curl -k https://$bmc/redfish/v1/Chassis/ { "@odata.id": "/redfish/v1/Chassis", "@odata.type": "#ChassisCollection.ChassisCollection", "Members": [ { "@odata.id": "/redfish/v1/Chassis/chassis" }, { "@odata.id": "/redfish/v1/Chassis/motherboard" } ], "[email protected]": 2, "Name": "Chassis Collection" Change-Id: Ie26f93faec9498124ab1d5747aed8300414b6d96 Signed-off-by: Gunnar Mills <[email protected]>
1 parent 05030b8 commit 02f6ff1

File tree

1 file changed

+5
-41
lines changed

1 file changed

+5
-41
lines changed

Diff for: redfish-core/lib/chassis.hpp

+5-41
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "node.hpp"
2121

2222
#include <boost/container/flat_map.hpp>
23+
#include <utils/collection.hpp>
2324

2425
#include <variant>
2526

@@ -182,49 +183,12 @@ class ChassisCollection : public Node
182183
res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
183184
res.jsonValue["Name"] = "Chassis Collection";
184185

185-
const std::array<const char*, 2> interfaces = {
186-
"xyz.openbmc_project.Inventory.Item.Board",
187-
"xyz.openbmc_project.Inventory.Item.Chassis"};
188-
189186
auto asyncResp = std::make_shared<AsyncResp>(res);
190-
crow::connections::systemBus->async_method_call(
191-
[asyncResp](const boost::system::error_code ec,
192-
const std::vector<std::string>& chassisList) {
193-
if (ec)
194-
{
195-
messages::internalError(asyncResp->res);
196-
return;
197-
}
198-
nlohmann::json& chassisArray =
199-
asyncResp->res.jsonValue["Members"];
200-
chassisArray = nlohmann::json::array();
201-
for (const std::string& objpath : chassisList)
202-
{
203-
std::size_t lastPos = objpath.rfind("/");
204-
if (lastPos == std::string::npos)
205-
{
206-
BMCWEB_LOG_ERROR << "Failed to find '/' in " << objpath;
207-
messages::internalError(asyncResp->res);
208-
return;
209-
}
210-
if ((lastPos + 1) >= objpath.size())
211-
{
212-
BMCWEB_LOG_ERROR << "Failed to parse path " << objpath;
213-
messages::internalError(asyncResp->res);
214-
return;
215-
}
216-
chassisArray.push_back(
217-
{{"@odata.id", "/redfish/v1/Chassis/" +
218-
objpath.substr(lastPos + 1)}});
219-
}
220187

221-
asyncResp->res.jsonValue["[email protected]"] =
222-
chassisArray.size();
223-
},
224-
"xyz.openbmc_project.ObjectMapper",
225-
"/xyz/openbmc_project/object_mapper",
226-
"xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
227-
"/xyz/openbmc_project/inventory", 0, interfaces);
188+
collection_util::getCollectionMembers(
189+
asyncResp, "/redfish/v1/Chassis",
190+
{"xyz.openbmc_project.Inventory.Item.Board",
191+
"xyz.openbmc_project.Inventory.Item.Chassis"});
228192
}
229193
};
230194

0 commit comments

Comments
 (0)