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