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