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