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