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 | a8e884f | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 5 | #include "query.hpp" |
| 6 | #include "registries/privilege_registry.hpp" |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 7 | #include "utils/collection.hpp" |
Lakshmi Yadlapati | 6177a30 | 2023-02-17 10:29:34 -0600 | [diff] [blame] | 8 | #include "utils/dbus_utils.hpp" |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 9 | #include "utils/json_utils.hpp" |
| 10 | |
| 11 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 12 | #include <boost/url/format.hpp> |
Gunnar Mills | f05e916 | 2023-02-16 20:23:30 -0600 | [diff] [blame] | 13 | #include <sdbusplus/asio/property.hpp> |
Lakshmi Yadlapati | 6177a30 | 2023-02-17 10:29:34 -0600 | [diff] [blame] | 14 | #include <sdbusplus/unpack_properties.hpp> |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 15 | |
| 16 | #include <array> |
| 17 | #include <functional> |
| 18 | #include <memory> |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 19 | #include <optional> |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <string_view> |
| 22 | |
| 23 | namespace redfish |
| 24 | { |
| 25 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 26 | inline void getFabricAdapterLocation( |
| 27 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 28 | const std::string& serviceName, const std::string& fabricAdapterPath) |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 29 | { |
| 30 | sdbusplus::asio::getProperty<std::string>( |
| 31 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 32 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 33 | [asyncResp](const boost::system::error_code& ec, |
| 34 | const std::string& property) { |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 35 | if (ec) |
| 36 | { |
| 37 | if (ec.value() != EBADR) |
| 38 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 39 | BMCWEB_LOG_ERROR("DBUS response error for Location"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 40 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 41 | } |
| 42 | return; |
| 43 | } |
| 44 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 45 | asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 46 | property; |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 47 | }); |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 48 | } |
| 49 | |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 50 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 51 | getFabricAdapterAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 52 | const std::string& serviceName, |
| 53 | const std::string& fabricAdapterPath) |
| 54 | { |
| 55 | sdbusplus::asio::getAllProperties( |
| 56 | *crow::connections::systemBus, serviceName, fabricAdapterPath, |
| 57 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 58 | [fabricAdapterPath, asyncResp{asyncResp}]( |
| 59 | const boost::system::error_code& ec, |
| 60 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 61 | if (ec) |
| 62 | { |
| 63 | if (ec.value() != EBADR) |
| 64 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 65 | BMCWEB_LOG_ERROR("DBUS response error for Properties"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 66 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 67 | } |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | const std::string* serialNumber = nullptr; |
| 72 | const std::string* model = nullptr; |
| 73 | const std::string* partNumber = nullptr; |
| 74 | const std::string* sparePartNumber = nullptr; |
| 75 | |
| 76 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 77 | dbus_utils::UnpackErrorPrinter(), propertiesList, "SerialNumber", |
| 78 | serialNumber, "Model", model, "PartNumber", partNumber, |
| 79 | "SparePartNumber", sparePartNumber); |
| 80 | |
| 81 | if (!success) |
| 82 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 83 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
| 87 | if (serialNumber != nullptr) |
| 88 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 89 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | if (model != nullptr) |
| 93 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 94 | asyncResp->res.jsonValue["Model"] = *model; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | if (partNumber != nullptr) |
| 98 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 99 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 103 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 104 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 105 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 106 | }); |
Lakshmi Yadlapati | 6369421 | 2023-01-27 16:35:22 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 109 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 110 | getFabricAdapterState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 111 | const std::string& serviceName, |
| 112 | const std::string& fabricAdapterPath) |
| 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) { |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 118 | if (ec) |
| 119 | { |
| 120 | if (ec.value() != EBADR) |
| 121 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 122 | BMCWEB_LOG_ERROR("DBUS response error for State"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 123 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 124 | } |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | if (!present) |
| 129 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 130 | asyncResp->res.jsonValue["Status"]["State"] = "Absent"; |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 131 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 132 | }); |
Lakshmi Yadlapati | cd7af44 | 2023-01-27 17:31:40 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 135 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 136 | getFabricAdapterHealth(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 137 | const std::string& serviceName, |
| 138 | const std::string& fabricAdapterPath) |
| 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) { |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 145 | if (ec) |
| 146 | { |
| 147 | if (ec.value() != EBADR) |
| 148 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 149 | BMCWEB_LOG_ERROR("DBUS response error for Health"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 150 | messages::internalError(asyncResp->res); |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 151 | } |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | if (!functional) |
| 156 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 157 | asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 158 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 159 | }); |
Lakshmi Yadlapati | 7da847b | 2023-01-27 17:53:18 -0600 | [diff] [blame] | 160 | } |
| 161 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 162 | inline void doAdapterGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 163 | const std::string& systemName, |
Lakshmi Yadlapati | 53ffeca | 2023-01-27 15:12:23 -0600 | [diff] [blame] | 164 | const std::string& adapterId, |
| 165 | const std::string& fabricAdapterPath, |
| 166 | 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 | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 178 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 179 | asyncResp->res.jsonValue["Status"]["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 | |
| 259 | inline void |
| 260 | handleFabricAdapterGet(App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 261 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 262 | const std::string& systemName, |
| 263 | const std::string& adapterId) |
| 264 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 265 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 266 | { |
| 267 | return; |
| 268 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 269 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 270 | { |
| 271 | // Option currently returns no systems. TBD |
| 272 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 273 | systemName); |
| 274 | return; |
| 275 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 276 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 277 | { |
| 278 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 279 | systemName); |
| 280 | return; |
| 281 | } |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 282 | getValidFabricAdapterPath( |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 283 | adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp, |
| 284 | systemName, adapterId)); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | inline void handleFabricAdapterCollectionGet( |
| 288 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 289 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 290 | const std::string& systemName) |
| 291 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 292 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 293 | { |
| 294 | return; |
| 295 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 296 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 297 | { |
| 298 | // Option currently returns no systems. TBD |
| 299 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 300 | systemName); |
| 301 | return; |
| 302 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 303 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 304 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 305 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 306 | systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 310 | asyncResp->res.addHeader( |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 311 | boost::beast::http::field::link, |
| 312 | "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 313 | asyncResp->res.jsonValue["@odata.type"] = |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 314 | "#FabricAdapterCollection.FabricAdapterCollection"; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 315 | asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection"; |
| 316 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 317 | "/redfish/v1/Systems/{}/FabricAdapters", systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 318 | |
| 319 | constexpr std::array<std::string_view, 1> interfaces{ |
| 320 | "xyz.openbmc_project.Inventory.Item.FabricAdapter"}; |
| 321 | collection_util::getCollectionMembers( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 322 | asyncResp, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 323 | boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", |
| 324 | BMCWEB_REDFISH_SYSTEM_URI_NAME), |
Lakshmi Yadlapati | 36b5f1e | 2023-09-26 23:53:28 -0500 | [diff] [blame] | 325 | interfaces, "/xyz/openbmc_project/inventory"); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | inline void handleFabricAdapterCollectionHead( |
| 329 | crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 330 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 331 | const std::string& systemName) |
| 332 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 333 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 334 | { |
| 335 | return; |
| 336 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 337 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 338 | { |
| 339 | // Option currently returns no systems. TBD |
| 340 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 341 | systemName); |
| 342 | return; |
| 343 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 344 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 345 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 346 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 347 | systemName); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 348 | return; |
| 349 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 350 | asyncResp->res.addHeader( |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 351 | boost::beast::http::field::link, |
| 352 | "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby"); |
| 353 | } |
| 354 | |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 355 | inline void afterHandleFabricAdapterHead( |
| 356 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 357 | const std::string& adapterId, const boost::system::error_code& ec, |
| 358 | const std::string& fabricAdapterPath, const std::string& serviceName) |
| 359 | { |
| 360 | if (ec) |
| 361 | { |
| 362 | if (ec.value() == boost::system::errc::io_error) |
| 363 | { |
| 364 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", |
| 365 | adapterId); |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | BMCWEB_LOG_ERROR("DBus method call failed with error {}", ec.value()); |
| 370 | messages::internalError(asyncResp->res); |
| 371 | return; |
| 372 | } |
| 373 | if (fabricAdapterPath.empty() || serviceName.empty()) |
| 374 | { |
| 375 | BMCWEB_LOG_WARNING("Adapter not found"); |
| 376 | messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId); |
| 377 | return; |
| 378 | } |
| 379 | asyncResp->res.addHeader( |
| 380 | boost::beast::http::field::link, |
| 381 | "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby"); |
| 382 | } |
| 383 | |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 384 | inline void |
| 385 | handleFabricAdapterHead(crow::App& app, const crow::Request& req, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 386 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 387 | const std::string& systemName, |
| 388 | const std::string& adapterId) |
| 389 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 390 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 391 | { |
| 392 | return; |
| 393 | } |
| 394 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 395 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 396 | { |
| 397 | // Option currently returns no systems. TBD |
| 398 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 399 | systemName); |
| 400 | return; |
| 401 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame^] | 402 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Myung Bae | 78c9020 | 2024-02-19 13:39:56 -0500 | [diff] [blame] | 403 | { |
| 404 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 405 | systemName); |
| 406 | return; |
| 407 | } |
| 408 | getValidFabricAdapterPath( |
| 409 | adapterId, |
| 410 | std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId)); |
Sunny Srivastava | 3179105 | 2021-03-12 10:39:16 -0600 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | inline void requestRoutesFabricAdapterCollection(App& app) |
| 414 | { |
| 415 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/") |
| 416 | .privileges(redfish::privileges::getFabricAdapterCollection) |
| 417 | .methods(boost::beast::http::verb::get)( |
| 418 | std::bind_front(handleFabricAdapterCollectionGet, std::ref(app))); |
| 419 | |
| 420 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/") |
| 421 | .privileges(redfish::privileges::headFabricAdapterCollection) |
| 422 | .methods(boost::beast::http::verb::head)( |
| 423 | std::bind_front(handleFabricAdapterCollectionHead, std::ref(app))); |
| 424 | } |
| 425 | |
| 426 | inline void requestRoutesFabricAdapters(App& app) |
| 427 | { |
| 428 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/") |
| 429 | .privileges(redfish::privileges::getFabricAdapter) |
| 430 | .methods(boost::beast::http::verb::get)( |
| 431 | std::bind_front(handleFabricAdapterGet, std::ref(app))); |
| 432 | |
| 433 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/FabricAdapters/<str>/") |
| 434 | .privileges(redfish::privileges::headFabricAdapter) |
| 435 | .methods(boost::beast::http::verb::head)( |
| 436 | std::bind_front(handleFabricAdapterHead, std::ref(app))); |
| 437 | } |
| 438 | } // namespace redfish |