Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 18 | #include "bmcweb_config.h" |
| 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 21 | #include "dbus_utility.hpp" |
John Edward Broadbent | e5029d8 | 2022-06-08 14:35:21 -0700 | [diff] [blame] | 22 | #include "generated/enums/drive.hpp" |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 23 | #include "generated/enums/protocol.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 24 | #include "generated/enums/resource.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 25 | #include "human_sort.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 26 | #include "query.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 27 | #include "redfish_util.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 28 | #include "registries/privilege_registry.hpp" |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 29 | #include "utils/collection.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 30 | #include "utils/dbus_utils.hpp" |
James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 31 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 32 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 33 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 34 | #include <sdbusplus/asio/property.hpp> |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 35 | #include <sdbusplus/unpack_properties.hpp> |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 36 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 37 | #include <array> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 38 | #include <ranges> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 39 | #include <string_view> |
| 40 | |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 41 | namespace redfish |
| 42 | { |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 43 | |
| 44 | inline void handleSystemsStorageCollectionGet( |
| 45 | App& app, const crow::Request& req, |
| 46 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 47 | const std::string& systemName) |
| 48 | { |
| 49 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 50 | { |
| 51 | return; |
| 52 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 53 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 54 | { |
| 55 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 56 | systemName); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | asyncResp->res.jsonValue["@odata.type"] = |
| 61 | "#StorageCollection.StorageCollection"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 62 | asyncResp->res.jsonValue["@odata.id"] = std::format( |
| 63 | "/redfish/v1/Systems/{}/Storage", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 64 | asyncResp->res.jsonValue["Name"] = "Storage Collection"; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 65 | |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 66 | constexpr std::array<std::string_view, 1> interface{ |
| 67 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 68 | collection_util::getCollectionMembers( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 69 | asyncResp, |
| 70 | boost::urls::format("/redfish/v1/Systems/{}/Storage", |
| 71 | BMCWEB_REDFISH_SYSTEM_URI_NAME), |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 72 | interface, "/xyz/openbmc_project/inventory"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | inline void handleStorageCollectionGet( |
| 76 | App& app, const crow::Request& req, |
| 77 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 78 | { |
| 79 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 80 | { |
| 81 | return; |
| 82 | } |
| 83 | asyncResp->res.jsonValue["@odata.type"] = |
| 84 | "#StorageCollection.StorageCollection"; |
| 85 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Storage"; |
| 86 | asyncResp->res.jsonValue["Name"] = "Storage Collection"; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 87 | constexpr std::array<std::string_view, 1> interface{ |
| 88 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 89 | collection_util::getCollectionMembers( |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 90 | asyncResp, boost::urls::format("/redfish/v1/Storage"), interface, |
| 91 | "/xyz/openbmc_project/inventory"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 92 | } |
| 93 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 94 | inline void requestRoutesStorageCollection(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 95 | { |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 96 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 97 | .privileges(redfish::privileges::getStorageCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 98 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 99 | std::bind_front(handleSystemsStorageCollectionGet, std::ref(app))); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 100 | BMCWEB_ROUTE(app, "/redfish/v1/Storage/") |
| 101 | .privileges(redfish::privileges::getStorageCollection) |
| 102 | .methods(boost::beast::http::verb::get)( |
| 103 | std::bind_front(handleStorageCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 104 | } |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 105 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 106 | inline void afterChassisDriveCollectionSubtree( |
| 107 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 108 | const boost::system::error_code& ec, |
| 109 | const dbus::utility::MapperGetSubTreePathsResponse& driveList) |
| 110 | { |
| 111 | if (ec) |
| 112 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 113 | BMCWEB_LOG_ERROR("Drive mapper call error"); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 114 | messages::internalError(asyncResp->res); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | nlohmann::json& driveArray = asyncResp->res.jsonValue["Drives"]; |
| 119 | driveArray = nlohmann::json::array(); |
| 120 | auto& count = asyncResp->res.jsonValue["Drives@odata.count"]; |
| 121 | count = 0; |
| 122 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 123 | for (const std::string& drive : driveList) |
| 124 | { |
| 125 | sdbusplus::message::object_path object(drive); |
| 126 | if (object.filename().empty()) |
| 127 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 128 | BMCWEB_LOG_ERROR("Failed to find filename in {}", drive); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 129 | return; |
| 130 | } |
| 131 | |
| 132 | nlohmann::json::object_t driveJson; |
| 133 | driveJson["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 134 | "/redfish/v1/Systems/{}/Storage/1/Drives/{}", |
| 135 | BMCWEB_REDFISH_SYSTEM_URI_NAME, object.filename()); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 136 | driveArray.emplace_back(std::move(driveJson)); |
| 137 | } |
| 138 | |
| 139 | count = driveArray.size(); |
| 140 | } |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 141 | inline void getDrives(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 142 | { |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 143 | const std::array<std::string_view, 1> interfaces = { |
| 144 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
| 145 | dbus::utility::getSubTreePaths( |
| 146 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 147 | std::bind_front(afterChassisDriveCollectionSubtree, asyncResp)); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 148 | } |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 149 | |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 150 | inline void afterSystemsStorageGetSubtree( |
| 151 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 152 | const std::string& storageId, const boost::system::error_code& ec, |
| 153 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 154 | { |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 155 | if (ec) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 156 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 157 | BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 158 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 159 | storageId); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 160 | return; |
| 161 | } |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 162 | auto storage = std::ranges::find_if( |
| 163 | subtree, |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 164 | [&storageId](const std::pair<std::string, |
| 165 | dbus::utility::MapperServiceMap>& object) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 166 | return sdbusplus::message::object_path(object.first).filename() == |
| 167 | storageId; |
| 168 | }); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 169 | if (storage == subtree.end()) |
| 170 | { |
| 171 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 172 | storageId); |
| 173 | return; |
| 174 | } |
| 175 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 176 | asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; |
| 177 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 178 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", |
| 179 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 180 | asyncResp->res.jsonValue["Name"] = "Storage"; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 181 | asyncResp->res.jsonValue["Id"] = storageId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 182 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 183 | |
Gunnar Mills | 7ac13cc | 2024-04-01 16:05:21 -0500 | [diff] [blame] | 184 | getDrives(asyncResp); |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 185 | asyncResp->res.jsonValue["Controllers"]["@odata.id"] = |
| 186 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}/Controllers", |
| 187 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 190 | inline void handleSystemsStorageGet( |
| 191 | App& app, const crow::Request& req, |
| 192 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 193 | const std::string& systemName, const std::string& storageId) |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 194 | { |
| 195 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 196 | { |
| 197 | return; |
| 198 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 199 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 200 | { |
| 201 | // Option currently returns no systems. TBD |
| 202 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 203 | systemName); |
| 204 | return; |
| 205 | } |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 206 | |
| 207 | constexpr std::array<std::string_view, 1> interfaces = { |
| 208 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
| 209 | dbus::utility::getSubTree( |
| 210 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 211 | std::bind_front(afterSystemsStorageGetSubtree, asyncResp, storageId)); |
| 212 | } |
| 213 | |
| 214 | inline void afterSubtree(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 215 | const std::string& storageId, |
| 216 | const boost::system::error_code& ec, |
| 217 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 218 | { |
| 219 | if (ec) |
| 220 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 221 | BMCWEB_LOG_DEBUG("requestRoutesStorage DBUS response error"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 222 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 223 | storageId); |
| 224 | return; |
| 225 | } |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 226 | auto storage = std::ranges::find_if( |
| 227 | subtree, |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 228 | [&storageId](const std::pair<std::string, |
| 229 | dbus::utility::MapperServiceMap>& object) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 230 | return sdbusplus::message::object_path(object.first).filename() == |
| 231 | storageId; |
| 232 | }); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 233 | if (storage == subtree.end()) |
| 234 | { |
| 235 | messages::resourceNotFound(asyncResp->res, "#Storage.v1_13_0.Storage", |
| 236 | storageId); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | asyncResp->res.jsonValue["@odata.type"] = "#Storage.v1_13_0.Storage"; |
| 241 | asyncResp->res.jsonValue["@odata.id"] = |
| 242 | boost::urls::format("/redfish/v1/Storage/{}", storageId); |
| 243 | asyncResp->res.jsonValue["Name"] = "Storage"; |
| 244 | asyncResp->res.jsonValue["Id"] = storageId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 245 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 246 | |
| 247 | // Storage subsystem to Storage link. |
| 248 | nlohmann::json::array_t storageServices; |
| 249 | nlohmann::json::object_t storageService; |
| 250 | storageService["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 251 | boost::urls::format("/redfish/v1/Systems/{}/Storage/{}", |
| 252 | BMCWEB_REDFISH_SYSTEM_URI_NAME, storageId); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 253 | storageServices.emplace_back(storageService); |
| 254 | asyncResp->res.jsonValue["Links"]["StorageServices"] = |
| 255 | std::move(storageServices); |
| 256 | asyncResp->res.jsonValue["Links"]["StorageServices@odata.count"] = 1; |
| 257 | } |
| 258 | |
| 259 | inline void |
| 260 | handleStorageGet(App& app, const crow::Request& req, |
| 261 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 262 | const std::string& storageId) |
| 263 | { |
| 264 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 265 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 266 | BMCWEB_LOG_DEBUG("requestRoutesStorage setUpRedfishRoute failed"); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | |
| 270 | constexpr std::array<std::string_view, 1> interfaces = { |
| 271 | "xyz.openbmc_project.Inventory.Item.Storage"}; |
| 272 | dbus::utility::getSubTree( |
| 273 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 274 | std::bind_front(afterSubtree, asyncResp, storageId)); |
Willy Tu | a85afbe | 2021-12-28 14:43:47 -0800 | [diff] [blame] | 275 | } |
| 276 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 277 | inline void requestRoutesStorage(App& app) |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 278 | { |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 279 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 280 | .privileges(redfish::privileges::getStorage) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 281 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 282 | std::bind_front(handleSystemsStorageGet, std::ref(app))); |
Willy Tu | 5e577bc | 2022-07-26 00:41:55 +0000 | [diff] [blame] | 283 | |
| 284 | BMCWEB_ROUTE(app, "/redfish/v1/Storage/<str>/") |
| 285 | .privileges(redfish::privileges::getStorage) |
| 286 | .methods(boost::beast::http::verb::get)( |
| 287 | std::bind_front(handleStorageGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 290 | inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 291 | const std::string& connectionName, |
| 292 | const std::string& path) |
| 293 | { |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 294 | sdbusplus::asio::getAllProperties( |
| 295 | *crow::connections::systemBus, connectionName, path, |
| 296 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 297 | [asyncResp](const boost::system::error_code& ec, |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 298 | const std::vector< |
| 299 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 300 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 301 | if (ec) |
| 302 | { |
| 303 | // this interface isn't necessary |
| 304 | return; |
| 305 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 306 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 307 | const std::string* partNumber = nullptr; |
| 308 | const std::string* serialNumber = nullptr; |
| 309 | const std::string* manufacturer = nullptr; |
| 310 | const std::string* model = nullptr; |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 311 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 312 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 313 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 314 | partNumber, "SerialNumber", serialNumber, "Manufacturer", |
| 315 | manufacturer, "Model", model); |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 316 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 317 | if (!success) |
| 318 | { |
| 319 | messages::internalError(asyncResp->res); |
| 320 | return; |
| 321 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 322 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 323 | if (partNumber != nullptr) |
| 324 | { |
| 325 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 326 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 327 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 328 | if (serialNumber != nullptr) |
| 329 | { |
| 330 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 331 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 332 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 333 | if (manufacturer != nullptr) |
| 334 | { |
| 335 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 336 | } |
Krzysztof Grobelny | d1bde9e | 2022-09-07 10:40:51 +0200 | [diff] [blame] | 337 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 338 | if (model != nullptr) |
| 339 | { |
| 340 | asyncResp->res.jsonValue["Model"] = *model; |
| 341 | } |
| 342 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 346 | const std::string& connectionName, |
| 347 | const std::string& path) |
| 348 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 349 | sdbusplus::asio::getProperty<bool>( |
| 350 | *crow::connections::systemBus, connectionName, path, |
| 351 | "xyz.openbmc_project.Inventory.Item", "Present", |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 352 | [asyncResp, |
| 353 | path](const boost::system::error_code& ec, const bool isPresent) { |
| 354 | // this interface isn't necessary, only check it if |
| 355 | // we get a good return |
| 356 | if (ec) |
| 357 | { |
| 358 | return; |
| 359 | } |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 360 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 361 | if (!isPresent) |
| 362 | { |
| 363 | asyncResp->res.jsonValue["Status"]["State"] = |
| 364 | resource::State::Absent; |
| 365 | } |
| 366 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 370 | const std::string& connectionName, |
| 371 | const std::string& path) |
| 372 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 373 | sdbusplus::asio::getProperty<bool>( |
| 374 | *crow::connections::systemBus, connectionName, path, |
| 375 | "xyz.openbmc_project.State.Drive", "Rebuilding", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 376 | [asyncResp](const boost::system::error_code& ec, const bool updating) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 377 | // this interface isn't necessary, only check it |
| 378 | // if we get a good return |
| 379 | if (ec) |
| 380 | { |
| 381 | return; |
| 382 | } |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 383 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 384 | // updating and disabled in the backend shouldn't be |
| 385 | // able to be set at the same time, so we don't need |
| 386 | // to check for the race condition of these two |
| 387 | // calls |
| 388 | if (updating) |
| 389 | { |
| 390 | asyncResp->res.jsonValue["Status"]["State"] = |
| 391 | resource::State::Updating; |
| 392 | } |
| 393 | }); |
Willy Tu | 0391317 | 2021-11-08 02:03:19 -0800 | [diff] [blame] | 394 | } |
| 395 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 396 | inline std::optional<drive::MediaType> convertDriveType(std::string_view type) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 397 | { |
| 398 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.HDD") |
| 399 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 400 | return drive::MediaType::HDD; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 401 | } |
| 402 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.SSD") |
| 403 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 404 | return drive::MediaType::SSD; |
| 405 | } |
| 406 | if (type == "xyz.openbmc_project.Inventory.Item.Drive.DriveType.Unknown") |
| 407 | { |
| 408 | return std::nullopt; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 409 | } |
| 410 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 411 | return drive::MediaType::Invalid; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 412 | } |
| 413 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 414 | inline std::optional<protocol::Protocol> |
| 415 | convertDriveProtocol(std::string_view proto) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 416 | { |
| 417 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SAS") |
| 418 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 419 | return protocol::Protocol::SAS; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 420 | } |
| 421 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.SATA") |
| 422 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 423 | return protocol::Protocol::SATA; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 424 | } |
| 425 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.NVMe") |
| 426 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 427 | return protocol::Protocol::NVMe; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 428 | } |
| 429 | if (proto == "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.FC") |
| 430 | { |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 431 | return protocol::Protocol::FC; |
| 432 | } |
| 433 | if (proto == |
| 434 | "xyz.openbmc_project.Inventory.Item.Drive.DriveProtocol.Unknown") |
| 435 | { |
| 436 | return std::nullopt; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 437 | } |
| 438 | |
George Liu | dde9bc1 | 2023-02-22 09:35:51 +0800 | [diff] [blame] | 439 | return protocol::Protocol::Invalid; |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 442 | inline void getDriveItemProperties( |
| 443 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 444 | const std::string& connectionName, const std::string& path) |
Willy Tu | 19b8e9a | 2021-11-08 02:55:03 -0800 | [diff] [blame] | 445 | { |
| 446 | sdbusplus::asio::getAllProperties( |
| 447 | *crow::connections::systemBus, connectionName, path, |
| 448 | "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 | constexpr std::array<std::string_view, 2> interfaces = { |
| 821 | "xyz.openbmc_project.Inventory.Item.Board", |
| 822 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 823 | dbus::utility::getSubTree( |
| 824 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 825 | std::bind_front(afterChassisDriveCollectionSubtreeGet, asyncResp, |
| 826 | chassisId)); |
John Edward Broadbent | 92903bd | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | inline void requestRoutesChassisDrive(App& app) |
| 830 | { |
| 831 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/") |
| 832 | .privileges(redfish::privileges::getDriveCollection) |
| 833 | .methods(boost::beast::http::verb::get)( |
| 834 | std::bind_front(chassisDriveCollectionGet, std::ref(app))); |
| 835 | } |
| 836 | |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 837 | inline void buildDrive(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 838 | const std::string& chassisId, |
| 839 | const std::string& driveName, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 840 | const boost::system::error_code& ec, |
Nan Zhou | b53dcd9 | 2022-06-21 17:47:50 +0000 | [diff] [blame] | 841 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 842 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 843 | if (ec) |
| 844 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 845 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 846 | messages::internalError(asyncResp->res); |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | // Iterate over all retrieved ObjectPaths. |
Nan Zhou | 8cb65f8 | 2022-06-15 05:12:24 +0000 | [diff] [blame] | 851 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 852 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 853 | sdbusplus::message::object_path objPath(path); |
| 854 | if (objPath.filename() != driveName) |
| 855 | { |
| 856 | continue; |
| 857 | } |
| 858 | |
| 859 | if (connectionNames.empty()) |
| 860 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 861 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 862 | continue; |
| 863 | } |
| 864 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 865 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 866 | "/redfish/v1/Chassis/{}/Drives/{}", chassisId, driveName); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 867 | |
| 868 | asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive"; |
John Edward Broadbent | a0cb40c | 2022-06-29 17:27:38 -0700 | [diff] [blame] | 869 | asyncResp->res.jsonValue["Name"] = driveName; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 870 | asyncResp->res.jsonValue["Id"] = driveName; |
| 871 | // default it to Enabled |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 872 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 873 | |
| 874 | nlohmann::json::object_t linkChassisNav; |
| 875 | linkChassisNav["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 876 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 877 | asyncResp->res.jsonValue["Links"]["Chassis"] = linkChassisNav; |
| 878 | |
| 879 | addAllDriveInfo(asyncResp, connectionNames[0].first, path, |
| 880 | connectionNames[0].second); |
| 881 | } |
| 882 | } |
| 883 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 884 | inline void matchAndFillDrive( |
| 885 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 886 | const std::string& chassisId, const std::string& driveName, |
| 887 | const std::vector<std::string>& resp) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 888 | { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 889 | for (const std::string& drivePath : resp) |
| 890 | { |
| 891 | sdbusplus::message::object_path path(drivePath); |
| 892 | std::string leaf = path.filename(); |
| 893 | if (leaf != driveName) |
| 894 | { |
| 895 | continue; |
| 896 | } |
| 897 | // mapper call drive |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 898 | constexpr std::array<std::string_view, 1> driveInterface = { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 899 | "xyz.openbmc_project.Inventory.Item.Drive"}; |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 900 | dbus::utility::getSubTree( |
| 901 | "/xyz/openbmc_project/inventory", 0, driveInterface, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 902 | [asyncResp, chassisId, driveName]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 903 | const boost::system::error_code& ec, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 904 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 905 | buildDrive(asyncResp, chassisId, driveName, ec, subtree); |
| 906 | }); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 910 | inline void handleChassisDriveGet( |
| 911 | crow::App& app, const crow::Request& req, |
| 912 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 913 | const std::string& chassisId, const std::string& driveName) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 914 | { |
Michal Orzel | 03810a1 | 2022-06-15 14:04:28 +0200 | [diff] [blame] | 915 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 916 | { |
| 917 | return; |
| 918 | } |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 919 | constexpr std::array<std::string_view, 2> interfaces = { |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 920 | "xyz.openbmc_project.Inventory.Item.Board", |
| 921 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 922 | |
| 923 | // mapper call chassis |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 924 | dbus::utility::getSubTree( |
| 925 | "/xyz/openbmc_project/inventory", 0, interfaces, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 926 | [asyncResp, chassisId, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 927 | driveName](const boost::system::error_code& ec, |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 928 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 929 | if (ec) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 930 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 931 | messages::internalError(asyncResp->res); |
| 932 | return; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 935 | // Iterate over all retrieved ObjectPaths. |
| 936 | for (const auto& [path, connectionNames] : subtree) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 937 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 938 | sdbusplus::message::object_path objPath(path); |
| 939 | if (objPath.filename() != chassisId) |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 940 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 941 | continue; |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 942 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 943 | |
| 944 | if (connectionNames.empty()) |
| 945 | { |
| 946 | BMCWEB_LOG_ERROR("Got 0 Connection names"); |
| 947 | continue; |
| 948 | } |
| 949 | |
| 950 | dbus::utility::getAssociationEndPoints( |
| 951 | path + "/drive", |
| 952 | [asyncResp, chassisId, |
| 953 | driveName](const boost::system::error_code& ec3, |
| 954 | const dbus::utility::MapperEndPoints& resp) { |
| 955 | if (ec3) |
| 956 | { |
| 957 | return; // no drives = no failures |
| 958 | } |
| 959 | matchAndFillDrive(asyncResp, chassisId, driveName, |
| 960 | resp); |
| 961 | }); |
| 962 | break; |
| 963 | } |
| 964 | }); |
John Edward Broadbent | e56ed6b | 2022-04-26 13:40:59 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /** |
| 968 | * This URL will show the drive interface for the specific drive in the chassis |
| 969 | */ |
| 970 | inline void requestRoutesChassisDriveName(App& app) |
| 971 | { |
| 972 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Drives/<str>/") |
| 973 | .privileges(redfish::privileges::getChassis) |
| 974 | .methods(boost::beast::http::verb::get)( |
| 975 | std::bind_front(handleChassisDriveGet, std::ref(app))); |
| 976 | } |
| 977 | |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 978 | inline void getStorageControllerAsset( |
| 979 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 980 | const boost::system::error_code& ec, |
| 981 | const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 982 | propertiesList) |
| 983 | { |
| 984 | if (ec) |
| 985 | { |
| 986 | // this interface isn't necessary |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 987 | BMCWEB_LOG_DEBUG("Failed to get StorageControllerAsset"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | |
| 991 | const std::string* partNumber = nullptr; |
| 992 | const std::string* serialNumber = nullptr; |
| 993 | const std::string* manufacturer = nullptr; |
| 994 | const std::string* model = nullptr; |
| 995 | if (!sdbusplus::unpackPropertiesNoThrow( |
| 996 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 997 | partNumber, "SerialNumber", serialNumber, "Manufacturer", |
| 998 | manufacturer, "Model", model)) |
| 999 | { |
| 1000 | messages::internalError(asyncResp->res); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | if (partNumber != nullptr) |
| 1005 | { |
| 1006 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 1007 | } |
| 1008 | |
| 1009 | if (serialNumber != nullptr) |
| 1010 | { |
| 1011 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 1012 | } |
| 1013 | |
| 1014 | if (manufacturer != nullptr) |
| 1015 | { |
| 1016 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 1017 | } |
| 1018 | |
| 1019 | if (model != nullptr) |
| 1020 | { |
| 1021 | asyncResp->res.jsonValue["Model"] = *model; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | inline void populateStorageController( |
| 1026 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1027 | const std::string& controllerId, const std::string& connectionName, |
| 1028 | const std::string& path) |
| 1029 | { |
| 1030 | asyncResp->res.jsonValue["@odata.type"] = |
| 1031 | "#StorageController.v1_6_0.StorageController"; |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1032 | asyncResp->res.jsonValue["@odata.id"] = |
| 1033 | boost::urls::format("/redfish/v1/Systems/{}/Storage/1/Controllers/{}", |
| 1034 | BMCWEB_REDFISH_SYSTEM_URI_NAME, controllerId); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1035 | asyncResp->res.jsonValue["Name"] = controllerId; |
| 1036 | asyncResp->res.jsonValue["Id"] = controllerId; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 1037 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1038 | |
| 1039 | sdbusplus::asio::getProperty<bool>( |
| 1040 | *crow::connections::systemBus, connectionName, path, |
| 1041 | "xyz.openbmc_project.Inventory.Item", "Present", |
| 1042 | [asyncResp](const boost::system::error_code& ec, bool isPresent) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1043 | // this interface isn't necessary, only check it |
| 1044 | // if we get a good return |
| 1045 | if (ec) |
| 1046 | { |
| 1047 | BMCWEB_LOG_DEBUG("Failed to get Present property"); |
| 1048 | return; |
| 1049 | } |
| 1050 | if (!isPresent) |
| 1051 | { |
| 1052 | asyncResp->res.jsonValue["Status"]["State"] = |
| 1053 | resource::State::Absent; |
| 1054 | } |
| 1055 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1056 | |
| 1057 | sdbusplus::asio::getAllProperties( |
| 1058 | *crow::connections::systemBus, connectionName, path, |
| 1059 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 1060 | [asyncResp](const boost::system::error_code& ec, |
| 1061 | const std::vector< |
| 1062 | std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 1063 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1064 | getStorageControllerAsset(asyncResp, ec, propertiesList); |
| 1065 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | inline void getStorageControllerHandler( |
| 1069 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1070 | const std::string& controllerId, const boost::system::error_code& ec, |
| 1071 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 1072 | { |
| 1073 | if (ec || subtree.empty()) |
| 1074 | { |
| 1075 | // doesn't have to be there |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1076 | BMCWEB_LOG_DEBUG("Failed to handle StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | for (const auto& [path, interfaceDict] : subtree) |
| 1081 | { |
| 1082 | sdbusplus::message::object_path object(path); |
| 1083 | std::string id = object.filename(); |
| 1084 | if (id.empty()) |
| 1085 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1086 | BMCWEB_LOG_ERROR("Failed to find filename in {}", path); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1087 | return; |
| 1088 | } |
| 1089 | if (id != controllerId) |
| 1090 | { |
| 1091 | continue; |
| 1092 | } |
| 1093 | |
| 1094 | if (interfaceDict.size() != 1) |
| 1095 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1096 | BMCWEB_LOG_ERROR("Connection size {}, greater than 1", |
| 1097 | interfaceDict.size()); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1098 | messages::internalError(asyncResp->res); |
| 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | const std::string& connectionName = interfaceDict.front().first; |
| 1103 | populateStorageController(asyncResp, controllerId, connectionName, |
| 1104 | path); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | inline void populateStorageControllerCollection( |
| 1109 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1110 | const boost::system::error_code& ec, |
| 1111 | const dbus::utility::MapperGetSubTreePathsResponse& controllerList) |
| 1112 | { |
| 1113 | nlohmann::json::array_t members; |
| 1114 | if (ec || controllerList.empty()) |
| 1115 | { |
| 1116 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 1117 | asyncResp->res.jsonValue["Members@odata.count"] = 0; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1118 | BMCWEB_LOG_DEBUG("Failed to find any StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | for (const std::string& path : controllerList) |
| 1123 | { |
| 1124 | std::string id = sdbusplus::message::object_path(path).filename(); |
| 1125 | if (id.empty()) |
| 1126 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1127 | BMCWEB_LOG_ERROR("Failed to find filename in {}", path); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1128 | return; |
| 1129 | } |
| 1130 | nlohmann::json::object_t member; |
| 1131 | member["@odata.id"] = boost::urls::format( |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1132 | "/redfish/v1/Systems/{}/Storage/1/Controllers/{}", |
| 1133 | BMCWEB_REDFISH_SYSTEM_URI_NAME, id); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1134 | members.emplace_back(member); |
| 1135 | } |
| 1136 | asyncResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 1137 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 1138 | } |
| 1139 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1140 | inline void handleSystemsStorageControllerCollectionGet( |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1141 | App& app, const crow::Request& req, |
| 1142 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1143 | const std::string& systemName) |
| 1144 | { |
| 1145 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1146 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1147 | BMCWEB_LOG_DEBUG( |
| 1148 | "Failed to setup Redfish Route for StorageController Collection"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1149 | return; |
| 1150 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1151 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1152 | { |
| 1153 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1154 | systemName); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1155 | BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1156 | return; |
| 1157 | } |
| 1158 | |
| 1159 | asyncResp->res.jsonValue["@odata.type"] = |
| 1160 | "#StorageControllerCollection.StorageControllerCollection"; |
| 1161 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1162 | std::format("/redfish/v1/Systems/{}/Storage/1/Controllers", |
| 1163 | BMCWEB_REDFISH_SYSTEM_URI_NAME); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1164 | asyncResp->res.jsonValue["Name"] = "Storage Controller Collection"; |
| 1165 | |
| 1166 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1167 | "xyz.openbmc_project.Inventory.Item.StorageController"}; |
| 1168 | dbus::utility::getSubTreePaths( |
| 1169 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1170 | [asyncResp](const boost::system::error_code& ec, |
| 1171 | const dbus::utility::MapperGetSubTreePathsResponse& |
| 1172 | controllerList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1173 | populateStorageControllerCollection(asyncResp, ec, controllerList); |
| 1174 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1177 | inline void handleSystemsStorageControllerGet( |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1178 | App& app, const crow::Request& req, |
| 1179 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1180 | const std::string& systemName, const std::string& controllerId) |
| 1181 | { |
| 1182 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1183 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1184 | BMCWEB_LOG_DEBUG("Failed to setup Redfish Route for StorageController"); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1185 | return; |
| 1186 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 1187 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1188 | { |
| 1189 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 1190 | systemName); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1191 | BMCWEB_LOG_DEBUG("Failed to find ComputerSystem of {}", systemName); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1192 | return; |
| 1193 | } |
| 1194 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1195 | "xyz.openbmc_project.Inventory.Item.StorageController"}; |
| 1196 | dbus::utility::getSubTree( |
| 1197 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 1198 | [asyncResp, |
| 1199 | controllerId](const boost::system::error_code& ec, |
| 1200 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1201 | getStorageControllerHandler(asyncResp, controllerId, ec, subtree); |
| 1202 | }); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | inline void requestRoutesStorageControllerCollection(App& app) |
| 1206 | { |
| 1207 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/") |
| 1208 | .privileges(redfish::privileges::getStorageControllerCollection) |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1209 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 1210 | handleSystemsStorageControllerCollectionGet, std::ref(app))); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | inline void requestRoutesStorageController(App& app) |
| 1214 | { |
| 1215 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Storage/1/Controllers/<str>") |
| 1216 | .privileges(redfish::privileges::getStorageController) |
| 1217 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 36d5233 | 2023-06-09 13:18:40 -0700 | [diff] [blame] | 1218 | std::bind_front(handleSystemsStorageControllerGet, std::ref(app))); |
Willy Tu | 61b1eb2 | 2023-03-14 11:29:50 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 1221 | } // namespace redfish |