Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "app.hpp" |
| 4 | #include "dbus_utility.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 5 | #include "generated/enums/resource.hpp" |
Ed Tanous | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 6 | #include "query.hpp" |
| 7 | #include "registries/privilege_registry.hpp" |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 8 | #include "utils/collection.hpp" |
Lakshmi Yadlapati | 6177a30 | 2023-02-17 10:29:34 -0600 | [diff] [blame] | 9 | #include "utils/dbus_utils.hpp" |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 10 | #include "utils/json_utils.hpp" |
| 11 | |
| 12 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 13 | #include <boost/url/format.hpp> |
Gunnar Mills | f05e916 | 2023-02-16 20:23:30 -0600 | [diff] [blame] | 14 | #include <sdbusplus/asio/property.hpp> |
Lakshmi Yadlapati | 6177a30 | 2023-02-17 10:29:34 -0600 | [diff] [blame] | 15 | #include <sdbusplus/unpack_properties.hpp> |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 16 | |
| 17 | #include <array> |
| 18 | #include <functional> |
| 19 | #include <memory> |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 20 | #include <optional> |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <string_view> |
| 23 | |
| 24 | namespace redfish |
| 25 | { |
| 26 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 27 | inline void getFabricAdapterLocation( |
| 28 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 29 | const std::string& serviceName, const std::string& fabricAdapterPath) |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 30 | { |
| 31 | sdbusplus::asio::getProperty<std::string>( |
| 32 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 33 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 34 | [asyncResp](const boost::system::error_code& ec, |
| 35 | const std::string& property) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 36 | if (ec) |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 37 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 38 | if (ec.value() != EBADR) |
| 39 | { |
| 40 | BMCWEB_LOG_ERROR("DBUS response error for Location"); |
| 41 | messages::internalError(asyncResp->res); |
| 42 | } |
| 43 | return; |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 44 | } |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 45 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 46 | asyncResp->res |
| 47 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 48 | property; |
| 49 | }); |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 50 | } |
| 51 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 52 | inline void getFabricAdapterAsset( |
| 53 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 54 | const std::string& serviceName, const std::string& fabricAdapterPath) |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 55 | { |
| 56 | sdbusplus::asio::getAllProperties( |
| 57 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 58 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 59 | [fabricAdapterPath, asyncResp{asyncResp}]( |
| 60 | const boost::system::error_code& ec, |
| 61 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 62 | if (ec) |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 63 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 64 | if (ec.value() != EBADR) |
| 65 | { |
| 66 | BMCWEB_LOG_ERROR("DBUS response error for Properties"); |
| 67 | messages::internalError(asyncResp->res); |
| 68 | } |
| 69 | return; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 70 | } |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 71 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 72 | const std::string* serialNumber = nullptr; |
| 73 | const std::string* model = nullptr; |
| 74 | const std::string* partNumber = nullptr; |
| 75 | const std::string* sparePartNumber = nullptr; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 76 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 77 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 78 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 79 | "SerialNumber", serialNumber, "Model", model, "PartNumber", |
| 80 | partNumber, "SparePartNumber", sparePartNumber); |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 81 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 82 | if (!success) |
| 83 | { |
| 84 | messages::internalError(asyncResp->res); |
| 85 | return; |
| 86 | } |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 87 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 88 | if (serialNumber != nullptr) |
| 89 | { |
| 90 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 91 | } |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 92 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 93 | if (model != nullptr) |
| 94 | { |
| 95 | asyncResp->res.jsonValue["Model"] = *model; |
| 96 | } |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 97 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 98 | if (partNumber != nullptr) |
| 99 | { |
| 100 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 101 | } |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 102 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 103 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 104 | { |
| 105 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
| 106 | } |
| 107 | }); |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 108 | } |
| 109 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 110 | inline void getFabricAdapterState( |
| 111 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 112 | const std::string& serviceName, const std::string& fabricAdapterPath) |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 113 | { |
| 114 | sdbusplus::asio::getProperty<bool>( |
| 115 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 116 | "xyz.openbmc_project.Inventory.Item", "Present", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 117 | [asyncResp](const boost::system::error_code& ec, const bool present) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 118 | if (ec) |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 119 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 120 | if (ec.value() != EBADR) |
| 121 | { |
| 122 | BMCWEB_LOG_ERROR("DBUS response error for State"); |
| 123 | messages::internalError(asyncResp->res); |
| 124 | } |
| 125 | return; |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 126 | } |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 127 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 128 | if (!present) |
| 129 | { |
| 130 | asyncResp->res.jsonValue["Status"]["State"] = |
| 131 | resource::State::Absent; |
| 132 | } |
| 133 | }); |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 136 | inline void getFabricAdapterHealth( |
| 137 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 138 | const std::string& serviceName, const std::string& fabricAdapterPath) |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 139 | { |
| 140 | sdbusplus::asio::getProperty<bool>( |
| 141 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 142 | "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 143 | [asyncResp](const boost::system::error_code& ec, |
| 144 | const bool functional) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 145 | if (ec) |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 146 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 147 | if (ec.value() != EBADR) |
| 148 | { |
| 149 | BMCWEB_LOG_ERROR("DBUS response error for Health"); |
| 150 | messages::internalError(asyncResp->res); |
| 151 | } |
| 152 | return; |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 153 | } |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 154 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 155 | if (!functional) |
| 156 | { |
| 157 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 158 | resource::Health::Critical; |
| 159 | } |
| 160 | }); |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 161 | } |
| 162 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 163 | inline void doAdapterGet( |
| 164 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 165 | const std::string& systemName, const std::string& adapterId, |
| 166 | const std::string& fabricAdapterPath, const std::string& serviceName) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 167 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 168 | asyncResp->res.addHeader( |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 169 | boost::beast::http::field::link, |
| 170 | "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 171 | asyncResp->res.jsonValue["@odata.type"] = |
| 172 | "#FabricAdapter.v1_4_0.FabricAdapter"; |
| 173 | asyncResp->res.jsonValue["Name"] = "Fabric Adapter"; |
| 174 | asyncResp->res.jsonValue["Id"] = adapterId; |
| 175 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 176 | "/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId); |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 177 | |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 178 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
| 179 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 180 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 181 | getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath); |
| 182 | getFabricAdapterAsset(asyncResp, serviceName, fabricAdapterPath); |
| 183 | getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath); |
| 184 | getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 185 | } |
| 186 | |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 187 | inline void afterGetValidFabricAdapterPath( |
| 188 | const std::string& adapterId, |
| 189 | std::function<void(const boost::system::error_code&, |
| 190 | const std::string& fabricAdapterPath, |
| 191 | const std::string& serviceName)>& callback, |
| 192 | const boost::system::error_code& ec, |
| 193 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 194 | { |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 195 | std::string fabricAdapterPath; |
| 196 | std::string serviceName; |
| 197 | if (ec) |
| 198 | { |
| 199 | callback(ec, fabricAdapterPath, serviceName); |
| 200 | return; |
| 201 | } |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 202 | |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 203 | for (const auto& [adapterPath, serviceMap] : subtree) |
| 204 | { |
| 205 | std::string fabricAdapterName = |
| 206 | sdbusplus::message::object_path(adapterPath).filename(); |
| 207 | if (fabricAdapterName == adapterId) |
| 208 | { |
| 209 | fabricAdapterPath = adapterPath; |
| 210 | serviceName = serviceMap.begin()->first; |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | callback(ec, fabricAdapterPath, serviceName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | inline void getValidFabricAdapterPath( |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 218 | const std::string& adapterId, |
| 219 | std::function<void(const boost::system::error_code& ec, |
| 220 | const std::string& fabricAdapterPath, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 221 | const std::string& serviceName)>&& callback) |
| 222 | { |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 223 | constexpr std::array<std::string_view, 1> interfaces{ |
| 224 | "xyz.openbmc_project.Inventory.Item.FabricAdapter"}; |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 225 | dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces, |
| 226 | std::bind_front(afterGetValidFabricAdapterPath, |
| 227 | adapterId, std::move(callback))); |
| 228 | } |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 229 | |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 230 | inline void afterHandleFabricAdapterGet( |
| 231 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 232 | const std::string& systemName, const std::string& adapterId, |
| 233 | const boost::system::error_code& ec, const std::string& fabricAdapterPath, |
| 234 | const std::string& serviceName) |
| 235 | { |
| 236 | if (ec) |
| 237 | { |
| 238 | if (ec.value() == boost::system::errc::io_error) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 239 | { |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 240 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", |
| 241 | adapterId); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 242 | return; |
| 243 | } |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 244 | |
| 245 | BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value()); |
| 246 | messages::internalError(asyncResp->res); |
| 247 | return; |
| 248 | } |
| 249 | if (fabricAdapterPath.empty() || serviceName.empty()) |
| 250 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 251 | BMCWEB_LOG_WARNING("Adapter not found"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 252 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId); |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 253 | return; |
| 254 | } |
| 255 | doAdapterGet(asyncResp, systemName, adapterId, fabricAdapterPath, |
| 256 | serviceName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 257 | } |
| 258 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 259 | inline void handleFabricAdapterGet( |
| 260 | App& app, const crow::Request& req, |
| 261 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 262 | const std::string& systemName, const std::string& adapterId) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 263 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 264 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 265 | { |
| 266 | return; |
| 267 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 268 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 269 | { |
| 270 | // Option currently returns no systems. TBD |
| 271 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 272 | systemName); |
| 273 | return; |
| 274 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 275 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 276 | { |
| 277 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 278 | systemName); |
| 279 | return; |
| 280 | } |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 281 | getValidFabricAdapterPath( |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 282 | adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp, |
| 283 | systemName, adapterId)); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | inline void handleFabricAdapterCollectionGet( |
| 287 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 288 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 289 | const std::string& systemName) |
| 290 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 291 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 292 | { |
| 293 | return; |
| 294 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 295 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 296 | { |
| 297 | // Option currently returns no systems. TBD |
| 298 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 299 | systemName); |
| 300 | return; |
| 301 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 302 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 303 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 304 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 305 | systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 306 | return; |
| 307 | } |
| 308 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 309 | asyncResp->res.addHeader( |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 310 | boost::beast::http::field::link, |
| 311 | "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 312 | asyncResp->res.jsonValue["@odata.type"] = |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 313 | "#FabricAdapterCollection.FabricAdapterCollection"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 314 | asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection"; |
| 315 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 316 | "/redfish/v1/Systems/{}/FabricAdapters", systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 317 | |
| 318 | constexpr std::array<std::string_view, 1> interfaces{ |
| 319 | "xyz.openbmc_project.Inventory.Item.FabricAdapter"}; |
| 320 | collection_util::getCollectionMembers( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 321 | asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 322 | boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", |
| 323 | BMCWEB_REDFISH_SYSTEM_URI_NAME), |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 324 | interfaces, "/xyz/openbmc_project/inventory"); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | inline void handleFabricAdapterCollectionHead( |
| 328 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 329 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 330 | const std::string& systemName) |
| 331 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 332 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 333 | { |
| 334 | return; |
| 335 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 336 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 337 | { |
| 338 | // Option currently returns no systems. TBD |
| 339 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 340 | systemName); |
| 341 | return; |
| 342 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 343 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 344 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 345 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 346 | systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 347 | return; |
| 348 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 349 | asyncResp->res.addHeader( |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 350 | boost::beast::http::field::link, |
| 351 | "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby"); |
| 352 | } |
| 353 | |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 354 | inline void afterHandleFabricAdapterHead( |
| 355 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 356 | const std::string& adapterId, const boost::system::error_code& ec, |
| 357 | const std::string& fabricAdapterPath, const std::string& serviceName) |
| 358 | { |
| 359 | if (ec) |
| 360 | { |
| 361 | if (ec.value() == boost::system::errc::io_error) |
| 362 | { |
| 363 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", |
| 364 | adapterId); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value()); |
| 369 | messages::internalError(asyncResp->res); |
| 370 | return; |
| 371 | } |
| 372 | if (fabricAdapterPath.empty() || serviceName.empty()) |
| 373 | { |
| 374 | BMCWEB_LOG_WARNING("Adapter not found"); |
| 375 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId); |
| 376 | return; |
| 377 | } |
| 378 | asyncResp->res.addHeader( |
| 379 | boost::beast::http::field::link, |
| 380 | "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby"); |
| 381 | } |
| 382 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 383 | inline void handleFabricAdapterHead( |
| 384 | crow::App& app, const crow::Request& req, |
| 385 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 386 | const std::string& systemName, const std::string& adapterId) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 387 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 388 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 389 | { |
| 390 | return; |
| 391 | } |
| 392 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 393 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 394 | { |
| 395 | // Option currently returns no systems. TBD |
| 396 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 397 | systemName); |
| 398 | return; |
| 399 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 400 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 401 | { |
| 402 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 403 | systemName); |
| 404 | return; |
| 405 | } |
| 406 | getValidFabricAdapterPath( |
| 407 | adapterId, |
| 408 | std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId)); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | inline void requestRoutesFabricAdapterCollection(App& app) |
| 412 | { |
| 413 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/") |
| 414 | .privileges(redfish::privileges::getFabricAdapterCollection) |
| 415 | .methods(boost::beast::http::verb::get)( |
| 416 | std::bind_front(handleFabricAdapterCollectionGet, std::ref(app))); |
| 417 | |
| 418 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/") |
| 419 | .privileges(redfish::privileges::headFabricAdapterCollection) |
| 420 | .methods(boost::beast::http::verb::head)( |
| 421 | std::bind_front(handleFabricAdapterCollectionHead, std::ref(app))); |
| 422 | } |
| 423 | |
| 424 | inline void requestRoutesFabricAdapters(App& app) |
| 425 | { |
| 426 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/") |
| 427 | .privileges(redfish::privileges::getFabricAdapter) |
| 428 | .methods(boost::beast::http::verb::get)( |
| 429 | std::bind_front(handleFabricAdapterGet, std::ref(app))); |
| 430 | |
| 431 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/") |
| 432 | .privileges(redfish::privileges::headFabricAdapter) |
| 433 | .methods(boost::beast::http::verb::head)( |
| 434 | std::bind_front(handleFabricAdapterHead, std::ref(app))); |
| 435 | } |
| 436 | } // namespace redfish |