blob: 5ec6b5c80f09fd0d53ae2e67fab7a1cfefbae427 [file] [log] [blame]
Nikhil Potadea25aecc2019-08-23 16:35:26 -07001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Willy Tu13451e32023-05-24 16:08:18 -070018#include "bmcweb_config.h"
19
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "app.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080021#include "dbus_utility.hpp"
John Edward Broadbente5029d82022-06-08 14:35:21 -070022#include "generated/enums/drive.hpp"
George Liudde9bc12023-02-22 09:35:51 +080023#include "generated/enums/protocol.hpp"
James Feist2ad9c2f2019-10-29 16:26:48 -070024#include "health.hpp"
Ed Tanousa8e884f2023-01-13 17:40:03 -080025#include "human_sort.hpp"
James Feiste284a7c2019-11-20 16:20:23 -080026#include "openbmc_dbus_rest.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080027#include "query.hpp"
Ed Tanousa8e884f2023-01-13 17:40:03 -080028#include "redfish_util.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080029#include "registries/privilege_registry.hpp"
30#include "utils/dbus_utils.hpp"
James Feist2ad9c2f2019-10-29 16:26:48 -070031
George Liue99073f2022-12-09 11:06:16 +080032#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070033#include <boost/url/format.hpp>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070034#include <sdbusplus/asio/property.hpp>
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +020035#include <sdbusplus/unpack_properties.hpp>
Nikhil Potadea25aecc2019-08-23 16:35:26 -070036
George Liu7a1dbc42022-12-07 16:03:22 +080037#include <array>
38#include <string_view>
39
Nikhil Potadea25aecc2019-08-23 16:35:26 -070040namespace redfish
41{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070042inline void requestRoutesStorageCollection(App& app)
Nikhil Potadea25aecc2019-08-23 16:35:26 -070043{
Ed Tanous22d268c2022-05-19 09:39:07 -070044 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/")
Ed Tanoused398212021-06-09 17:05:54 -070045 .privileges(redfish::privileges::getStorageCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070046 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070047 [&app](const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070048 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
49 const std::string& systemName) {
Carson Labrado3ba00072022-06-06 19:40:56 +000050 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -070051 {
52 return;
53 }
Ed Tanous22d268c2022-05-19 09:39:07 -070054 if (systemName != "system")
55 {
56 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
57 systemName);
58 return;
59 }
60
Ed Tanous002d39b2022-05-31 08:59:27 -070061 asyncResp->res.jsonValue["@odata.type"] =
62 "#StorageCollection.StorageCollection";
63 asyncResp->res.jsonValue["@odata.id"] =
64 "/redfish/v1/Systems/system/Storage";
65 asyncResp->res.jsonValue["Name"] = "Storage Collection";
66 nlohmann::json::array_t members;
67 nlohmann::json::object_t member;
68 member["@odata.id"] = "/redfish/v1/Systems/system/Storage/1";
69 members.emplace_back(member);
70 asyncResp->res.jsonValue["Members"] = std::move(members);
71 asyncResp->res.jsonValue["Members@odata.count"] = 1;
72 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -070073}
Nikhil Potadea25aecc2019-08-23 16:35:26 -070074
Willy Tua85afbe2021-12-28 14:43:47 -080075inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
76 const std::shared_ptr<HealthPopulate>& health)
77{
George Liu7a1dbc42022-12-07 16:03:22 +080078 const std::array<std::string_view, 1> interfaces = {
79 "xyz.openbmc_project.Inventory.Item.Drive"};
80 dbus::utility::getSubTreePaths(
81 "/xyz/openbmc_project/inventory", 0, interfaces,
Willy Tua85afbe2021-12-28 14:43:47 -080082 [asyncResp, health](
George Liu7a1dbc42022-12-07 16:03:22 +080083 const boost::system::error_code& ec,
Willy Tua85afbe2021-12-28 14:43:47 -080084 const dbus::utility::MapperGetSubTreePathsResponse& driveList) {
85 if (ec)
86 {
87 BMCWEB_LOG_ERROR << "Drive mapper call error";
88 messages::internalError(asyncResp->res);
89 return;
90 }
91
92 nlohmann::json& driveArray = asyncResp->res.jsonValue["Drives"];
93 driveArray = nlohmann::json::array();
94 auto& count = asyncResp->res.jsonValue["Drives@odata.count"];
95 count = 0;
96
Willy Tu13451e32023-05-24 16:08:18 -070097 if constexpr (bmcwebEnableHealthPopulate)
98 {
99 health->inventory.insert(health->inventory.end(), driveList.begin(),
100 driveList.end());
101 }
Willy Tua85afbe2021-12-28 14:43:47 -0800102
103 for (const std::string& drive : driveList)
104 {
105 sdbusplus::message::object_path object(drive);
106 if (object.filename().empty())
107 {
108 BMCWEB_LOG_ERROR << "Failed to find filename in " << drive;
109 return;
110 }
111
112 nlohmann::json::object_t driveJson;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700113 driveJson["@odata.id"] = boost::urls::format(
114 "/redfish/v1/Systems/system/Storage/1/Drives/{}",
Willy Tueddfc432022-09-26 16:46:38 +0000115 object.filename());
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500116 driveArray.emplace_back(std::move(driveJson));
Willy Tua85afbe2021-12-28 14:43:47 -0800117 }
118
119 count = driveArray.size();
George Liu7a1dbc42022-12-07 16:03:22 +0800120 });
Willy Tua85afbe2021-12-28 14:43:47 -0800121}
122
123inline void
124 getStorageControllers(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
125 const std::shared_ptr<HealthPopulate>& health)
126{
George Liue99073f2022-12-09 11:06:16 +0800127 constexpr std::array<std::string_view, 1> interfaces = {
128 "xyz.openbmc_project.Inventory.Item.StorageController"};
129 dbus::utility::getSubTree(
130 "/xyz/openbmc_project/inventory", 0, interfaces,
Willy Tua85afbe2021-12-28 14:43:47 -0800131 [asyncResp,
George Liue99073f2022-12-09 11:06:16 +0800132 health](const boost::system::error_code& ec,
Willy Tua85afbe2021-12-28 14:43:47 -0800133 const dbus::utility::MapperGetSubTreeResponse& subtree) {
134 if (ec || subtree.empty())
135 {
136 // doesn't have to be there
137 return;
138 }
139
140 nlohmann::json& root = asyncResp->res.jsonValue["StorageControllers"];
141 root = nlohmann::json::array();
142 for (const auto& [path, interfaceDict] : subtree)
143 {
144 sdbusplus::message::object_path object(path);
145 std::string id = object.filename();
146 if (id.empty())
147 {
148 BMCWEB_LOG_ERROR << "Failed to find filename in " << path;
149 return;
150 }
151
152 if (interfaceDict.size() != 1)
153 {
154 BMCWEB_LOG_ERROR << "Connection size " << interfaceDict.size()
155 << ", greater than 1";
156 messages::internalError(asyncResp->res);
157 return;
158 }
159
160 const std::string& connectionName = interfaceDict.front().first;
161
162 size_t index = root.size();
163 nlohmann::json& storageController =
164 root.emplace_back(nlohmann::json::object());
165
166 storageController["@odata.type"] =
167 "#Storage.v1_7_0.StorageController";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700168 storageController["@odata.id"] = boost::urls::format(
169 "/redfish/v1/Systems/system/Storage/1#{}",
170 ("/StorageControllers"_json_pointer / index).to_string());
Willy Tua85afbe2021-12-28 14:43:47 -0800171 storageController["Name"] = id;
172 storageController["MemberId"] = id;
173 storageController["Status"]["State"] = "Enabled";
174
175 sdbusplus::asio::getProperty<bool>(
176 *crow::connections::systemBus, connectionName, path,
177 "xyz.openbmc_project.Inventory.Item", "Present",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800178 [asyncResp, index](const boost::system::error_code& ec2,
Willy Tucef57e82022-12-15 16:42:02 -0800179 bool isPresent) {
Willy Tua85afbe2021-12-28 14:43:47 -0800180 // this interface isn't necessary, only check it
181 // if we get a good return
182 if (ec2)
183 {
184 return;
185 }
Willy Tucef57e82022-12-15 16:42:02 -0800186 if (!isPresent)
Willy Tua85afbe2021-12-28 14:43:47 -0800187 {
188 asyncResp->res.jsonValue["StorageControllers"][index]
Willy Tucef57e82022-12-15 16:42:02 -0800189 ["Status"]["State"] = "Absent";
Willy Tua85afbe2021-12-28 14:43:47 -0800190 }
191 });
192
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200193 sdbusplus::asio::getAllProperties(
194 *crow::connections::systemBus, connectionName, path,
195 "xyz.openbmc_project.Inventory.Decorator.Asset",
Willy Tua85afbe2021-12-28 14:43:47 -0800196 [asyncResp, index](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800197 const boost::system::error_code& ec2,
Willy Tua85afbe2021-12-28 14:43:47 -0800198 const std::vector<
199 std::pair<std::string, dbus::utility::DbusVariantType>>&
200 propertiesList) {
201 if (ec2)
202 {
203 // this interface isn't necessary
204 return;
205 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200206
207 const std::string* partNumber = nullptr;
208 const std::string* serialNumber = nullptr;
209 const std::string* manufacturer = nullptr;
210 const std::string* model = nullptr;
211
212 const bool success = sdbusplus::unpackPropertiesNoThrow(
213 dbus_utils::UnpackErrorPrinter(), propertiesList,
214 "PartNumber", partNumber, "SerialNumber", serialNumber,
215 "Manufacturer", manufacturer, "Model", model);
216
217 if (!success)
Willy Tua85afbe2021-12-28 14:43:47 -0800218 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200219 messages::internalError(asyncResp->res);
220 return;
Willy Tua85afbe2021-12-28 14:43:47 -0800221 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200222
223 nlohmann::json& controller =
224 asyncResp->res.jsonValue["StorageControllers"][index];
225
226 if (partNumber != nullptr)
227 {
228 controller["PartNumber"] = *partNumber;
229 }
230
231 if (serialNumber != nullptr)
232 {
233 controller["SerialNumber"] = *serialNumber;
234 }
235
236 if (manufacturer != nullptr)
237 {
238 controller["Manufacturer"] = *manufacturer;
239 }
240
241 if (model != nullptr)
242 {
243 controller["Model"] = *model;
244 }
245 });
Willy Tua85afbe2021-12-28 14:43:47 -0800246 }
247
Willy Tu13451e32023-05-24 16:08:18 -0700248 if constexpr (bmcwebEnableHealthPopulate)
Willy Tua85afbe2021-12-28 14:43:47 -0800249 {
Willy Tu13451e32023-05-24 16:08:18 -0700250 // this is done after we know the json array will no longer
251 // be resized, as json::array uses vector underneath and we
252 // need references to its members that won't change
253 size_t count = 0;
254 // Pointer based on |asyncResp->res.jsonValue|
255 nlohmann::json::json_pointer rootPtr =
256 "/StorageControllers"_json_pointer;
257 for (const auto& [path, interfaceDict] : subtree)
258 {
259 auto subHealth = std::make_shared<HealthPopulate>(
260 asyncResp, rootPtr / count / "Status");
261 subHealth->inventory.emplace_back(path);
262 health->inventory.emplace_back(path);
263 health->children.emplace_back(subHealth);
264 count++;
265 }
Willy Tua85afbe2021-12-28 14:43:47 -0800266 }
George Liue99073f2022-12-09 11:06:16 +0800267 });
Willy Tua85afbe2021-12-28 14:43:47 -0800268}
269
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700270inline void requestRoutesStorage(App& app)
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700271{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700272 BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/")
Ed Tanoused398212021-06-09 17:05:54 -0700273 .privileges(redfish::privileges::getStorage)
Ed Tanous002d39b2022-05-31 08:59:27 -0700274 .methods(boost::beast::http::verb::get)(
275 [&app](const crow::Request& req,
276 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000277 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700278 {
279 return;
280 }
281 asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_7_1.Storage";
282 asyncResp->res.jsonValue["@odata.id"] =
283 "/redfish/v1/Systems/system/Storage/1";
284 asyncResp->res.jsonValue["Name"] = "Storage";
285 asyncResp->res.jsonValue["Id"] = "1";
286 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
287
288 auto health = std::make_shared<HealthPopulate>(asyncResp);
Willy Tu13451e32023-05-24 16:08:18 -0700289 if constexpr (bmcwebEnableHealthPopulate)
290 {
291 health->populate();
292 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700293
Willy Tua85afbe2021-12-28 14:43:47 -0800294 getDrives(asyncResp, health);
295 getStorageControllers(asyncResp, health);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700296 });
297}
298
Willy Tu03913172021-11-08 02:03:19 -0800299inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
300 const std::string& connectionName,
301 const std::string& path)
302{
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200303 sdbusplus::asio::getAllProperties(
304 *crow::connections::systemBus, connectionName, path,
305 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800306 [asyncResp](const boost::system::error_code& ec,
Ed Tanous168e20c2021-12-13 14:39:53 -0800307 const std::vector<
308 std::pair<std::string, dbus::utility::DbusVariantType>>&
309 propertiesList) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700310 if (ec)
311 {
312 // this interface isn't necessary
313 return;
314 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200315
316 const std::string* partNumber = nullptr;
317 const std::string* serialNumber = nullptr;
318 const std::string* manufacturer = nullptr;
319 const std::string* model = nullptr;
320
321 const bool success = sdbusplus::unpackPropertiesNoThrow(
322 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
323 partNumber, "SerialNumber", serialNumber, "Manufacturer",
324 manufacturer, "Model", model);
325
326 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -0700327 {
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200328 messages::internalError(asyncResp->res);
329 return;
Ed Tanous002d39b2022-05-31 08:59:27 -0700330 }
Krzysztof Grobelnyd1bde9e2022-09-07 10:40:51 +0200331
332 if (partNumber != nullptr)
333 {
334 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
335 }
336
337 if (serialNumber != nullptr)
338 {
339 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
340 }
341
342 if (manufacturer != nullptr)
343 {
344 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
345 }
346
347 if (model != nullptr)
348 {
349 asyncResp->res.jsonValue["Model"] = *model;
350 }
351 });
Willy Tu03913172021-11-08 02:03:19 -0800352}
353
354inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
355 const std::string& connectionName,
356 const std::string& path)
357{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700358 sdbusplus::asio::getProperty<bool>(
359 *crow::connections::systemBus, connectionName, path,
360 "xyz.openbmc_project.Inventory.Item", "Present",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800361 [asyncResp, path](const boost::system::error_code& ec,
Willy Tucef57e82022-12-15 16:42:02 -0800362 const bool isPresent) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700363 // this interface isn't necessary, only check it if
364 // we get a good return
365 if (ec)
366 {
367 return;
368 }
Willy Tu03913172021-11-08 02:03:19 -0800369
Willy Tucef57e82022-12-15 16:42:02 -0800370 if (!isPresent)
Ed Tanous002d39b2022-05-31 08:59:27 -0700371 {
Willy Tucef57e82022-12-15 16:42:02 -0800372 asyncResp->res.jsonValue["Status"]["State"] = "Absent";
Ed Tanous002d39b2022-05-31 08:59:27 -0700373 }
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700374 });
Willy Tu03913172021-11-08 02:03:19 -0800375}
376
377inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
378 const std::string& connectionName,
379 const std::string& path)
380{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700381 sdbusplus::asio::getProperty<bool>(
382 *crow::connections::systemBus, connectionName, path,
383 "xyz.openbmc_project.State.Drive", "Rebuilding",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800384 [asyncResp](const boost::system::error_code& ec, const bool updating) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700385 // this interface isn't necessary, only check it
386 // if we get a good return
387 if (ec)
388 {
389 return;
390 }
Willy Tu03913172021-11-08 02:03:19 -0800391
Ed Tanous002d39b2022-05-31 08:59:27 -0700392 // updating and disabled in the backend shouldn't be
393 // able to be set at the same time, so we don't need
394 // to check for the race condition of these two
395 // calls
396 if (updating)
397 {
398 asyncResp->res.jsonValue["Status"]["State"] = "Updating";
399 }
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700400 });
Willy Tu03913172021-11-08 02:03:19 -0800401}
402
George Liudde9bc12023-02-22 09:35:51 +0800403inline std::optional<drive::MediaType> convertDriveType(std::string_view type)
Willy Tu19b8e9a2021-11-08 02:55:03 -0800404{
405 if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.HDD")
406 {
George Liudde9bc12023-02-22 09:35:51 +0800407 return drive::MediaType::HDD;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800408 }
409 if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.SSD")
410 {
George Liudde9bc12023-02-22 09:35:51 +0800411 return drive::MediaType::SSD;
412 }
413 if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.Unknown")
414 {
415 return std::nullopt;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800416 }
417
George Liudde9bc12023-02-22 09:35:51 +0800418 return drive::MediaType::Invalid;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800419}
420
George Liudde9bc12023-02-22 09:35:51 +0800421inline std::optional<protocol::Protocol>
422 convertDriveProtocol(std::string_view proto)
Willy Tu19b8e9a2021-11-08 02:55:03 -0800423{
424 if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SAS")
425 {
George Liudde9bc12023-02-22 09:35:51 +0800426 return protocol::Protocol::SAS;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800427 }
428 if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SATA")
429 {
George Liudde9bc12023-02-22 09:35:51 +0800430 return protocol::Protocol::SATA;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800431 }
432 if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.NVMe")
433 {
George Liudde9bc12023-02-22 09:35:51 +0800434 return protocol::Protocol::NVMe;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800435 }
436 if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.FC")
437 {
George Liudde9bc12023-02-22 09:35:51 +0800438 return protocol::Protocol::FC;
439 }
440 if (proto ==
441 "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.Unknown")
442 {
443 return std::nullopt;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800444 }
445
George Liudde9bc12023-02-22 09:35:51 +0800446 return protocol::Protocol::Invalid;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800447}
448
449inline void
450 getDriveItemProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
451 const std::string& connectionName,
452 const std::string& path)
453{
454 sdbusplus::asio::getAllProperties(
455 *crow::connections::systemBus, connectionName, path,
456 "xyz.openbmc_project.Inventory.Item.Drive",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800457 [asyncResp](const boost::system::error_code& ec,
Willy Tu19b8e9a2021-11-08 02:55:03 -0800458 const std::vector<
459 std::pair<std::string, dbus::utility::DbusVariantType>>&
460 propertiesList) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700461 if (ec)
462 {
463 // this interface isn't required
464 return;
465 }
John Edward Broadbente5029d82022-06-08 14:35:21 -0700466 const std::string* encryptionStatus = nullptr;
467 const bool* isLocked = nullptr;
Ed Tanous002d39b2022-05-31 08:59:27 -0700468 for (const std::pair<std::string, dbus::utility::DbusVariantType>&
469 property : propertiesList)
470 {
471 const std::string& propertyName = property.first;
472 if (propertyName == "Type")
Willy Tu19b8e9a2021-11-08 02:55:03 -0800473 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700474 const std::string* value =
475 std::get_if<std::string>(&property.second);
476 if (value == nullptr)
477 {
478 // illegal property
479 BMCWEB_LOG_ERROR << "Illegal property: Type";
480 messages::internalError(asyncResp->res);
481 return;
482 }
483
George Liudde9bc12023-02-22 09:35:51 +0800484 std::optional<drive::MediaType> mediaType =
485 convertDriveType(*value);
Ed Tanous002d39b2022-05-31 08:59:27 -0700486 if (!mediaType)
487 {
George Liudde9bc12023-02-22 09:35:51 +0800488 BMCWEB_LOG_WARNING << "UnknownDriveType Interface: "
489 << *value;
490 continue;
491 }
492 if (*mediaType == drive::MediaType::Invalid)
493 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700494 messages::internalError(asyncResp->res);
495 return;
496 }
497
498 asyncResp->res.jsonValue["MediaType"] = *mediaType;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800499 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700500 else if (propertyName == "Capacity")
Willy Tu19b8e9a2021-11-08 02:55:03 -0800501 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700502 const uint64_t* capacity =
503 std::get_if<uint64_t>(&property.second);
504 if (capacity == nullptr)
Willy Tu19b8e9a2021-11-08 02:55:03 -0800505 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700506 BMCWEB_LOG_ERROR << "Illegal property: Capacity";
507 messages::internalError(asyncResp->res);
508 return;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800509 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700510 if (*capacity == 0)
Willy Tu19b8e9a2021-11-08 02:55:03 -0800511 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700512 // drive capacity not known
513 continue;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800514 }
Willy Tu19b8e9a2021-11-08 02:55:03 -0800515
Ed Tanous002d39b2022-05-31 08:59:27 -0700516 asyncResp->res.jsonValue["CapacityBytes"] = *capacity;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800517 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700518 else if (propertyName == "Protocol")
519 {
520 const std::string* value =
521 std::get_if<std::string>(&property.second);
522 if (value == nullptr)
523 {
524 BMCWEB_LOG_ERROR << "Illegal property: Protocol";
525 messages::internalError(asyncResp->res);
526 return;
527 }
528
George Liudde9bc12023-02-22 09:35:51 +0800529 std::optional<protocol::Protocol> proto =
530 convertDriveProtocol(*value);
Ed Tanous002d39b2022-05-31 08:59:27 -0700531 if (!proto)
532 {
George Liudde9bc12023-02-22 09:35:51 +0800533 BMCWEB_LOG_WARNING << "Unknown DrivePrototype Interface: "
534 << *value;
535 continue;
536 }
537 if (*proto == protocol::Protocol::Invalid)
538 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700539 messages::internalError(asyncResp->res);
540 return;
541 }
542 asyncResp->res.jsonValue["Protocol"] = *proto;
543 }
John Edward Broadbent3fe4d5c2022-05-06 14:42:35 -0700544 else if (propertyName == "PredictedMediaLifeLeftPercent")
545 {
546 const uint8_t* lifeLeft =
547 std::get_if<uint8_t>(&property.second);
548 if (lifeLeft == nullptr)
549 {
550 BMCWEB_LOG_ERROR
551 << "Illegal property: PredictedMediaLifeLeftPercent";
552 messages::internalError(asyncResp->res);
553 return;
554 }
555 // 255 means reading the value is not supported
556 if (*lifeLeft != 255)
557 {
558 asyncResp->res.jsonValue["PredictedMediaLifeLeftPercent"] =
559 *lifeLeft;
560 }
561 }
John Edward Broadbente5029d82022-06-08 14:35:21 -0700562 else if (propertyName == "EncryptionStatus")
563 {
564 encryptionStatus = std::get_if<std::string>(&property.second);
565 if (encryptionStatus == nullptr)
566 {
567 BMCWEB_LOG_ERROR << "Illegal property: EncryptionStatus";
568 messages::internalError(asyncResp->res);
569 return;
570 }
571 }
572 else if (propertyName == "Locked")
573 {
574 isLocked = std::get_if<bool>(&property.second);
575 if (isLocked == nullptr)
576 {
577 BMCWEB_LOG_ERROR << "Illegal property: Locked";
578 messages::internalError(asyncResp->res);
579 return;
580 }
581 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700582 }
John Edward Broadbente5029d82022-06-08 14:35:21 -0700583
584 if (encryptionStatus == nullptr || isLocked == nullptr ||
585 *encryptionStatus ==
586 "xyz.openbmc_project.Drive.DriveEncryptionState.Unknown")
587 {
588 return;
589 }
590 if (*encryptionStatus !=
591 "xyz.openbmc_project.Drive.DriveEncryptionState.Encrypted")
592 {
593 //"The drive is not currently encrypted."
594 asyncResp->res.jsonValue["EncryptionStatus"] =
595 drive::EncryptionStatus::Unencrypted;
596 return;
597 }
598 if (*isLocked)
599 {
600 //"The drive is currently encrypted and the data is not
601 // accessible to the user."
602 asyncResp->res.jsonValue["EncryptionStatus"] =
603 drive::EncryptionStatus::Locked;
604 return;
605 }
606 // if not locked
607 // "The drive is currently encrypted but the data is accessible
608 // to the user in unencrypted form."
609 asyncResp->res.jsonValue["EncryptionStatus"] =
610 drive::EncryptionStatus::Unlocked;
Willy Tu19b8e9a2021-11-08 02:55:03 -0800611 });
612}
613
Nan Zhoub53dcd92022-06-21 17:47:50 +0000614static void addAllDriveInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
615 const std::string& connectionName,
616 const std::string& path,
617 const std::vector<std::string>& interfaces)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700618{
619 for (const std::string& interface : interfaces)
620 {
621 if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
622 {
623 getDriveAsset(asyncResp, connectionName, path);
624 }
625 else if (interface == "xyz.openbmc_project.Inventory.Item")
626 {
627 getDrivePresent(asyncResp, connectionName, path);
628 }
629 else if (interface == "xyz.openbmc_project.State.Drive")
630 {
631 getDriveState(asyncResp, connectionName, path);
632 }
633 else if (interface == "xyz.openbmc_project.Inventory.Item.Drive")
634 {
635 getDriveItemProperties(asyncResp, connectionName, path);
636 }
637 }
638}
639
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700640inline void requestRoutesDrive(App& app)
641{
Ed Tanous22d268c2022-05-19 09:39:07 -0700642 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Drives/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700643 .privileges(redfish::privileges::getDrive)
Ed Tanous002d39b2022-05-31 08:59:27 -0700644 .methods(boost::beast::http::verb::get)(
645 [&app](const crow::Request& req,
646 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanous22d268c2022-05-19 09:39:07 -0700647 const std::string& systemName, const std::string& driveId) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000648 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700649 {
650 return;
651 }
Ed Tanous22d268c2022-05-19 09:39:07 -0700652 if (systemName != "system")
653 {
654 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
655 systemName);
656 return;
657 }
658
George Liue99073f2022-12-09 11:06:16 +0800659 constexpr std::array<std::string_view, 1> interfaces = {
660 "xyz.openbmc_project.Inventory.Item.Drive"};
661 dbus::utility::getSubTree(
662 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -0700663 [asyncResp,
George Liue99073f2022-12-09 11:06:16 +0800664 driveId](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -0700665 const dbus::utility::MapperGetSubTreeResponse& subtree) {
666 if (ec)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700667 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700668 BMCWEB_LOG_ERROR << "Drive mapper call error";
669 messages::internalError(asyncResp->res);
Ed Tanous45ca1b82022-03-25 13:07:27 -0700670 return;
671 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700672
Ed Tanous002d39b2022-05-31 08:59:27 -0700673 auto drive = std::find_if(
674 subtree.begin(), subtree.end(),
675 [&driveId](
Nan Zhou8cb65f82022-06-15 05:12:24 +0000676 const std::pair<std::string,
677 dbus::utility::MapperServiceMap>& object) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700678 return sdbusplus::message::object_path(object.first)
679 .filename() == driveId;
680 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700681
Ed Tanous002d39b2022-05-31 08:59:27 -0700682 if (drive == subtree.end())
683 {
684 messages::resourceNotFound(asyncResp->res, "Drive", driveId);
685 return;
686 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700687
Ed Tanous002d39b2022-05-31 08:59:27 -0700688 const std::string& path = drive->first;
Nan Zhou8cb65f82022-06-15 05:12:24 +0000689 const dbus::utility::MapperServiceMap& connectionNames =
690 drive->second;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700691
Ed Tanous002d39b2022-05-31 08:59:27 -0700692 asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700693 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
694 "/redfish/v1/Systems/system/Storage/1/Drives/{}", driveId);
Ed Tanous002d39b2022-05-31 08:59:27 -0700695 asyncResp->res.jsonValue["Name"] = driveId;
696 asyncResp->res.jsonValue["Id"] = driveId;
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700697
Ed Tanous002d39b2022-05-31 08:59:27 -0700698 if (connectionNames.size() != 1)
699 {
700 BMCWEB_LOG_ERROR << "Connection size " << connectionNames.size()
701 << ", not equal to 1";
702 messages::internalError(asyncResp->res);
703 return;
704 }
James Feiste284a7c2019-11-20 16:20:23 -0800705
Ed Tanous002d39b2022-05-31 08:59:27 -0700706 getMainChassisId(
Ed Tanousef4c65b2023-04-24 15:28:50 -0700707 asyncResp,
708 [](const std::string& chassisId,
709 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
710 aRsp->res.jsonValue["Links"]["Chassis"]["@odata.id"] =
711 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
Ed Tanous002d39b2022-05-31 08:59:27 -0700712 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700713
Ed Tanous002d39b2022-05-31 08:59:27 -0700714 // default it to Enabled
715 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700716
Willy Tu13451e32023-05-24 16:08:18 -0700717 if constexpr (bmcwebEnableHealthPopulate)
718 {
719 auto health = std::make_shared<HealthPopulate>(asyncResp);
720 health->inventory.emplace_back(path);
721 health->populate();
722 }
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700723
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700724 addAllDriveInfo(asyncResp, connectionNames[0].first, path,
725 connectionNames[0].second);
George Liue99073f2022-12-09 11:06:16 +0800726 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700727 });
728}
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700729
730/**
731 * Chassis drives, this URL will show all the DriveCollection
732 * information
733 */
Nan Zhoub53dcd92022-06-21 17:47:50 +0000734inline void chassisDriveCollectionGet(
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700735 crow::App& app, const crow::Request& req,
736 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
737 const std::string& chassisId)
738{
Carson Labrado3ba00072022-06-06 19:40:56 +0000739 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700740 {
741 return;
742 }
743
744 // mapper call lambda
George Liue99073f2022-12-09 11:06:16 +0800745 constexpr std::array<std::string_view, 2> interfaces = {
746 "xyz.openbmc_project.Inventory.Item.Board",
747 "xyz.openbmc_project.Inventory.Item.Chassis"};
748 dbus::utility::getSubTree(
749 "/xyz/openbmc_project/inventory", 0, interfaces,
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700750 [asyncResp,
George Liue99073f2022-12-09 11:06:16 +0800751 chassisId](const boost::system::error_code& ec,
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700752 const dbus::utility::MapperGetSubTreeResponse& subtree) {
753 if (ec)
754 {
755 if (ec == boost::system::errc::host_unreachable)
756 {
757 messages::resourceNotFound(asyncResp->res, "Chassis",
758 chassisId);
759 return;
760 }
761 messages::internalError(asyncResp->res);
762 return;
763 }
764
765 // Iterate over all retrieved ObjectPaths.
Nan Zhou8cb65f82022-06-15 05:12:24 +0000766 for (const auto& [path, connectionNames] : subtree)
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700767 {
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700768 sdbusplus::message::object_path objPath(path);
769 if (objPath.filename() != chassisId)
770 {
771 continue;
772 }
773
774 if (connectionNames.empty())
775 {
776 BMCWEB_LOG_ERROR << "Got 0 Connection names";
777 continue;
778 }
779
780 asyncResp->res.jsonValue["@odata.type"] =
781 "#DriveCollection.DriveCollection";
782 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700783 boost::urls::format("/redfish/v1/Chassis/{}/Drives", chassisId);
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700784 asyncResp->res.jsonValue["Name"] = "Drive Collection";
785
786 // Association lambda
George Liu6c3e9452023-03-03 13:55:29 +0800787 dbus::utility::getAssociationEndPoints(
788 path + "/drive",
789 [asyncResp,
790 chassisId](const boost::system::error_code& ec3,
791 const dbus::utility::MapperEndPoints& resp) {
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700792 if (ec3)
793 {
794 BMCWEB_LOG_ERROR << "Error in chassis Drive association ";
795 }
796 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
797 // important if array is empty
798 members = nlohmann::json::array();
799
800 std::vector<std::string> leafNames;
801 for (const auto& drive : resp)
802 {
Ed Tanous8a592812022-06-04 09:06:59 -0700803 sdbusplus::message::object_path drivePath(drive);
804 leafNames.push_back(drivePath.filename());
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700805 }
806
807 std::sort(leafNames.begin(), leafNames.end(),
808 AlphanumLess<std::string>());
809
810 for (const auto& leafName : leafNames)
811 {
812 nlohmann::json::object_t member;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700813 member["@odata.id"] =
814 boost::urls::format("/redfish/v1/Chassis/{}/Drives/{}",
815 chassisId, leafName);
Patrick Williamsb2ba3072023-05-12 10:27:39 -0500816 members.emplace_back(std::move(member));
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700817 // navigation links will be registered in next patch set
818 }
819 asyncResp->res.jsonValue["Members@odata.count"] = resp.size();
820 }); // end association lambda
821
Patrick Williams89492a12023-05-10 07:51:34 -0500822 } // end Iterate over all retrieved ObjectPaths
George Liue99073f2022-12-09 11:06:16 +0800823 });
John Edward Broadbent92903bd2022-04-26 13:40:59 -0700824}
825
826inline void requestRoutesChassisDrive(App& app)
827{
828 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/")
829 .privileges(redfish::privileges::getDriveCollection)
830 .methods(boost::beast::http::verb::get)(
831 std::bind_front(chassisDriveCollectionGet, std::ref(app)));
832}
833
Nan Zhoub53dcd92022-06-21 17:47:50 +0000834inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
835 const std::string& chassisId,
836 const std::string& driveName,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800837 const boost::system::error_code& ec,
Nan Zhoub53dcd92022-06-21 17:47:50 +0000838 const dbus::utility::MapperGetSubTreeResponse& subtree)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700839{
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700840 if (ec)
841 {
842 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
843 messages::internalError(asyncResp->res);
844 return;
845 }
846
847 // Iterate over all retrieved ObjectPaths.
Nan Zhou8cb65f82022-06-15 05:12:24 +0000848 for (const auto& [path, connectionNames] : subtree)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700849 {
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700850 sdbusplus::message::object_path objPath(path);
851 if (objPath.filename() != driveName)
852 {
853 continue;
854 }
855
856 if (connectionNames.empty())
857 {
858 BMCWEB_LOG_ERROR << "Got 0 Connection names";
859 continue;
860 }
861
Ed Tanousef4c65b2023-04-24 15:28:50 -0700862 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
863 "/redfish/v1/Chassis/{}/Drives/{}", chassisId, driveName);
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700864
865 asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive";
John Edward Broadbenta0cb40c2022-06-29 17:27:38 -0700866 asyncResp->res.jsonValue["Name"] = driveName;
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700867 asyncResp->res.jsonValue["Id"] = driveName;
868 // default it to Enabled
869 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
870
871 nlohmann::json::object_t linkChassisNav;
872 linkChassisNav["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700873 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700874 asyncResp->res.jsonValue["Links"]["Chassis"] = linkChassisNav;
875
876 addAllDriveInfo(asyncResp, connectionNames[0].first, path,
877 connectionNames[0].second);
878 }
879}
880
Nan Zhoub53dcd92022-06-21 17:47:50 +0000881inline void
882 matchAndFillDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
883 const std::string& chassisId,
884 const std::string& driveName,
885 const std::vector<std::string>& resp)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700886{
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700887 for (const std::string& drivePath : resp)
888 {
889 sdbusplus::message::object_path path(drivePath);
890 std::string leaf = path.filename();
891 if (leaf != driveName)
892 {
893 continue;
894 }
895 // mapper call drive
George Liue99073f2022-12-09 11:06:16 +0800896 constexpr std::array<std::string_view, 1> driveInterface = {
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700897 "xyz.openbmc_project.Inventory.Item.Drive"};
George Liue99073f2022-12-09 11:06:16 +0800898 dbus::utility::getSubTree(
899 "/xyz/openbmc_project/inventory", 0, driveInterface,
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700900 [asyncResp, chassisId, driveName](
George Liue99073f2022-12-09 11:06:16 +0800901 const boost::system::error_code& ec,
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700902 const dbus::utility::MapperGetSubTreeResponse& subtree) {
903 buildDrive(asyncResp, chassisId, driveName, ec, subtree);
George Liue99073f2022-12-09 11:06:16 +0800904 });
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700905 }
906}
907
Nan Zhoub53dcd92022-06-21 17:47:50 +0000908inline void
909 handleChassisDriveGet(crow::App& app, const crow::Request& req,
910 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
911 const std::string& chassisId,
912 const std::string& driveName)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700913{
Michal Orzel03810a12022-06-15 14:04:28 +0200914 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700915 {
916 return;
917 }
George Liue99073f2022-12-09 11:06:16 +0800918 constexpr std::array<std::string_view, 2> interfaces = {
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700919 "xyz.openbmc_project.Inventory.Item.Board",
920 "xyz.openbmc_project.Inventory.Item.Chassis"};
921
922 // mapper call chassis
George Liue99073f2022-12-09 11:06:16 +0800923 dbus::utility::getSubTree(
924 "/xyz/openbmc_project/inventory", 0, interfaces,
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700925 [asyncResp, chassisId,
George Liue99073f2022-12-09 11:06:16 +0800926 driveName](const boost::system::error_code& ec,
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700927 const dbus::utility::MapperGetSubTreeResponse& subtree) {
928 if (ec)
929 {
930 messages::internalError(asyncResp->res);
931 return;
932 }
933
934 // Iterate over all retrieved ObjectPaths.
Nan Zhou8cb65f82022-06-15 05:12:24 +0000935 for (const auto& [path, connectionNames] : subtree)
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700936 {
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700937 sdbusplus::message::object_path objPath(path);
938 if (objPath.filename() != chassisId)
939 {
940 continue;
941 }
942
943 if (connectionNames.empty())
944 {
945 BMCWEB_LOG_ERROR << "Got 0 Connection names";
946 continue;
947 }
948
George Liu6c3e9452023-03-03 13:55:29 +0800949 dbus::utility::getAssociationEndPoints(
950 path + "/drive",
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700951 [asyncResp, chassisId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800952 driveName](const boost::system::error_code& ec3,
George Liu6c3e9452023-03-03 13:55:29 +0800953 const dbus::utility::MapperEndPoints& resp) {
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700954 if (ec3)
955 {
956 return; // no drives = no failures
957 }
958 matchAndFillDrive(asyncResp, chassisId, driveName, resp);
959 });
960 break;
961 }
George Liue99073f2022-12-09 11:06:16 +0800962 });
John Edward Broadbente56ed6b2022-04-26 13:40:59 -0700963}
964
965/**
966 * This URL will show the drive interface for the specific drive in the chassis
967 */
968inline void requestRoutesChassisDriveName(App& app)
969{
970 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/<str>/")
971 .privileges(redfish::privileges::getChassis)
972 .methods(boost::beast::http::verb::get)(
973 std::bind_front(handleChassisDriveGet, std::ref(app)));
974}
975
Nikhil Potadea25aecc2019-08-23 16:35:26 -0700976} // namespace redfish