blob: 7d20302d81fb03d69fa08730b5302e11c28eb095 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Sunny Srivastava31791052021-03-12 10:39:16 -06003#pragma once
4
Ed Tanousd7857202025-01-28 15:32:26 -08005#include "bmcweb_config.h"
6
Sunny Srivastava31791052021-03-12 10:39:16 -06007#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08008#include "async_resp.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -06009#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080010#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070011#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "http_request.hpp"
Myung Baebe1384e2024-08-20 12:07:10 -050013#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080014#include "logging.hpp"
Ed Tanousa8e884f2023-01-13 17:40:03 -080015#include "query.hpp"
16#include "registries/privilege_registry.hpp"
Myung Baef7e62c12025-09-07 14:02:08 -050017#include "utils/asset_utils.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -060018#include "utils/collection.hpp"
Lakshmi Yadlapati6177a302023-02-17 10:29:34 -060019#include "utils/dbus_utils.hpp"
Myung Baebe1384e2024-08-20 12:07:10 -050020#include "utils/json_utils.hpp"
Sunny Srivastava31791052021-03-12 10:39:16 -060021
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <asm-generic/errno.h>
23
24#include <boost/beast/http/field.hpp>
25#include <boost/beast/http/verb.hpp>
Sunny Srivastava31791052021-03-12 10:39:16 -060026#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070027#include <boost/url/format.hpp>
Lakshmi Yadlapati6177a302023-02-17 10:29:34 -060028#include <sdbusplus/unpack_properties.hpp>
Sunny Srivastava31791052021-03-12 10:39:16 -060029
30#include <array>
31#include <functional>
32#include <memory>
Myung Baebe1384e2024-08-20 12:07:10 -050033#include <optional>
Sunny Srivastava31791052021-03-12 10:39:16 -060034#include <string>
35#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080036#include <utility>
Sunny Srivastava31791052021-03-12 10:39:16 -060037
38namespace redfish
39{
40
Ed Tanousac106bf2023-06-07 09:24:59 -070041inline void getFabricAdapterLocation(
42 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
43 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060044{
Ed Tanousdeae6a72024-11-11 21:58:57 -080045 dbus::utility::getProperty<std::string>(
46 serviceName, fabricAdapterPath,
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060047 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanousac106bf2023-06-07 09:24:59 -070048 [asyncResp](const boost::system::error_code& ec,
49 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040050 if (ec)
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060051 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040052 if (ec.value() != EBADR)
53 {
54 BMCWEB_LOG_ERROR("DBUS response error for Location");
55 messages::internalError(asyncResp->res);
56 }
57 return;
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060058 }
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060059
Patrick Williamsbd79bce2024-08-16 15:22:20 -040060 asyncResp->res
61 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
62 property;
63 });
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -060064}
65
Patrick Williamsbd79bce2024-08-16 15:22:20 -040066inline void getFabricAdapterState(
67 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
68 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -060069{
Ed Tanousdeae6a72024-11-11 21:58:57 -080070 dbus::utility::getProperty<bool>(
71 serviceName, fabricAdapterPath, "xyz.openbmc_project.Inventory.Item",
72 "Present",
Ed Tanousac106bf2023-06-07 09:24:59 -070073 [asyncResp](const boost::system::error_code& ec, const bool present) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040074 if (ec)
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -060075 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040076 if (ec.value() != EBADR)
77 {
78 BMCWEB_LOG_ERROR("DBUS response error for State");
79 messages::internalError(asyncResp->res);
80 }
81 return;
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -060082 }
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -060083
Patrick Williamsbd79bce2024-08-16 15:22:20 -040084 if (!present)
85 {
86 asyncResp->res.jsonValue["Status"]["State"] =
87 resource::State::Absent;
88 }
89 });
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -060090}
91
Patrick Williamsbd79bce2024-08-16 15:22:20 -040092inline void getFabricAdapterHealth(
93 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
94 const std::string& serviceName, const std::string& fabricAdapterPath)
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -060095{
Ed Tanousdeae6a72024-11-11 21:58:57 -080096 dbus::utility::getProperty<bool>(
97 serviceName, fabricAdapterPath,
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -060098 "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
Ed Tanousac106bf2023-06-07 09:24:59 -070099 [asyncResp](const boost::system::error_code& ec,
100 const bool functional) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400101 if (ec)
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600102 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400103 if (ec.value() != EBADR)
104 {
105 BMCWEB_LOG_ERROR("DBUS response error for Health");
106 messages::internalError(asyncResp->res);
107 }
108 return;
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600109 }
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600110
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400111 if (!functional)
112 {
113 asyncResp->res.jsonValue["Status"]["Health"] =
114 resource::Health::Critical;
115 }
116 });
Lakshmi Yadlapati7da847b2023-01-27 17:53:18 -0600117}
118
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400119inline 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 Srivastava31791052021-03-12 10:39:16 -0600123{
Ed Tanousac106bf2023-06-07 09:24:59 -0700124 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600125 boost::beast::http::field::link,
126 "</redfish/v1/JsonSchemas/FabricAdapter/FabricAdapter.json>; rel=describedby");
Ed Tanousac106bf2023-06-07 09:24:59 -0700127 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 Tanousef4c65b2023-04-24 15:28:50 -0700132 "/redfish/v1/Systems/{}/FabricAdapters/{}", systemName, adapterId);
Lakshmi Yadlapati53ffeca2023-01-27 15:12:23 -0600133
Ed Tanous539d8c62024-06-19 14:38:27 -0700134 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
135 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
Lakshmi Yadlapaticd7af442023-01-27 17:31:40 -0600136
George Liu37937d52023-02-21 18:02:26 +0800137 asyncResp->res.jsonValue["Ports"]["@odata.id"] =
138 boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters/{}/Ports",
139 systemName, adapterId);
140
Ed Tanousac106bf2023-06-07 09:24:59 -0700141 getFabricAdapterLocation(asyncResp, serviceName, fabricAdapterPath);
Myung Baef7e62c12025-09-07 14:02:08 -0500142 asset_utils::getAssetInfo(asyncResp, serviceName, fabricAdapterPath,
143 ""_json_pointer, true);
Ed Tanousac106bf2023-06-07 09:24:59 -0700144 getFabricAdapterState(asyncResp, serviceName, fabricAdapterPath);
145 getFabricAdapterHealth(asyncResp, serviceName, fabricAdapterPath);
Myung Baebe1384e2024-08-20 12:07:10 -0500146 getLocationIndicatorActive(asyncResp, fabricAdapterPath);
Sunny Srivastava31791052021-03-12 10:39:16 -0600147}
148
Myung Bae78c90202024-02-19 13:39:56 -0500149inline 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 Srivastava31791052021-03-12 10:39:16 -0600156{
Myung Bae78c90202024-02-19 13:39:56 -0500157 std::string fabricAdapterPath;
158 std::string serviceName;
159 if (ec)
160 {
161 callback(ec, fabricAdapterPath, serviceName);
162 return;
163 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600164
Myung Bae78c90202024-02-19 13:39:56 -0500165 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 Srivastava31791052021-03-12 10:39:16 -0600177}
178
179inline void getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500180 const std::string& adapterId,
181 std::function<void(const boost::system::error_code& ec,
182 const std::string& fabricAdapterPath,
Sunny Srivastava31791052021-03-12 10:39:16 -0600183 const std::string& serviceName)>&& callback)
184{
Sunny Srivastava31791052021-03-12 10:39:16 -0600185 constexpr std::array<std::string_view, 1> interfaces{
186 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
Myung Bae78c90202024-02-19 13:39:56 -0500187 dbus::utility::getSubTree("/xyz/openbmc_project/inventory", 0, interfaces,
188 std::bind_front(afterGetValidFabricAdapterPath,
189 adapterId, std::move(callback)));
190}
Sunny Srivastava31791052021-03-12 10:39:16 -0600191
Myung Bae78c90202024-02-19 13:39:56 -0500192inline 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 Srivastava31791052021-03-12 10:39:16 -0600201 {
Myung Bae78c90202024-02-19 13:39:56 -0500202 messages::resourceNotFound(asyncResp->res, "FabricAdapter",
203 adapterId);
Sunny Srivastava31791052021-03-12 10:39:16 -0600204 return;
205 }
Myung Bae78c90202024-02-19 13:39:56 -0500206
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 Tanous62598e32023-07-17 17:06:25 -0700213 BMCWEB_LOG_WARNING("Adapter not found");
Ed Tanousac106bf2023-06-07 09:24:59 -0700214 messages::resourceNotFound(asyncResp->res, "FabricAdapter", adapterId);
Myung Bae78c90202024-02-19 13:39:56 -0500215 return;
216 }
217 doAdapterGet(asyncResp, systemName, adapterId, fabricAdapterPath,
218 serviceName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600219}
220
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400221inline 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 Srivastava31791052021-03-12 10:39:16 -0600225{
Ed Tanousac106bf2023-06-07 09:24:59 -0700226 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600227 {
228 return;
229 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700230 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800231 {
232 // Option currently returns no systems. TBD
233 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
234 systemName);
235 return;
236 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700237 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500238 {
239 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
240 systemName);
241 return;
242 }
Sunny Srivastava31791052021-03-12 10:39:16 -0600243 getValidFabricAdapterPath(
Myung Bae78c90202024-02-19 13:39:56 -0500244 adapterId, std::bind_front(afterHandleFabricAdapterGet, asyncResp,
245 systemName, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600246}
247
Myung Baebe1384e2024-08-20 12:07:10 -0500248inline 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
281inline 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 Srivastava31791052021-03-12 10:39:16 -0600318inline void handleFabricAdapterCollectionGet(
319 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700320 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600321 const std::string& systemName)
322{
Ed Tanousac106bf2023-06-07 09:24:59 -0700323 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600324 {
325 return;
326 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700327 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800328 {
329 // Option currently returns no systems. TBD
330 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
331 systemName);
332 return;
333 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700334 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600335 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700336 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
337 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600338 return;
339 }
340
Ed Tanousac106bf2023-06-07 09:24:59 -0700341 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600342 boost::beast::http::field::link,
343 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
Ed Tanousac106bf2023-06-07 09:24:59 -0700344 asyncResp->res.jsonValue["@odata.type"] =
Sunny Srivastava31791052021-03-12 10:39:16 -0600345 "#FabricAdapterCollection.FabricAdapterCollection";
Ed Tanousac106bf2023-06-07 09:24:59 -0700346 asyncResp->res.jsonValue["Name"] = "Fabric Adapter Collection";
347 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
Ed Tanousef4c65b2023-04-24 15:28:50 -0700348 "/redfish/v1/Systems/{}/FabricAdapters", systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600349
350 constexpr std::array<std::string_view, 1> interfaces{
351 "xyz.openbmc_project.Inventory.Item.FabricAdapter"};
352 collection_util::getCollectionMembers(
Ed Tanousac106bf2023-06-07 09:24:59 -0700353 asyncResp,
Ed Tanous253f11b2024-05-16 09:38:31 -0700354 boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters",
355 BMCWEB_REDFISH_SYSTEM_URI_NAME),
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500356 interfaces, "/xyz/openbmc_project/inventory");
Sunny Srivastava31791052021-03-12 10:39:16 -0600357}
358
359inline void handleFabricAdapterCollectionHead(
360 crow::App& app, const crow::Request& req,
Ed Tanousac106bf2023-06-07 09:24:59 -0700361 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Sunny Srivastava31791052021-03-12 10:39:16 -0600362 const std::string& systemName)
363{
Ed Tanousac106bf2023-06-07 09:24:59 -0700364 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600365 {
366 return;
367 }
Ed Tanous25b54db2024-04-17 15:40:31 -0700368 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800369 {
370 // Option currently returns no systems. TBD
371 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
372 systemName);
373 return;
374 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700375 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Sunny Srivastava31791052021-03-12 10:39:16 -0600376 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700377 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
378 systemName);
Sunny Srivastava31791052021-03-12 10:39:16 -0600379 return;
380 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700381 asyncResp->res.addHeader(
Sunny Srivastava31791052021-03-12 10:39:16 -0600382 boost::beast::http::field::link,
383 "</redfish/v1/JsonSchemas/FabricAdapterCollection/FabricAdapterCollection.json>; rel=describedby");
384}
385
Myung Bae78c90202024-02-19 13:39:56 -0500386inline 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 Williamsbd79bce2024-08-16 15:22:20 -0400415inline 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 Srivastava31791052021-03-12 10:39:16 -0600419{
Ed Tanousac106bf2023-06-07 09:24:59 -0700420 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Sunny Srivastava31791052021-03-12 10:39:16 -0600421 {
422 return;
423 }
424
Ed Tanous25b54db2024-04-17 15:40:31 -0700425 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -0800426 {
427 // Option currently returns no systems. TBD
428 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
429 systemName);
430 return;
431 }
Ed Tanous253f11b2024-05-16 09:38:31 -0700432 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Myung Bae78c90202024-02-19 13:39:56 -0500433 {
434 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
435 systemName);
436 return;
437 }
438 getValidFabricAdapterPath(
439 adapterId,
440 std::bind_front(afterHandleFabricAdapterHead, asyncResp, adapterId));
Sunny Srivastava31791052021-03-12 10:39:16 -0600441}
442
443inline 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
456inline 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 Baebe1384e2024-08-20 12:07:10 -0500467
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 Srivastava31791052021-03-12 10:39:16 -0600472}
473} // namespace redfish