Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 18 | #include "health.hpp" |
James Feist | e284a7c | 2019-11-20 16:20:23 -0800 | [diff] [blame] | 19 | #include "openbmc_dbus_rest.hpp" |
James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 20 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 21 | #include <app.hpp> |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 22 | #include <dbus_utility.hpp> |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 23 | #include <query.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 24 | #include <registries/privilege_registry.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 25 | #include <sdbusplus/asio/property.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 26 | #include <sdbusplus/unpack_properties.hpp> |
| 27 | #include <utils/dbus_utils.hpp> |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 28 | |
| 29 | namespace redfish |
| 30 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 31 | inline void requestRoutesStorageCollection(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 32 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 33 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 34 | .privileges(redfish::privileges::getStorageCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 35 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 36 | [&app](const crow::Request& req, |
| 37 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 38 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 39 | { |
| 40 | return; |
| 41 | } |
| 42 | asyncResp->res.jsonValue["@odata.type"] = |
| 43 | "#StorageCollection.StorageCollection"; |
| 44 | asyncResp->res.jsonValue["@odata.id"] = |
| 45 | "/redfish/v1/Systems/system/Storage"; |
| 46 | asyncResp->res.jsonValue["Name"] = "Storage Collection"; |
| 47 | nlohmann::json::array_t members; |
| 48 | nlohmann::json::object_t member; |
| 49 | member["@odata.id"] = "/redfish/v1/Systems/system/Storage/1"; |
| 50 | members.emplace_back(member); |
| 51 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 52 | asyncResp->res.jsonValue["Members@odata.count"] = 1; |
| 53 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 54 | } |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 55 | |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 56 | inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 57 | const std::shared_ptr<HealthPopulate>& health) |
| 58 | { |
| 59 | crow::connections::systemBus->async_method_call( |
| 60 | [asyncResp, health]( |
| 61 | const boost::system::error_code ec, |
| 62 | const dbus::utility::MapperGetSubTreePathsResponse& driveList) { |
| 63 | if (ec) |
| 64 | { |
| 65 | BMCWEB_LOG_ERROR << "Drive mapper call error"; |
| 66 | messages::internalError(asyncResp->res); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | nlohmann::json& driveArray = asyncResp->res.jsonValue["Drives"]; |
| 71 | driveArray = nlohmann::json::array(); |
| 72 | auto& count = asyncResp->res.jsonValue["Drives@odata.count"]; |
| 73 | count = 0; |
| 74 | |
| 75 | health->inventory.insert(health->inventory.end(), driveList.begin(), |
| 76 | driveList.end()); |
| 77 | |
| 78 | for (const std::string& drive : driveList) |
| 79 | { |
| 80 | sdbusplus::message::object_path object(drive); |
| 81 | if (object.filename().empty()) |
| 82 | { |
| 83 | BMCWEB_LOG_ERROR << "Failed to find filename in " << drive; |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | nlohmann::json::object_t driveJson; |
| 88 | driveJson["@odata.id"] = |
| 89 | "/redfish/v1/Systems/system/Storage/1/Drives/" + |
| 90 | object.filename(); |
| 91 | driveArray.push_back(std::move(driveJson)); |
| 92 | } |
| 93 | |
| 94 | count = driveArray.size(); |
| 95 | }, |
| 96 | "xyz.openbmc_project.ObjectMapper", |
| 97 | "/xyz/openbmc_project/object_mapper", |
| 98 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
| 99 | "/xyz/openbmc_project/inventory", int32_t(0), |
| 100 | std::array<const char*, 1>{"xyz.openbmc_project.Inventory.Item.Drive"}); |
| 101 | } |
| 102 | |
| 103 | inline void |
| 104 | getStorageControllers(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 105 | const std::shared_ptr<HealthPopulate>& health) |
| 106 | { |
| 107 | crow::connections::systemBus->async_method_call( |
| 108 | [asyncResp, |
| 109 | health](const boost::system::error_code ec, |
| 110 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 111 | if (ec || subtree.empty()) |
| 112 | { |
| 113 | // doesn't have to be there |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | nlohmann::json& root = asyncResp->res.jsonValue["StorageControllers"]; |
| 118 | root = nlohmann::json::array(); |
| 119 | for (const auto& [path, interfaceDict] : subtree) |
| 120 | { |
| 121 | sdbusplus::message::object_path object(path); |
| 122 | std::string id = object.filename(); |
| 123 | if (id.empty()) |
| 124 | { |
| 125 | BMCWEB_LOG_ERROR << "Failed to find filename in " << path; |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | if (interfaceDict.size() != 1) |
| 130 | { |
| 131 | BMCWEB_LOG_ERROR << "Connection size " << interfaceDict.size() |
| 132 | << ", greater than 1"; |
| 133 | messages::internalError(asyncResp->res); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | const std::string& connectionName = interfaceDict.front().first; |
| 138 | |
| 139 | size_t index = root.size(); |
| 140 | nlohmann::json& storageController = |
| 141 | root.emplace_back(nlohmann::json::object()); |
| 142 | |
| 143 | storageController["@odata.type"] = |
| 144 | "#Storage.v1_7_0.StorageController"; |
| 145 | storageController["@odata.id"] = |
| 146 | "/redfish/v1/Systems/system/Storage/1#/StorageControllers/" + |
| 147 | std::to_string(index); |
| 148 | storageController["Name"] = id; |
| 149 | storageController["MemberId"] = id; |
| 150 | storageController["Status"]["State"] = "Enabled"; |
| 151 | |
| 152 | sdbusplus::asio::getProperty<bool>( |
| 153 | *crow::connections::systemBus, connectionName, path, |
| 154 | "xyz.openbmc_project.Inventory.Item", "Present", |
| 155 | [asyncResp, index](const boost::system::error_code ec2, |
| 156 | bool enabled) { |
| 157 | // this interface isn't necessary, only check it |
| 158 | // if we get a good return |
| 159 | if (ec2) |
| 160 | { |
| 161 | return; |
| 162 | } |
| 163 | if (!enabled) |
| 164 | { |
| 165 | asyncResp->res.jsonValue["StorageControllers"][index] |
| 166 | ["Status"]["State"] = "Disabled"; |
| 167 | } |
| 168 | }); |
| 169 | |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 170 | sdbusplus::asio::getAllProperties( |
| 171 | *crow::connections::systemBus, connectionName, path, |
| 172 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 173 | [asyncResp, index]( |
| 174 | const boost::system::error_code ec2, |
| 175 | const std::vector< |
| 176 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 177 | propertiesList) { |
| 178 | if (ec2) |
| 179 | { |
| 180 | // this interface isn't necessary |
| 181 | return; |
| 182 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 183 | |
| 184 | const std::string* partNumber = nullptr; |
| 185 | const std::string* serialNumber = nullptr; |
| 186 | const std::string* manufacturer = nullptr; |
| 187 | const std::string* model = nullptr; |
| 188 | |
| 189 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 190 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 191 | "PartNumber", partNumber, "SerialNumber", serialNumber, |
| 192 | "Manufacturer", manufacturer, "Model", model); |
| 193 | |
| 194 | if (!success) |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 195 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 196 | messages::internalError(asyncResp->res); |
| 197 | return; |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 198 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 199 | |
| 200 | nlohmann::json& controller = |
| 201 | asyncResp->res.jsonValue["StorageControllers"][index]; |
| 202 | |
| 203 | if (partNumber != nullptr) |
| 204 | { |
| 205 | controller["PartNumber"] = *partNumber; |
| 206 | } |
| 207 | |
| 208 | if (serialNumber != nullptr) |
| 209 | { |
| 210 | controller["SerialNumber"] = *serialNumber; |
| 211 | } |
| 212 | |
| 213 | if (manufacturer != nullptr) |
| 214 | { |
| 215 | controller["Manufacturer"] = *manufacturer; |
| 216 | } |
| 217 | |
| 218 | if (model != nullptr) |
| 219 | { |
| 220 | controller["Model"] = *model; |
| 221 | } |
| 222 | }); |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | // this is done after we know the json array will no longer |
| 226 | // be resized, as json::array uses vector underneath and we |
| 227 | // need references to its members that won't change |
| 228 | size_t count = 0; |
| 229 | // Pointer based on |asyncResp->res.jsonValue| |
| 230 | nlohmann::json::json_pointer rootPtr = |
| 231 | "/StorageControllers"_json_pointer; |
| 232 | for (const auto& [path, interfaceDict] : subtree) |
| 233 | { |
| 234 | auto subHealth = std::make_shared<HealthPopulate>( |
| 235 | asyncResp, rootPtr / count / "Status"); |
| 236 | subHealth->inventory.emplace_back(path); |
| 237 | health->inventory.emplace_back(path); |
| 238 | health->children.emplace_back(subHealth); |
| 239 | count++; |
| 240 | } |
| 241 | }, |
| 242 | "xyz.openbmc_project.ObjectMapper", |
| 243 | "/xyz/openbmc_project/object_mapper", |
| 244 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 245 | "/xyz/openbmc_project/inventory", int32_t(0), |
| 246 | std::array<const char*, 1>{ |
| 247 | "xyz.openbmc_project.Inventory.Item.StorageController"}); |
| 248 | } |
| 249 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 250 | inline void requestRoutesStorage(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 251 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 252 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 253 | .privileges(redfish::privileges::getStorage) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 254 | .methods(boost::beast::http::verb::get)( |
| 255 | [&app](const crow::Request& req, |
| 256 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 257 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 258 | { |
| 259 | return; |
| 260 | } |
| 261 | asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_7_1.Storage"; |
| 262 | asyncResp->res.jsonValue["@odata.id"] = |
| 263 | "/redfish/v1/Systems/system/Storage/1"; |
| 264 | asyncResp->res.jsonValue["Name"] = "Storage"; |
| 265 | asyncResp->res.jsonValue["Id"] = "1"; |
| 266 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 267 | |
| 268 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 269 | health->populate(); |
| 270 | |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 271 | getDrives(asyncResp, health); |
| 272 | getStorageControllers(asyncResp, health); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 273 | }); |
| 274 | } |
| 275 | |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 276 | inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 277 | const std::string& connectionName, |
| 278 | const std::string& path) |
| 279 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 280 | sdbusplus::asio::getAllProperties( |
| 281 | *crow::connections::systemBus, connectionName, path, |
| 282 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 283 | [asyncResp](const boost::system::error_code ec, |
| 284 | const std::vector< |
| 285 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 286 | propertiesList) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 287 | if (ec) |
| 288 | { |
| 289 | // this interface isn't necessary |
| 290 | return; |
| 291 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 292 | |
| 293 | const std::string* partNumber = nullptr; |
| 294 | const std::string* serialNumber = nullptr; |
| 295 | const std::string* manufacturer = nullptr; |
| 296 | const std::string* model = nullptr; |
| 297 | |
| 298 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 299 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 300 | partNumber, "SerialNumber", serialNumber, "Manufacturer", |
| 301 | manufacturer, "Model", model); |
| 302 | |
| 303 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 304 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 305 | messages::internalError(asyncResp->res); |
| 306 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 307 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 308 | |
| 309 | if (partNumber != nullptr) |
| 310 | { |
| 311 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 312 | } |
| 313 | |
| 314 | if (serialNumber != nullptr) |
| 315 | { |
| 316 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 317 | } |
| 318 | |
| 319 | if (manufacturer != nullptr) |
| 320 | { |
| 321 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 322 | } |
| 323 | |
| 324 | if (model != nullptr) |
| 325 | { |
| 326 | asyncResp->res.jsonValue["Model"] = *model; |
| 327 | } |
| 328 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 332 | const std::string& connectionName, |
| 333 | const std::string& path) |
| 334 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 335 | sdbusplus::asio::getProperty<bool>( |
| 336 | *crow::connections::systemBus, connectionName, path, |
| 337 | "xyz.openbmc_project.Inventory.Item", "Present", |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 338 | [asyncResp, path](const boost::system::error_code ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 339 | const bool enabled) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 340 | // this interface isn't necessary, only check it if |
| 341 | // we get a good return |
| 342 | if (ec) |
| 343 | { |
| 344 | return; |
| 345 | } |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 346 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 347 | if (!enabled) |
| 348 | { |
| 349 | asyncResp->res.jsonValue["Status"]["State"] = "Disabled"; |
| 350 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 351 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 355 | const std::string& connectionName, |
| 356 | const std::string& path) |
| 357 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 358 | sdbusplus::asio::getProperty<bool>( |
| 359 | *crow::connections::systemBus, connectionName, path, |
| 360 | "xyz.openbmc_project.State.Drive", "Rebuilding", |
| 361 | [asyncResp](const boost::system::error_code ec, const bool updating) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 362 | // this interface isn't necessary, only check it |
| 363 | // if we get a good return |
| 364 | if (ec) |
| 365 | { |
| 366 | return; |
| 367 | } |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 368 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 369 | // updating and disabled in the backend shouldn't be |
| 370 | // able to be set at the same time, so we don't need |
| 371 | // to check for the race condition of these two |
| 372 | // calls |
| 373 | if (updating) |
| 374 | { |
| 375 | asyncResp->res.jsonValue["Status"]["State"] = "Updating"; |
| 376 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 377 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 380 | inline std::optional<std::string> convertDriveType(const std::string& type) |
| 381 | { |
| 382 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.HDD") |
| 383 | { |
| 384 | return "HDD"; |
| 385 | } |
| 386 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.SSD") |
| 387 | { |
| 388 | return "SSD"; |
| 389 | } |
| 390 | |
| 391 | return std::nullopt; |
| 392 | } |
| 393 | |
| 394 | inline std::optional<std::string> convertDriveProtocol(const std::string& proto) |
| 395 | { |
| 396 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SAS") |
| 397 | { |
| 398 | return "SAS"; |
| 399 | } |
| 400 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SATA") |
| 401 | { |
| 402 | return "SATA"; |
| 403 | } |
| 404 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.NVMe") |
| 405 | { |
| 406 | return "NVMe"; |
| 407 | } |
| 408 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.FC") |
| 409 | { |
| 410 | return "FC"; |
| 411 | } |
| 412 | |
| 413 | return std::nullopt; |
| 414 | } |
| 415 | |
| 416 | inline void |
| 417 | getDriveItemProperties(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 418 | const std::string& connectionName, |
| 419 | const std::string& path) |
| 420 | { |
| 421 | sdbusplus::asio::getAllProperties( |
| 422 | *crow::connections::systemBus, connectionName, path, |
| 423 | "xyz.openbmc_project.Inventory.Item.Drive", |
| 424 | [asyncResp](const boost::system::error_code ec, |
| 425 | const std::vector< |
| 426 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 427 | propertiesList) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 428 | if (ec) |
| 429 | { |
| 430 | // this interface isn't required |
| 431 | return; |
| 432 | } |
| 433 | for (const std::pair<std::string, dbus::utility::DbusVariantType>& |
| 434 | property : propertiesList) |
| 435 | { |
| 436 | const std::string& propertyName = property.first; |
| 437 | if (propertyName == "Type") |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 438 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 439 | const std::string* value = |
| 440 | std::get_if<std::string>(&property.second); |
| 441 | if (value == nullptr) |
| 442 | { |
| 443 | // illegal property |
| 444 | BMCWEB_LOG_ERROR << "Illegal property: Type"; |
| 445 | messages::internalError(asyncResp->res); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | std::optional<std::string> mediaType = convertDriveType(*value); |
| 450 | if (!mediaType) |
| 451 | { |
| 452 | BMCWEB_LOG_ERROR << "Unsupported DriveType Interface: " |
| 453 | << *value; |
| 454 | messages::internalError(asyncResp->res); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | asyncResp->res.jsonValue["MediaType"] = *mediaType; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 459 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 460 | else if (propertyName == "Capacity") |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 461 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 462 | const uint64_t* capacity = |
| 463 | std::get_if<uint64_t>(&property.second); |
| 464 | if (capacity == nullptr) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 465 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 466 | BMCWEB_LOG_ERROR << "Illegal property: Capacity"; |
| 467 | messages::internalError(asyncResp->res); |
| 468 | return; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 469 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 470 | if (*capacity == 0) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 471 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 472 | // drive capacity not known |
| 473 | continue; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 474 | } |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 475 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 476 | asyncResp->res.jsonValue["CapacityBytes"] = *capacity; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 477 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 478 | else if (propertyName == "Protocol") |
| 479 | { |
| 480 | const std::string* value = |
| 481 | std::get_if<std::string>(&property.second); |
| 482 | if (value == nullptr) |
| 483 | { |
| 484 | BMCWEB_LOG_ERROR << "Illegal property: Protocol"; |
| 485 | messages::internalError(asyncResp->res); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | std::optional<std::string> proto = convertDriveProtocol(*value); |
| 490 | if (!proto) |
| 491 | { |
| 492 | BMCWEB_LOG_ERROR << "Unsupported DrivePrototype Interface: " |
| 493 | << *value; |
| 494 | messages::internalError(asyncResp->res); |
| 495 | return; |
| 496 | } |
| 497 | asyncResp->res.jsonValue["Protocol"] = *proto; |
| 498 | } |
John Edward Broadbent | 3fe4d5c | 2022-05-06 14:42:35 -0700 | [diff] [blame] | 499 | else if (propertyName == "PredictedMediaLifeLeftPercent") |
| 500 | { |
| 501 | const uint8_t* lifeLeft = |
| 502 | std::get_if<uint8_t>(&property.second); |
| 503 | if (lifeLeft == nullptr) |
| 504 | { |
| 505 | BMCWEB_LOG_ERROR |
| 506 | << "Illegal property: PredictedMediaLifeLeftPercent"; |
| 507 | messages::internalError(asyncResp->res); |
| 508 | return; |
| 509 | } |
| 510 | // 255 means reading the value is not supported |
| 511 | if (*lifeLeft != 255) |
| 512 | { |
| 513 | asyncResp->res.jsonValue["PredictedMediaLifeLeftPercent"] = |
| 514 | *lifeLeft; |
| 515 | } |
| 516 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 517 | } |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 518 | }); |
| 519 | } |
| 520 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 521 | static void addAllDriveInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 522 | const std::string& connectionName, |
| 523 | const std::string& path, |
| 524 | const std::vector<std::string>& interfaces) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 525 | { |
| 526 | for (const std::string& interface : interfaces) |
| 527 | { |
| 528 | if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 529 | { |
| 530 | getDriveAsset(asyncResp, connectionName, path); |
| 531 | } |
| 532 | else if (interface == "xyz.openbmc_project.Inventory.Item") |
| 533 | { |
| 534 | getDrivePresent(asyncResp, connectionName, path); |
| 535 | } |
| 536 | else if (interface == "xyz.openbmc_project.State.Drive") |
| 537 | { |
| 538 | getDriveState(asyncResp, connectionName, path); |
| 539 | } |
| 540 | else if (interface == "xyz.openbmc_project.Inventory.Item.Drive") |
| 541 | { |
| 542 | getDriveItemProperties(asyncResp, connectionName, path); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 547 | inline void requestRoutesDrive(App& app) |
| 548 | { |
| 549 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Storage/1/Drives/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 550 | .privileges(redfish::privileges::getDrive) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 551 | .methods(boost::beast::http::verb::get)( |
| 552 | [&app](const crow::Request& req, |
| 553 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 554 | const std::string& driveId) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 555 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 556 | { |
| 557 | return; |
| 558 | } |
| 559 | crow::connections::systemBus->async_method_call( |
| 560 | [asyncResp, |
| 561 | driveId](const boost::system::error_code ec, |
| 562 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 563 | if (ec) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 564 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 565 | BMCWEB_LOG_ERROR << "Drive mapper call error"; |
| 566 | messages::internalError(asyncResp->res); |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 567 | return; |
| 568 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 569 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 570 | auto drive = std::find_if( |
| 571 | subtree.begin(), subtree.end(), |
| 572 | [&driveId]( |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 573 | const std::pair<std::string, |
| 574 | dbus::utility::MapperServiceMap>& object) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 575 | return sdbusplus::message::object_path(object.first) |
| 576 | .filename() == driveId; |
| 577 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 578 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 579 | if (drive == subtree.end()) |
| 580 | { |
| 581 | messages::resourceNotFound(asyncResp->res, "Drive", driveId); |
| 582 | return; |
| 583 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 584 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 585 | const std::string& path = drive->first; |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 586 | const dbus::utility::MapperServiceMap& connectionNames = |
| 587 | drive->second; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 588 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 589 | asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; |
| 590 | asyncResp->res.jsonValue["@odata.id"] = |
| 591 | "/redfish/v1/Systems/system/Storage/1/Drives/" + driveId; |
| 592 | asyncResp->res.jsonValue["Name"] = driveId; |
| 593 | asyncResp->res.jsonValue["Id"] = driveId; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 594 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 595 | if (connectionNames.size() != 1) |
| 596 | { |
| 597 | BMCWEB_LOG_ERROR << "Connection size " << connectionNames.size() |
| 598 | << ", not equal to 1"; |
| 599 | messages::internalError(asyncResp->res); |
| 600 | return; |
| 601 | } |
James Feist | e284a7c | 2019-11-20 16:20:23 -0800 | [diff] [blame] | 602 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 603 | getMainChassisId( |
| 604 | asyncResp, [](const std::string& chassisId, |
| 605 | const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { |
| 606 | aRsp->res.jsonValue["Links"]["Chassis"]["@odata.id"] = |
| 607 | "/redfish/v1/Chassis/" + chassisId; |
| 608 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 609 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 610 | // default it to Enabled |
| 611 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 612 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 613 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 614 | health->inventory.emplace_back(path); |
| 615 | health->populate(); |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 616 | |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 617 | addAllDriveInfo(asyncResp, connectionNames[0].first, path, |
| 618 | connectionNames[0].second); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 619 | }, |
| 620 | "xyz.openbmc_project.ObjectMapper", |
| 621 | "/xyz/openbmc_project/object_mapper", |
| 622 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 623 | "/xyz/openbmc_project/inventory", int32_t(0), |
| 624 | std::array<const char*, 1>{ |
| 625 | "xyz.openbmc_project.Inventory.Item.Drive"}); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 626 | }); |
| 627 | } |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 628 | |
| 629 | /** |
| 630 | * Chassis drives, this URL will show all the DriveCollection |
| 631 | * information |
| 632 | */ |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 633 | inline void chassisDriveCollectionGet( |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 634 | crow::App& app, const crow::Request& req, |
| 635 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 636 | const std::string& chassisId) |
| 637 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 638 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 639 | { |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | // mapper call lambda |
| 644 | crow::connections::systemBus->async_method_call( |
| 645 | [asyncResp, |
| 646 | chassisId](const boost::system::error_code ec, |
| 647 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 648 | if (ec) |
| 649 | { |
| 650 | if (ec == boost::system::errc::host_unreachable) |
| 651 | { |
| 652 | messages::resourceNotFound(asyncResp->res, "Chassis", |
| 653 | chassisId); |
| 654 | return; |
| 655 | } |
| 656 | messages::internalError(asyncResp->res); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | // Iterate over all retrieved ObjectPaths. |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 661 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 662 | { |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 663 | sdbusplus::message::object_path objPath(path); |
| 664 | if (objPath.filename() != chassisId) |
| 665 | { |
| 666 | continue; |
| 667 | } |
| 668 | |
| 669 | if (connectionNames.empty()) |
| 670 | { |
| 671 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 672 | continue; |
| 673 | } |
| 674 | |
| 675 | asyncResp->res.jsonValue["@odata.type"] = |
| 676 | "#DriveCollection.DriveCollection"; |
| 677 | asyncResp->res.jsonValue["@odata.id"] = |
John Edward Broadbent | 14bd7d9 | 2022-06-14 17:17:43 -0700 | [diff] [blame] | 678 | crow::utility::urlFromPieces("redfish", "v1", "Chassis", |
| 679 | chassisId, "Drives"); |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 680 | asyncResp->res.jsonValue["Name"] = "Drive Collection"; |
| 681 | |
| 682 | // Association lambda |
| 683 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 684 | *crow::connections::systemBus, |
| 685 | "xyz.openbmc_project.ObjectMapper", path + "/drive", |
| 686 | "xyz.openbmc_project.Association", "endpoints", |
| 687 | [asyncResp, chassisId](const boost::system::error_code ec3, |
| 688 | const std::vector<std::string>& resp) { |
| 689 | if (ec3) |
| 690 | { |
| 691 | BMCWEB_LOG_ERROR << "Error in chassis Drive association "; |
| 692 | } |
| 693 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
| 694 | // important if array is empty |
| 695 | members = nlohmann::json::array(); |
| 696 | |
| 697 | std::vector<std::string> leafNames; |
| 698 | for (const auto& drive : resp) |
| 699 | { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 700 | sdbusplus::message::object_path drivePath(drive); |
| 701 | leafNames.push_back(drivePath.filename()); |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | std::sort(leafNames.begin(), leafNames.end(), |
| 705 | AlphanumLess<std::string>()); |
| 706 | |
| 707 | for (const auto& leafName : leafNames) |
| 708 | { |
| 709 | nlohmann::json::object_t member; |
| 710 | member["@odata.id"] = crow::utility::urlFromPieces( |
| 711 | "redfish", "v1", "Chassis", chassisId, "Drives", |
| 712 | leafName); |
| 713 | members.push_back(std::move(member)); |
| 714 | // navigation links will be registered in next patch set |
| 715 | } |
| 716 | asyncResp->res.jsonValue["Members@odata.count"] = resp.size(); |
| 717 | }); // end association lambda |
| 718 | |
| 719 | } // end Iterate over all retrieved ObjectPaths |
| 720 | }, |
| 721 | "xyz.openbmc_project.ObjectMapper", |
| 722 | "/xyz/openbmc_project/object_mapper", |
| 723 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 724 | "/xyz/openbmc_project/inventory", 0, |
| 725 | std::array<const char*, 2>{ |
| 726 | "xyz.openbmc_project.Inventory.Item.Board", |
| 727 | "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| 728 | } |
| 729 | |
| 730 | inline void requestRoutesChassisDrive(App& app) |
| 731 | { |
| 732 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/") |
| 733 | .privileges(redfish::privileges::getDriveCollection) |
| 734 | .methods(boost::beast::http::verb::get)( |
| 735 | std::bind_front(chassisDriveCollectionGet, std::ref(app))); |
| 736 | } |
| 737 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 738 | inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 739 | const std::string& chassisId, |
| 740 | const std::string& driveName, |
| 741 | const boost::system::error_code ec, |
| 742 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 743 | { |
| 744 | |
| 745 | if (ec) |
| 746 | { |
| 747 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 748 | messages::internalError(asyncResp->res); |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | // Iterate over all retrieved ObjectPaths. |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 753 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 754 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 755 | sdbusplus::message::object_path objPath(path); |
| 756 | if (objPath.filename() != driveName) |
| 757 | { |
| 758 | continue; |
| 759 | } |
| 760 | |
| 761 | if (connectionNames.empty()) |
| 762 | { |
| 763 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 764 | continue; |
| 765 | } |
| 766 | |
| 767 | asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( |
John Edward Broadbent | a0cb40c | 2022-06-29 17:27:38 -0700 | [diff] [blame] | 768 | "redfish", "v1", "Chassis", chassisId, "Drives", driveName); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 769 | |
| 770 | asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; |
John Edward Broadbent | a0cb40c | 2022-06-29 17:27:38 -0700 | [diff] [blame] | 771 | asyncResp->res.jsonValue["Name"] = driveName; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 772 | asyncResp->res.jsonValue["Id"] = driveName; |
| 773 | // default it to Enabled |
| 774 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 775 | |
| 776 | nlohmann::json::object_t linkChassisNav; |
| 777 | linkChassisNav["@odata.id"] = |
| 778 | crow::utility::urlFromPieces("redfish", "v1", "Chassis", chassisId); |
| 779 | asyncResp->res.jsonValue["Links"]["Chassis"] = linkChassisNav; |
| 780 | |
| 781 | addAllDriveInfo(asyncResp, connectionNames[0].first, path, |
| 782 | connectionNames[0].second); |
| 783 | } |
| 784 | } |
| 785 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 786 | inline void |
| 787 | matchAndFillDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 788 | const std::string& chassisId, |
| 789 | const std::string& driveName, |
| 790 | const std::vector<std::string>& resp) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 791 | { |
| 792 | |
| 793 | for (const std::string& drivePath : resp) |
| 794 | { |
| 795 | sdbusplus::message::object_path path(drivePath); |
| 796 | std::string leaf = path.filename(); |
| 797 | if (leaf != driveName) |
| 798 | { |
| 799 | continue; |
| 800 | } |
| 801 | // mapper call drive |
| 802 | const std::array<const char*, 1> driveInterface = { |
| 803 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
| 804 | |
| 805 | crow::connections::systemBus->async_method_call( |
| 806 | [asyncResp, chassisId, driveName]( |
| 807 | const boost::system::error_code ec, |
| 808 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 809 | buildDrive(asyncResp, chassisId, driveName, ec, subtree); |
| 810 | }, |
| 811 | "xyz.openbmc_project.ObjectMapper", |
| 812 | "/xyz/openbmc_project/object_mapper", |
| 813 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 814 | "/xyz/openbmc_project/inventory", 0, driveInterface); |
| 815 | } |
| 816 | } |
| 817 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 818 | inline void |
| 819 | handleChassisDriveGet(crow::App& app, const crow::Request& req, |
| 820 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 821 | const std::string& chassisId, |
| 822 | const std::string& driveName) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 823 | { |
Michal Orzel | 03810a1 | 2022-06-15 14:04:28 +0200 | [diff] [blame] | 824 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 825 | { |
| 826 | return; |
| 827 | } |
| 828 | const std::array<const char*, 2> interfaces = { |
| 829 | "xyz.openbmc_project.Inventory.Item.Board", |
| 830 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 831 | |
| 832 | // mapper call chassis |
| 833 | crow::connections::systemBus->async_method_call( |
| 834 | [asyncResp, chassisId, |
| 835 | driveName](const boost::system::error_code ec, |
| 836 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 837 | if (ec) |
| 838 | { |
| 839 | messages::internalError(asyncResp->res); |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | // Iterate over all retrieved ObjectPaths. |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 844 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 845 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 846 | sdbusplus::message::object_path objPath(path); |
| 847 | if (objPath.filename() != chassisId) |
| 848 | { |
| 849 | continue; |
| 850 | } |
| 851 | |
| 852 | if (connectionNames.empty()) |
| 853 | { |
| 854 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 855 | continue; |
| 856 | } |
| 857 | |
| 858 | sdbusplus::asio::getProperty<std::vector<std::string>>( |
| 859 | *crow::connections::systemBus, |
| 860 | "xyz.openbmc_project.ObjectMapper", path + "/drive", |
| 861 | "xyz.openbmc_project.Association", "endpoints", |
| 862 | [asyncResp, chassisId, |
| 863 | driveName](const boost::system::error_code ec3, |
| 864 | const std::vector<std::string>& resp) { |
| 865 | if (ec3) |
| 866 | { |
| 867 | return; // no drives = no failures |
| 868 | } |
| 869 | matchAndFillDrive(asyncResp, chassisId, driveName, resp); |
| 870 | }); |
| 871 | break; |
| 872 | } |
| 873 | }, |
| 874 | "xyz.openbmc_project.ObjectMapper", |
| 875 | "/xyz/openbmc_project/object_mapper", |
| 876 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 877 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * This URL will show the drive interface for the specific drive in the chassis |
| 882 | */ |
| 883 | inline void requestRoutesChassisDriveName(App& app) |
| 884 | { |
| 885 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/<str>/") |
| 886 | .privileges(redfish::privileges::getChassis) |
| 887 | .methods(boost::beast::http::verb::get)( |
| 888 | std::bind_front(handleChassisDriveGet, std::ref(app))); |
| 889 | } |
| 890 | |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 891 | } // namespace redfish |