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