Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 8 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 9 | #include "dbus_utility.hpp" |
John Edward Broadbent | e5029d8 | 2022-06-08 14:35:21 -0700 | [diff] [blame] | 10 | #include "generated/enums/drive.hpp" |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 11 | #include "generated/enums/protocol.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 12 | #include "generated/enums/resource.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 13 | #include "human_sort.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 14 | #include "query.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 15 | #include "redfish_util.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 16 | #include "registries/privilege_registry.hpp" |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 17 | #include "utils/collection.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "utils/dbus_utils.hpp" |
James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 19 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 20 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 21 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 22 | #include <sdbusplus/asio/property.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 23 | #include <sdbusplus/unpack_properties.hpp> |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 24 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 25 | #include <array> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 26 | #include <ranges> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 27 | #include <string_view> |
| 28 | |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 29 | namespace redfish |
| 30 | { |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 31 | |
| 32 | inline void handleSystemsStorageCollectionGet( |
| 33 | App& app, const crow::Request& req, |
| 34 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 35 | const std::string& systemName) |
| 36 | { |
| 37 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 38 | { |
| 39 | return; |
| 40 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 41 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 42 | { |
| 43 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 44 | systemName); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | asyncResp->res.jsonValue["@odata.type"] = |
| 49 | "#StorageCollection.StorageCollection"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 50 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 51 | "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 52 | asyncResp->res.jsonValue["Name"] = "Storage Collection"; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 53 | |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 54 | constexpr std::array<std::string_view, 1> interface{ |
| 55 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 56 | collection_util::getCollectionMembers( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 57 | asyncResp, |
| 58 | boost::urls::format("/redfish/v1/Systems/{}/Storage", |
| 59 | BMCWEB_REDFISH_SYSTEM_URI_NAME), |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 60 | interface, "/xyz/openbmc_project/inventory"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | inline void handleStorageCollectionGet( |
| 64 | App& app, const crow::Request& req, |
| 65 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 66 | { |
| 67 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 68 | { |
| 69 | return; |
| 70 | } |
| 71 | asyncResp->res.jsonValue["@odata.type"] = |
| 72 | "#StorageCollection.StorageCollection"; |
| 73 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Storage"; |
| 74 | asyncResp->res.jsonValue["Name"] = "Storage Collection"; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 75 | constexpr std::array<std::string_view, 1> interface{ |
| 76 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 77 | collection_util::getCollectionMembers( |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 78 | asyncResp, boost::urls::format("/redfish/v1/Storage"), interface, |
| 79 | "/xyz/openbmc_project/inventory"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 80 | } |
| 81 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 82 | inline void requestRoutesStorageCollection(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 83 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 84 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 85 | .privileges(redfish::privileges::getStorageCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 86 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 87 | std::bind_front(handleSystemsStorageCollectionGet, std::ref(app))); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 88 | BMCWEB_ROUTE(app, "/redfish/v1/Storage/") |
| 89 | .privileges(redfish::privileges::getStorageCollection) |
| 90 | .methods(boost::beast::http::verb::get)( |
| 91 | std::bind_front(handleStorageCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 92 | } |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 93 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 94 | inline void afterChassisDriveCollectionSubtree( |
| 95 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 96 | const boost::system::error_code& ec, |
| 97 | const dbus::utility::MapperGetSubTreePathsResponse& driveList) |
| 98 | { |
| 99 | if (ec) |
| 100 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 101 | BMCWEB_LOG_ERROR("Drive mapper call error"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 102 | messages::internalError(asyncResp->res); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | nlohmann::json& driveArray = asyncResp->res.jsonValue["Drives"]; |
| 107 | driveArray = nlohmann::json::array(); |
| 108 | auto& count = asyncResp->res.jsonValue["Drives@odata.count"]; |
| 109 | count = 0; |
| 110 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 111 | for (const std::string& drive : driveList) |
| 112 | { |
| 113 | sdbusplus::message::object_path object(drive); |
| 114 | if (object.filename().empty()) |
| 115 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 116 | BMCWEB_LOG_ERROR("Failed to find filename in {}", drive); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | |
| 120 | nlohmann::json::object_t driveJson; |
| 121 | driveJson["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 122 | "/redfish/v1/Systems/{}/Storage/1/Drives/{}", |
| 123 | BMCWEB_REDFISH_SYSTEM_URI_NAME, object.filename()); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 124 | driveArray.emplace_back(std::move(driveJson)); |
| 125 | } |
| 126 | |
| 127 | count = driveArray.size(); |
| 128 | } |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 129 | inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 130 | { |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 131 | const std::array<std::string_view, 1> interfaces = { |
| 132 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
| 133 | dbus::utility::getSubTreePaths( |
| 134 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 135 | std::bind_front(afterChassisDriveCollectionSubtree, asyncResp)); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 136 | } |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 137 | |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 138 | inline void afterSystemsStorageGetSubtree( |
| 139 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 140 | const std::string& storageId, const boost::system::error_code& ec, |
| 141 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 142 | { |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 143 | if (ec) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 144 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 145 | BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 146 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 147 | storageId); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 148 | return; |
| 149 | } |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 150 | auto storage = std::ranges::find_if( |
| 151 | subtree, |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 152 | [&storageId](const std::pair<std::string, |
| 153 | dbus::utility::MapperServiceMap>& object) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 154 | return sdbusplus::message::object_path(object.first).filename() == |
| 155 | storageId; |
| 156 | }); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 157 | if (storage == subtree.end()) |
| 158 | { |
| 159 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 160 | storageId); |
| 161 | return; |
| 162 | } |
| 163 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 164 | asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; |
| 165 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 166 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", |
| 167 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 168 | asyncResp->res.jsonValue["Name"] = "Storage"; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 169 | asyncResp->res.jsonValue["Id"] = storageId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 170 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 171 | |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 172 | getDrives(asyncResp); |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 173 | asyncResp->res.jsonValue["Controllers"]["@odata.id"] = |
| 174 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}/Controllers", |
| 175 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 178 | inline void handleSystemsStorageGet( |
| 179 | App& app, const crow::Request& req, |
| 180 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 181 | const std::string& systemName, const std::string& storageId) |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 182 | { |
| 183 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 184 | { |
| 185 | return; |
| 186 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 187 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 188 | { |
| 189 | // Option currently returns no systems. TBD |
| 190 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 191 | systemName); |
| 192 | return; |
| 193 | } |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 194 | |
| 195 | constexpr std::array<std::string_view, 1> interfaces = { |
| 196 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
| 197 | dbus::utility::getSubTree( |
| 198 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 199 | std::bind_front(afterSystemsStorageGetSubtree, asyncResp, storageId)); |
| 200 | } |
| 201 | |
| 202 | inline void afterSubtree(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 203 | const std::string& storageId, |
| 204 | const boost::system::error_code& ec, |
| 205 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 206 | { |
| 207 | if (ec) |
| 208 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 209 | BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 210 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 211 | storageId); |
| 212 | return; |
| 213 | } |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 214 | auto storage = std::ranges::find_if( |
| 215 | subtree, |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 216 | [&storageId](const std::pair<std::string, |
| 217 | dbus::utility::MapperServiceMap>& object) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 218 | return sdbusplus::message::object_path(object.first).filename() == |
| 219 | storageId; |
| 220 | }); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 221 | if (storage == subtree.end()) |
| 222 | { |
| 223 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 224 | storageId); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; |
| 229 | asyncResp->res.jsonValue["@odata.id"] = |
| 230 | boost::urls::format("/redfish/v1/Storage/{}", storageId); |
| 231 | asyncResp->res.jsonValue["Name"] = "Storage"; |
| 232 | asyncResp->res.jsonValue["Id"] = storageId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 233 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 234 | |
| 235 | // Storage subsystem to Storage link. |
| 236 | nlohmann::json::array_t storageServices; |
| 237 | nlohmann::json::object_t storageService; |
| 238 | storageService["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 239 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", |
| 240 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 241 | storageServices.emplace_back(storageService); |
| 242 | asyncResp->res.jsonValue["Links"]["StorageServices"] = |
| 243 | std::move(storageServices); |
| 244 | asyncResp->res.jsonValue["Links"]["StorageServices@odata.count"] = 1; |
| 245 | } |
| 246 | |
| 247 | inline void |
| 248 | handleStorageGet(App& app, const crow::Request& req, |
| 249 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 250 | const std::string& storageId) |
| 251 | { |
| 252 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 253 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 254 | BMCWEB_LOG_DEBUG("requestRoutesStorage setUpRedfishRoute failed"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 255 | return; |
| 256 | } |
| 257 | |
| 258 | constexpr std::array<std::string_view, 1> interfaces = { |
| 259 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
| 260 | dbus::utility::getSubTree( |
| 261 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 262 | std::bind_front(afterSubtree, asyncResp, storageId)); |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 263 | } |
| 264 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 265 | inline void requestRoutesStorage(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 266 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 267 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 268 | .privileges(redfish::privileges::getStorage) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 269 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 270 | std::bind_front(handleSystemsStorageGet, std::ref(app))); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 271 | |
| 272 | BMCWEB_ROUTE(app, "/redfish/v1/Storage/<str>/") |
| 273 | .privileges(redfish::privileges::getStorage) |
| 274 | .methods(boost::beast::http::verb::get)( |
| 275 | std::bind_front(handleStorageGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 278 | inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 279 | const std::string& connectionName, |
| 280 | const std::string& path) |
| 281 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 282 | dbus::utility::getAllProperties( |
| 283 | connectionName, path, "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 284 | [asyncResp](const boost::system::error_code& ec, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 285 | const std::vector< |
| 286 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 287 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 288 | if (ec) |
| 289 | { |
| 290 | // this interface isn't necessary |
| 291 | return; |
| 292 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 293 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 294 | const std::string* partNumber = nullptr; |
| 295 | const std::string* serialNumber = nullptr; |
| 296 | const std::string* manufacturer = nullptr; |
| 297 | const std::string* model = nullptr; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 298 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 299 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 300 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 301 | partNumber, "SerialNumber", serialNumber, "Manufacturer", |
| 302 | manufacturer, "Model", model); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 303 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 304 | if (!success) |
| 305 | { |
| 306 | messages::internalError(asyncResp->res); |
| 307 | return; |
| 308 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 309 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 310 | if (partNumber != nullptr) |
| 311 | { |
| 312 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 313 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 314 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 315 | if (serialNumber != nullptr) |
| 316 | { |
| 317 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 318 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 319 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 320 | if (manufacturer != nullptr) |
| 321 | { |
| 322 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 323 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 324 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 325 | if (model != nullptr) |
| 326 | { |
| 327 | asyncResp->res.jsonValue["Model"] = *model; |
| 328 | } |
| 329 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 333 | const std::string& connectionName, |
| 334 | const std::string& path) |
| 335 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 336 | dbus::utility::getProperty<bool>( |
| 337 | connectionName, path, "xyz.openbmc_project.Inventory.Item", "Present", |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 338 | [asyncResp, |
| 339 | path](const boost::system::error_code& ec, const bool isPresent) { |
| 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 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 347 | if (!isPresent) |
| 348 | { |
| 349 | asyncResp->res.jsonValue["Status"]["State"] = |
| 350 | resource::State::Absent; |
| 351 | } |
| 352 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 356 | const std::string& connectionName, |
| 357 | const std::string& path) |
| 358 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 359 | dbus::utility::getProperty<bool>( |
| 360 | connectionName, path, "xyz.openbmc_project.State.Drive", "Rebuilding", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 361 | [asyncResp](const boost::system::error_code& ec, const bool updating) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [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 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [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"] = |
| 376 | resource::State::Updating; |
| 377 | } |
| 378 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 379 | } |
| 380 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 381 | inline std::optional<drive::MediaType> convertDriveType(std::string_view type) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 382 | { |
| 383 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.HDD") |
| 384 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 385 | return drive::MediaType::HDD; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 386 | } |
| 387 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.SSD") |
| 388 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 389 | return drive::MediaType::SSD; |
| 390 | } |
| 391 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.Unknown") |
| 392 | { |
| 393 | return std::nullopt; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 394 | } |
| 395 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 396 | return drive::MediaType::Invalid; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 397 | } |
| 398 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 399 | inline std::optional<protocol::Protocol> |
| 400 | convertDriveProtocol(std::string_view proto) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 401 | { |
| 402 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SAS") |
| 403 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 404 | return protocol::Protocol::SAS; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 405 | } |
| 406 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SATA") |
| 407 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 408 | return protocol::Protocol::SATA; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 409 | } |
| 410 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.NVMe") |
| 411 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 412 | return protocol::Protocol::NVMe; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 413 | } |
| 414 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.FC") |
| 415 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 416 | return protocol::Protocol::FC; |
| 417 | } |
| 418 | if (proto == |
| 419 | "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.Unknown") |
| 420 | { |
| 421 | return std::nullopt; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 422 | } |
| 423 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 424 | return protocol::Protocol::Invalid; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 427 | inline void getDriveItemProperties( |
| 428 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 429 | const std::string& connectionName, const std::string& path) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 430 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 431 | dbus::utility::getAllProperties( |
| 432 | connectionName, path, "xyz.openbmc_project.Inventory.Item.Drive", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 433 | [asyncResp](const boost::system::error_code& ec, |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 434 | const std::vector< |
| 435 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 436 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 437 | if (ec) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 438 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 439 | // this interface isn't required |
| 440 | return; |
| 441 | } |
| 442 | const std::string* encryptionStatus = nullptr; |
| 443 | const bool* isLocked = nullptr; |
| 444 | for (const std::pair<std::string, dbus::utility::DbusVariantType>& |
| 445 | property : propertiesList) |
| 446 | { |
| 447 | const std::string& propertyName = property.first; |
| 448 | if (propertyName == "Type") |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 449 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 450 | const std::string* value = |
| 451 | std::get_if<std::string>(&property.second); |
| 452 | if (value == nullptr) |
| 453 | { |
| 454 | // illegal property |
| 455 | BMCWEB_LOG_ERROR("Illegal property: Type"); |
| 456 | messages::internalError(asyncResp->res); |
| 457 | return; |
| 458 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 459 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 460 | std::optional<drive::MediaType> mediaType = |
| 461 | convertDriveType(*value); |
| 462 | if (!mediaType) |
| 463 | { |
| 464 | BMCWEB_LOG_WARNING("UnknownDriveType Interface: {}", |
| 465 | *value); |
| 466 | continue; |
| 467 | } |
| 468 | if (*mediaType == drive::MediaType::Invalid) |
| 469 | { |
| 470 | messages::internalError(asyncResp->res); |
| 471 | return; |
| 472 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 473 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 474 | asyncResp->res.jsonValue["MediaType"] = *mediaType; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 475 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 476 | else if (propertyName == "Capacity") |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 477 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 478 | const uint64_t* capacity = |
| 479 | std::get_if<uint64_t>(&property.second); |
| 480 | if (capacity == nullptr) |
| 481 | { |
| 482 | BMCWEB_LOG_ERROR("Illegal property: Capacity"); |
| 483 | messages::internalError(asyncResp->res); |
| 484 | return; |
| 485 | } |
| 486 | if (*capacity == 0) |
| 487 | { |
| 488 | // drive capacity not known |
| 489 | continue; |
| 490 | } |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 491 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 492 | asyncResp->res.jsonValue["CapacityBytes"] = *capacity; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 493 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 494 | else if (propertyName == "Protocol") |
| 495 | { |
| 496 | const std::string* value = |
| 497 | std::get_if<std::string>(&property.second); |
| 498 | if (value == nullptr) |
| 499 | { |
| 500 | BMCWEB_LOG_ERROR("Illegal property: Protocol"); |
| 501 | messages::internalError(asyncResp->res); |
| 502 | return; |
| 503 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 504 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 505 | std::optional<protocol::Protocol> proto = |
| 506 | convertDriveProtocol(*value); |
| 507 | if (!proto) |
| 508 | { |
| 509 | BMCWEB_LOG_WARNING( |
| 510 | "Unknown DrivePrototype Interface: {}", *value); |
| 511 | continue; |
| 512 | } |
| 513 | if (*proto == protocol::Protocol::Invalid) |
| 514 | { |
| 515 | messages::internalError(asyncResp->res); |
| 516 | return; |
| 517 | } |
| 518 | asyncResp->res.jsonValue["Protocol"] = *proto; |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 519 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 520 | else if (propertyName == "PredictedMediaLifeLeftPercent") |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 521 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 522 | const uint8_t* lifeLeft = |
| 523 | std::get_if<uint8_t>(&property.second); |
| 524 | if (lifeLeft == nullptr) |
| 525 | { |
| 526 | BMCWEB_LOG_ERROR( |
| 527 | "Illegal property: PredictedMediaLifeLeftPercent"); |
| 528 | messages::internalError(asyncResp->res); |
| 529 | return; |
| 530 | } |
| 531 | // 255 means reading the value is not supported |
| 532 | if (*lifeLeft != 255) |
| 533 | { |
| 534 | asyncResp->res |
| 535 | .jsonValue["PredictedMediaLifeLeftPercent"] = |
| 536 | *lifeLeft; |
| 537 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 538 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 539 | else if (propertyName == "EncryptionStatus") |
John Edward Broadbent | 3fe4d5c | 2022-05-06 14:42:35 -0700 | [diff] [blame] | 540 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 541 | encryptionStatus = |
| 542 | std::get_if<std::string>(&property.second); |
| 543 | if (encryptionStatus == nullptr) |
| 544 | { |
| 545 | BMCWEB_LOG_ERROR("Illegal property: EncryptionStatus"); |
| 546 | messages::internalError(asyncResp->res); |
| 547 | return; |
| 548 | } |
John Edward Broadbent | 3fe4d5c | 2022-05-06 14:42:35 -0700 | [diff] [blame] | 549 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 550 | else if (propertyName == "Locked") |
John Edward Broadbent | 3fe4d5c | 2022-05-06 14:42:35 -0700 | [diff] [blame] | 551 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 552 | isLocked = std::get_if<bool>(&property.second); |
| 553 | if (isLocked == nullptr) |
| 554 | { |
| 555 | BMCWEB_LOG_ERROR("Illegal property: Locked"); |
| 556 | messages::internalError(asyncResp->res); |
| 557 | return; |
| 558 | } |
John Edward Broadbent | 3fe4d5c | 2022-05-06 14:42:35 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
John Edward Broadbent | e5029d8 | 2022-06-08 14:35:21 -0700 | [diff] [blame] | 561 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 562 | if (encryptionStatus == nullptr || isLocked == nullptr || |
| 563 | *encryptionStatus == |
| 564 | "xyz.openbmc_project.Inventory.Item.Drive.DriveEncryptionState.Unknown") |
| 565 | { |
| 566 | return; |
| 567 | } |
| 568 | if (*encryptionStatus != |
| 569 | "xyz.openbmc_project.Inventory.Item.Drive.DriveEncryptionState.Encrypted") |
| 570 | { |
| 571 | //"The drive is not currently encrypted." |
| 572 | asyncResp->res.jsonValue["EncryptionStatus"] = |
| 573 | drive::EncryptionStatus::Unencrypted; |
| 574 | return; |
| 575 | } |
| 576 | if (*isLocked) |
| 577 | { |
| 578 | //"The drive is currently encrypted and the data is not |
| 579 | // accessible to the user." |
| 580 | asyncResp->res.jsonValue["EncryptionStatus"] = |
| 581 | drive::EncryptionStatus::Locked; |
| 582 | return; |
| 583 | } |
| 584 | // if not locked |
| 585 | // "The drive is currently encrypted but the data is accessible |
| 586 | // to the user in unencrypted form." |
John Edward Broadbent | e5029d8 | 2022-06-08 14:35:21 -0700 | [diff] [blame] | 587 | asyncResp->res.jsonValue["EncryptionStatus"] = |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 588 | drive::EncryptionStatus::Unlocked; |
| 589 | }); |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Ed Tanous | 4ff0f1f | 2024-09-04 17:27:37 -0700 | [diff] [blame] | 592 | inline void addAllDriveInfo(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 593 | const std::string& connectionName, |
| 594 | const std::string& path, |
| 595 | const std::vector<std::string>& interfaces) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 596 | { |
| 597 | for (const std::string& interface : interfaces) |
| 598 | { |
| 599 | if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 600 | { |
| 601 | getDriveAsset(asyncResp, connectionName, path); |
| 602 | } |
| 603 | else if (interface == "xyz.openbmc_project.Inventory.Item") |
| 604 | { |
| 605 | getDrivePresent(asyncResp, connectionName, path); |
| 606 | } |
| 607 | else if (interface == "xyz.openbmc_project.State.Drive") |
| 608 | { |
| 609 | getDriveState(asyncResp, connectionName, path); |
| 610 | } |
| 611 | else if (interface == "xyz.openbmc_project.Inventory.Item.Drive") |
| 612 | { |
| 613 | getDriveItemProperties(asyncResp, connectionName, path); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 618 | inline void afterGetSubtreeSystemsStorageDrive( |
| 619 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 620 | const std::string& driveId, const boost::system::error_code& ec, |
| 621 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 622 | { |
| 623 | if (ec) |
| 624 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 625 | BMCWEB_LOG_ERROR("Drive mapper call error"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 626 | messages::internalError(asyncResp->res); |
| 627 | return; |
| 628 | } |
| 629 | |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 630 | auto drive = std::ranges::find_if( |
| 631 | subtree, |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 632 | [&driveId](const std::pair<std::string, |
| 633 | dbus::utility::MapperServiceMap>& object) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 634 | return sdbusplus::message::object_path(object.first).filename() == |
| 635 | driveId; |
| 636 | }); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 637 | |
| 638 | if (drive == subtree.end()) |
| 639 | { |
| 640 | messages::resourceNotFound(asyncResp->res, "Drive", driveId); |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | const std::string& path = drive->first; |
| 645 | const dbus::utility::MapperServiceMap& connectionNames = drive->second; |
| 646 | |
| 647 | asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 648 | asyncResp->res.jsonValue["@odata.id"] = |
| 649 | boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Drives/{}", |
| 650 | BMCWEB_REDFISH_SYSTEM_URI_NAME, driveId); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 651 | asyncResp->res.jsonValue["Name"] = driveId; |
| 652 | asyncResp->res.jsonValue["Id"] = driveId; |
| 653 | |
| 654 | if (connectionNames.size() != 1) |
| 655 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 656 | BMCWEB_LOG_ERROR("Connection size {}, not equal to 1", |
| 657 | connectionNames.size()); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 658 | messages::internalError(asyncResp->res); |
| 659 | return; |
| 660 | } |
| 661 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 662 | getMainChassisId( |
| 663 | asyncResp, [](const std::string& chassisId, |
| 664 | const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { |
| 665 | aRsp->res.jsonValue["Links"]["Chassis"]["@odata.id"] = |
| 666 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
| 667 | }); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 668 | |
| 669 | // default it to Enabled |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 670 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 671 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 672 | addAllDriveInfo(asyncResp, connectionNames[0].first, path, |
| 673 | connectionNames[0].second); |
| 674 | } |
| 675 | |
| 676 | inline void handleSystemsStorageDriveGet( |
| 677 | App& app, const crow::Request& req, |
| 678 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 679 | const std::string& systemName, const std::string& driveId) |
| 680 | { |
| 681 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 682 | { |
| 683 | return; |
| 684 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 685 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 686 | { |
| 687 | // Option currently returns no systems. TBD |
| 688 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 689 | systemName); |
| 690 | return; |
| 691 | } |
| 692 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 693 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 694 | { |
| 695 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 696 | systemName); |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | constexpr std::array<std::string_view, 1> interfaces = { |
| 701 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
| 702 | dbus::utility::getSubTree( |
| 703 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 704 | std::bind_front(afterGetSubtreeSystemsStorageDrive, asyncResp, |
| 705 | driveId)); |
| 706 | } |
| 707 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 708 | inline void requestRoutesDrive(App& app) |
| 709 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 710 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Drives/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 711 | .privileges(redfish::privileges::getDrive) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 712 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 713 | std::bind_front(handleSystemsStorageDriveGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 714 | } |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 715 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 716 | inline void afterChassisDriveCollectionSubtreeGet( |
| 717 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 718 | const std::string& chassisId, const boost::system::error_code& ec, |
| 719 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 720 | { |
| 721 | if (ec) |
| 722 | { |
| 723 | if (ec == boost::system::errc::host_unreachable) |
| 724 | { |
| 725 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
| 726 | return; |
| 727 | } |
| 728 | messages::internalError(asyncResp->res); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | // Iterate over all retrieved ObjectPaths. |
| 733 | for (const auto& [path, connectionNames] : subtree) |
| 734 | { |
| 735 | sdbusplus::message::object_path objPath(path); |
| 736 | if (objPath.filename() != chassisId) |
| 737 | { |
| 738 | continue; |
| 739 | } |
| 740 | |
| 741 | if (connectionNames.empty()) |
| 742 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 743 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 744 | continue; |
| 745 | } |
| 746 | |
| 747 | asyncResp->res.jsonValue["@odata.type"] = |
| 748 | "#DriveCollection.DriveCollection"; |
| 749 | asyncResp->res.jsonValue["@odata.id"] = |
| 750 | boost::urls::format("/redfish/v1/Chassis/{}/Drives", chassisId); |
| 751 | asyncResp->res.jsonValue["Name"] = "Drive Collection"; |
| 752 | |
| 753 | // Association lambda |
| 754 | dbus::utility::getAssociationEndPoints( |
| 755 | path + "/drive", |
| 756 | [asyncResp, chassisId](const boost::system::error_code& ec3, |
| 757 | const dbus::utility::MapperEndPoints& resp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 758 | if (ec3) |
| 759 | { |
| 760 | BMCWEB_LOG_ERROR("Error in chassis Drive association "); |
| 761 | } |
| 762 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
| 763 | // important if array is empty |
| 764 | members = nlohmann::json::array(); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 765 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 766 | std::vector<std::string> leafNames; |
| 767 | for (const auto& drive : resp) |
| 768 | { |
| 769 | sdbusplus::message::object_path drivePath(drive); |
| 770 | leafNames.push_back(drivePath.filename()); |
| 771 | } |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 772 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 773 | std::ranges::sort(leafNames, AlphanumLess<std::string>()); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 774 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 775 | for (const auto& leafName : leafNames) |
| 776 | { |
| 777 | nlohmann::json::object_t member; |
| 778 | member["@odata.id"] = |
| 779 | boost::urls::format("/redfish/v1/Chassis/{}/Drives/{}", |
| 780 | chassisId, leafName); |
| 781 | members.emplace_back(std::move(member)); |
| 782 | // navigation links will be registered in next patch set |
| 783 | } |
| 784 | asyncResp->res.jsonValue["Members@odata.count"] = resp.size(); |
| 785 | }); // end association lambda |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 786 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 787 | } // end Iterate over all retrieved ObjectPaths |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 788 | } |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 789 | /** |
| 790 | * Chassis drives, this URL will show all the DriveCollection |
| 791 | * information |
| 792 | */ |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 793 | inline void chassisDriveCollectionGet( |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 794 | crow::App& app, const crow::Request& req, |
| 795 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 796 | const std::string& chassisId) |
| 797 | { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 798 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 799 | { |
| 800 | return; |
| 801 | } |
| 802 | |
| 803 | // mapper call lambda |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 804 | constexpr std::array<std::string_view, 2> interfaces = { |
| 805 | "xyz.openbmc_project.Inventory.Item.Board", |
| 806 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 807 | dbus::utility::getSubTree( |
| 808 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 809 | std::bind_front(afterChassisDriveCollectionSubtreeGet, asyncResp, |
| 810 | chassisId)); |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | inline void requestRoutesChassisDrive(App& app) |
| 814 | { |
| 815 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/") |
| 816 | .privileges(redfish::privileges::getDriveCollection) |
| 817 | .methods(boost::beast::http::verb::get)( |
| 818 | std::bind_front(chassisDriveCollectionGet, std::ref(app))); |
| 819 | } |
| 820 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 821 | inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 822 | const std::string& chassisId, |
| 823 | const std::string& driveName, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 824 | const boost::system::error_code& ec, |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 825 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 826 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 827 | if (ec) |
| 828 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 829 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 830 | messages::internalError(asyncResp->res); |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | // Iterate over all retrieved ObjectPaths. |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 835 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 836 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 837 | sdbusplus::message::object_path objPath(path); |
| 838 | if (objPath.filename() != driveName) |
| 839 | { |
| 840 | continue; |
| 841 | } |
| 842 | |
| 843 | if (connectionNames.empty()) |
| 844 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 845 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 846 | continue; |
| 847 | } |
| 848 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 849 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 850 | "/redfish/v1/Chassis/{}/Drives/{}", chassisId, driveName); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 851 | |
| 852 | asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; |
John Edward Broadbent | a0cb40c | 2022-06-29 17:27:38 -0700 | [diff] [blame] | 853 | asyncResp->res.jsonValue["Name"] = driveName; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 854 | asyncResp->res.jsonValue["Id"] = driveName; |
| 855 | // default it to Enabled |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 856 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 857 | |
| 858 | nlohmann::json::object_t linkChassisNav; |
| 859 | linkChassisNav["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 860 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 861 | asyncResp->res.jsonValue["Links"]["Chassis"] = linkChassisNav; |
| 862 | |
| 863 | addAllDriveInfo(asyncResp, connectionNames[0].first, path, |
| 864 | connectionNames[0].second); |
| 865 | } |
| 866 | } |
| 867 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 868 | inline void matchAndFillDrive( |
| 869 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 870 | const std::string& chassisId, const std::string& driveName, |
| 871 | const std::vector<std::string>& resp) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 872 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 873 | for (const std::string& drivePath : resp) |
| 874 | { |
| 875 | sdbusplus::message::object_path path(drivePath); |
| 876 | std::string leaf = path.filename(); |
| 877 | if (leaf != driveName) |
| 878 | { |
| 879 | continue; |
| 880 | } |
| 881 | // mapper call drive |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 882 | constexpr std::array<std::string_view, 1> driveInterface = { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 883 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 884 | dbus::utility::getSubTree( |
| 885 | "/xyz/openbmc_project/inventory", 0, driveInterface, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 886 | [asyncResp, chassisId, driveName]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 887 | const boost::system::error_code& ec, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 888 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 889 | buildDrive(asyncResp, chassisId, driveName, ec, subtree); |
| 890 | }); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 894 | inline void handleChassisDriveGet( |
| 895 | crow::App& app, const crow::Request& req, |
| 896 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 897 | const std::string& chassisId, const std::string& driveName) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 898 | { |
Michal Orzel | 03810a1 | 2022-06-15 14:04:28 +0200 | [diff] [blame] | 899 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 900 | { |
| 901 | return; |
| 902 | } |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 903 | constexpr std::array<std::string_view, 2> interfaces = { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 904 | "xyz.openbmc_project.Inventory.Item.Board", |
| 905 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 906 | |
| 907 | // mapper call chassis |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 908 | dbus::utility::getSubTree( |
| 909 | "/xyz/openbmc_project/inventory", 0, interfaces, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 910 | [asyncResp, chassisId, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 911 | driveName](const boost::system::error_code& ec, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 912 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 913 | if (ec) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 914 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 915 | messages::internalError(asyncResp->res); |
| 916 | return; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 919 | // Iterate over all retrieved ObjectPaths. |
| 920 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 921 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 922 | sdbusplus::message::object_path objPath(path); |
| 923 | if (objPath.filename() != chassisId) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 924 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 925 | continue; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 926 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 927 | |
| 928 | if (connectionNames.empty()) |
| 929 | { |
| 930 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
| 931 | continue; |
| 932 | } |
| 933 | |
| 934 | dbus::utility::getAssociationEndPoints( |
| 935 | path + "/drive", |
| 936 | [asyncResp, chassisId, |
| 937 | driveName](const boost::system::error_code& ec3, |
| 938 | const dbus::utility::MapperEndPoints& resp) { |
| 939 | if (ec3) |
| 940 | { |
| 941 | return; // no drives = no failures |
| 942 | } |
| 943 | matchAndFillDrive(asyncResp, chassisId, driveName, |
| 944 | resp); |
| 945 | }); |
| 946 | break; |
| 947 | } |
| 948 | }); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /** |
| 952 | * This URL will show the drive interface for the specific drive in the chassis |
| 953 | */ |
| 954 | inline void requestRoutesChassisDriveName(App& app) |
| 955 | { |
| 956 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/<str>/") |
| 957 | .privileges(redfish::privileges::getChassis) |
| 958 | .methods(boost::beast::http::verb::get)( |
| 959 | std::bind_front(handleChassisDriveGet, std::ref(app))); |
| 960 | } |
| 961 | |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 962 | inline void getStorageControllerAsset( |
| 963 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 964 | const boost::system::error_code& ec, |
| 965 | const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 966 | propertiesList) |
| 967 | { |
| 968 | if (ec) |
| 969 | { |
| 970 | // this interface isn't necessary |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 971 | BMCWEB_LOG_DEBUG("Failed to get StorageControllerAsset"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 972 | return; |
| 973 | } |
| 974 | |
| 975 | const std::string* partNumber = nullptr; |
| 976 | const std::string* serialNumber = nullptr; |
| 977 | const std::string* manufacturer = nullptr; |
| 978 | const std::string* model = nullptr; |
| 979 | if (!sdbusplus::unpackPropertiesNoThrow( |
| 980 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 981 | partNumber, "SerialNumber", serialNumber, "Manufacturer", |
| 982 | manufacturer, "Model", model)) |
| 983 | { |
| 984 | messages::internalError(asyncResp->res); |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | if (partNumber != nullptr) |
| 989 | { |
| 990 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 991 | } |
| 992 | |
| 993 | if (serialNumber != nullptr) |
| 994 | { |
| 995 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 996 | } |
| 997 | |
| 998 | if (manufacturer != nullptr) |
| 999 | { |
| 1000 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 1001 | } |
| 1002 | |
| 1003 | if (model != nullptr) |
| 1004 | { |
| 1005 | asyncResp->res.jsonValue["Model"] = *model; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | inline void populateStorageController( |
| 1010 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1011 | const std::string& controllerId, const std::string& connectionName, |
| 1012 | const std::string& path) |
| 1013 | { |
| 1014 | asyncResp->res.jsonValue["@odata.type"] = |
| 1015 | "#StorageController.v1_6_0.StorageController"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1016 | asyncResp->res.jsonValue["@odata.id"] = |
| 1017 | boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Controllers/{}", |
| 1018 | BMCWEB_REDFISH_SYSTEM_URI_NAME, controllerId); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1019 | asyncResp->res.jsonValue["Name"] = controllerId; |
| 1020 | asyncResp->res.jsonValue["Id"] = controllerId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1021 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1022 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1023 | dbus::utility::getProperty<bool>( |
| 1024 | connectionName, path, "xyz.openbmc_project.Inventory.Item", "Present", |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1025 | [asyncResp](const boost::system::error_code& ec, bool isPresent) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1026 | // this interface isn't necessary, only check it |
| 1027 | // if we get a good return |
| 1028 | if (ec) |
| 1029 | { |
| 1030 | BMCWEB_LOG_DEBUG("Failed to get Present property"); |
| 1031 | return; |
| 1032 | } |
| 1033 | if (!isPresent) |
| 1034 | { |
| 1035 | asyncResp->res.jsonValue["Status"]["State"] = |
| 1036 | resource::State::Absent; |
| 1037 | } |
| 1038 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1039 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1040 | dbus::utility::getAllProperties( |
| 1041 | connectionName, path, "xyz.openbmc_project.Inventory.Decorator.Asset", |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1042 | [asyncResp](const boost::system::error_code& ec, |
| 1043 | const std::vector< |
| 1044 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 1045 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1046 | getStorageControllerAsset(asyncResp, ec, propertiesList); |
| 1047 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | inline void getStorageControllerHandler( |
| 1051 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1052 | const std::string& controllerId, const boost::system::error_code& ec, |
| 1053 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 1054 | { |
| 1055 | if (ec || subtree.empty()) |
| 1056 | { |
| 1057 | // doesn't have to be there |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1058 | BMCWEB_LOG_DEBUG("Failed to handle StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | for (const auto& [path, interfaceDict] : subtree) |
| 1063 | { |
| 1064 | sdbusplus::message::object_path object(path); |
| 1065 | std::string id = object.filename(); |
| 1066 | if (id.empty()) |
| 1067 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1068 | BMCWEB_LOG_ERROR("Failed to find filename in {}", path); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | if (id != controllerId) |
| 1072 | { |
| 1073 | continue; |
| 1074 | } |
| 1075 | |
| 1076 | if (interfaceDict.size() != 1) |
| 1077 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1078 | BMCWEB_LOG_ERROR("Connection size {}, greater than 1", |
| 1079 | interfaceDict.size()); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1080 | messages::internalError(asyncResp->res); |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | const std::string& connectionName = interfaceDict.front().first; |
| 1085 | populateStorageController(asyncResp, controllerId, connectionName, |
| 1086 | path); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | inline void populateStorageControllerCollection( |
| 1091 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1092 | const boost::system::error_code& ec, |
| 1093 | const dbus::utility::MapperGetSubTreePathsResponse& controllerList) |
| 1094 | { |
| 1095 | nlohmann::json::array_t members; |
| 1096 | if (ec || controllerList.empty()) |
| 1097 | { |
| 1098 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 1099 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1100 | BMCWEB_LOG_DEBUG("Failed to find any StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | for (const std::string& path : controllerList) |
| 1105 | { |
| 1106 | std::string id = sdbusplus::message::object_path(path).filename(); |
| 1107 | if (id.empty()) |
| 1108 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1109 | BMCWEB_LOG_ERROR("Failed to find filename in {}", path); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1110 | return; |
| 1111 | } |
| 1112 | nlohmann::json::object_t member; |
| 1113 | member["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1114 | "/redfish/v1/Systems/{}/Storage/1/Controllers/{}", |
| 1115 | BMCWEB_REDFISH_SYSTEM_URI_NAME, id); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1116 | members.emplace_back(member); |
| 1117 | } |
| 1118 | asyncResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 1119 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 1120 | } |
| 1121 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1122 | inline void handleSystemsStorageControllerCollectionGet( |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1123 | App& app, const crow::Request& req, |
| 1124 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1125 | const std::string& systemName) |
| 1126 | { |
| 1127 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1128 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1129 | BMCWEB_LOG_DEBUG( |
| 1130 | "Failed to setup Redfish Route for StorageController Collection"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1131 | return; |
| 1132 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1133 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1134 | { |
| 1135 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1136 | systemName); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1137 | BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1138 | return; |
| 1139 | } |
| 1140 | |
| 1141 | asyncResp->res.jsonValue["@odata.type"] = |
| 1142 | "#StorageControllerCollection.StorageControllerCollection"; |
| 1143 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1144 | std::format("/redfish/v1/Systems/{}/Storage/1/Controllers", |
| 1145 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1146 | asyncResp->res.jsonValue["Name"] = "Storage Controller Collection"; |
| 1147 | |
| 1148 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1149 | "xyz.openbmc_project.Inventory.Item.StorageController"}; |
| 1150 | dbus::utility::getSubTreePaths( |
| 1151 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1152 | [asyncResp](const boost::system::error_code& ec, |
| 1153 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1154 | controllerList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1155 | populateStorageControllerCollection(asyncResp, ec, controllerList); |
| 1156 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1159 | inline void handleSystemsStorageControllerGet( |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1160 | App& app, const crow::Request& req, |
| 1161 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1162 | const std::string& systemName, const std::string& controllerId) |
| 1163 | { |
| 1164 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1165 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1166 | BMCWEB_LOG_DEBUG("Failed to setup Redfish Route for StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1167 | return; |
| 1168 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1169 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1170 | { |
| 1171 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1172 | systemName); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1173 | BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1174 | return; |
| 1175 | } |
| 1176 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1177 | "xyz.openbmc_project.Inventory.Item.StorageController"}; |
| 1178 | dbus::utility::getSubTree( |
| 1179 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1180 | [asyncResp, |
| 1181 | controllerId](const boost::system::error_code& ec, |
| 1182 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1183 | getStorageControllerHandler(asyncResp, controllerId, ec, subtree); |
| 1184 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | inline void requestRoutesStorageControllerCollection(App& app) |
| 1188 | { |
| 1189 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/") |
| 1190 | .privileges(redfish::privileges::getStorageControllerCollection) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1191 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1192 | handleSystemsStorageControllerCollectionGet, std::ref(app))); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | inline void requestRoutesStorageController(App& app) |
| 1196 | { |
| 1197 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/<str>") |
| 1198 | .privileges(redfish::privileges::getStorageController) |
| 1199 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1200 | std::bind_front(handleSystemsStorageControllerGet, std::ref(app))); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 1203 | } // namespace redfish |