blob: 27a7dbc24d7ada5d4d7d336d01304deafc5a5a16 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +01004#pragma once
5
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "bmcweb_config.h"
7
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08008#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "async_resp.hpp"
10#include "dbus_singleton.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080011#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080012#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070013#include "generated/enums/action_info.hpp"
14#include "generated/enums/chassis.hpp"
15#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080016#include "http_request.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080017#include "led.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080018#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080019#include "query.hpp"
20#include "registries/privilege_registry.hpp"
Myung Bae3f95a272024-03-13 07:32:02 -070021#include "utils/chassis_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080022#include "utils/collection.hpp"
23#include "utils/dbus_utils.hpp"
Nan Zhoucf7eba02022-07-21 23:53:20 +000024#include "utils/json_utils.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070025
Ed Tanousd7857202025-01-28 15:32:26 -080026#include <asm-generic/errno.h>
27
28#include <boost/beast/http/field.hpp>
29#include <boost/beast/http/verb.hpp>
George Liue99073f2022-12-09 11:06:16 +080030#include <boost/system/error_code.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070031#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080032#include <boost/url/url.hpp>
33#include <nlohmann/json.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080034#include <sdbusplus/message/native_types.hpp>
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +020035#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050036
Ed Tanousd7857202025-01-28 15:32:26 -080037#include <algorithm>
George Liu7a1dbc42022-12-07 16:03:22 +080038#include <array>
Ed Tanousd7857202025-01-28 15:32:26 -080039#include <format>
40#include <functional>
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -070041#include <memory>
Ed Tanousd7857202025-01-28 15:32:26 -080042#include <optional>
Ed Tanous3544d2a2023-08-06 18:12:20 -070043#include <ranges>
Ed Tanousd7857202025-01-28 15:32:26 -080044#include <string>
George Liu7a1dbc42022-12-07 16:03:22 +080045#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080046#include <utility>
47#include <vector>
George Liu7a1dbc42022-12-07 16:03:22 +080048
Ed Tanous1abe55e2018-09-05 08:30:59 -070049namespace redfish
50{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010051
Patrick Williams504af5a2025-02-03 14:29:03 -050052inline chassis::ChassisType translateChassisTypeToRedfish(
53 const std::string_view& chassisType)
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -070054{
55 if (chassisType ==
56 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Blade")
57 {
58 return chassis::ChassisType::Blade;
59 }
60 if (chassisType ==
61 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Component")
62 {
63 return chassis::ChassisType::Component;
64 }
65 if (chassisType ==
66 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Enclosure")
67 {
68 return chassis::ChassisType::Enclosure;
69 }
70 if (chassisType ==
71 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Module")
72 {
73 return chassis::ChassisType::Module;
74 }
75 if (chassisType ==
76 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.RackMount")
77 {
78 return chassis::ChassisType::RackMount;
79 }
80 if (chassisType ==
81 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StandAlone")
82 {
83 return chassis::ChassisType::StandAlone;
84 }
85 if (chassisType ==
86 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.StorageEnclosure")
87 {
88 return chassis::ChassisType::StorageEnclosure;
89 }
90 if (chassisType ==
91 "xyz.openbmc_project.Inventory.Item.Chassis.ChassisType.Zone")
92 {
93 return chassis::ChassisType::Zone;
94 }
95 return chassis::ChassisType::Invalid;
96}
97
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010098/**
Willy Tu5e577bc2022-07-26 00:41:55 +000099 * @brief Retrieves resources over dbus to link to the chassis
100 *
101 * @param[in] asyncResp - Shared pointer for completing asynchronous
102 * calls
103 * @param[in] path - Chassis dbus path to look for the storage.
104 *
105 * Calls the Association endpoints on the path + "/storage" and add the link of
106 * json["Links"]["Storage@odata.count"] =
107 * {"@odata.id", "/redfish/v1/Storage/" + resourceId}
108 *
109 * @return None.
110 */
111inline void getStorageLink(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
112 const sdbusplus::message::object_path& path)
113{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800114 dbus::utility::getProperty<std::vector<std::string>>(
115 "xyz.openbmc_project.ObjectMapper", (path / "storage").str,
116 "xyz.openbmc_project.Association", "endpoints",
Willy Tud4b054c2023-06-12 15:18:45 -0700117 [asyncResp](const boost::system::error_code& ec,
Willy Tu5e577bc2022-07-26 00:41:55 +0000118 const std::vector<std::string>& storageList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400119 if (ec)
Willy Tu5e577bc2022-07-26 00:41:55 +0000120 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400121 BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error");
122 return;
Willy Tu5e577bc2022-07-26 00:41:55 +0000123 }
124
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400125 nlohmann::json::array_t storages;
126 for (const std::string& storagePath : storageList)
127 {
128 std::string id =
129 sdbusplus::message::object_path(storagePath).filename();
130 if (id.empty())
131 {
132 continue;
133 }
134
135 nlohmann::json::object_t storage;
136 storage["@odata.id"] =
137 boost::urls::format("/redfish/v1/Systems/{}/Storage/{}",
138 BMCWEB_REDFISH_SYSTEM_URI_NAME, id);
139 storages.emplace_back(std::move(storage));
140 }
141 asyncResp->res.jsonValue["Links"]["Storage@odata.count"] =
142 storages.size();
143 asyncResp->res.jsonValue["Links"]["Storage"] = std::move(storages);
144 });
Willy Tu5e577bc2022-07-26 00:41:55 +0000145}
146
147/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600148 * @brief Retrieves chassis state properties over dbus
149 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700150 * @param[in] asyncResp - Shared pointer for completing asynchronous calls.
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600151 *
152 * @return None.
153 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700154inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> asyncResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600155{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800156 dbus::utility::getProperty<std::string>(
157 "xyz.openbmc_project.State.Chassis",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700158 "/xyz/openbmc_project/state/chassis0",
159 "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
Ed Tanousac106bf2023-06-07 09:24:59 -0700160 [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec,
161 const std::string& chassisState) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400162 if (ec)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600163 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400164 if (ec == boost::system::errc::host_unreachable)
165 {
166 // Service not available, no error, just don't return
167 // chassis state info
168 BMCWEB_LOG_DEBUG("Service not available {}", ec);
169 return;
170 }
171 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
172 messages::internalError(asyncResp->res);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600173 return;
174 }
175
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400176 BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState);
177 // Verify Chassis State
178 if (chassisState ==
179 "xyz.openbmc_project.State.Chassis.PowerState.On")
180 {
181 asyncResp->res.jsonValue["PowerState"] =
182 resource::PowerState::On;
183 asyncResp->res.jsonValue["Status"]["State"] =
184 resource::State::Enabled;
185 }
186 else if (chassisState ==
187 "xyz.openbmc_project.State.Chassis.PowerState.Off")
188 {
189 asyncResp->res.jsonValue["PowerState"] =
190 resource::PowerState::Off;
191 asyncResp->res.jsonValue["Status"]["State"] =
192 resource::State::StandbyOffline;
193 }
194 });
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600195}
196
Qiang XUc1819422019-02-27 13:51:32 +0800197/**
198 * Retrieves physical security properties over dbus
199 */
Chau Ly7164bc62023-10-15 14:55:30 +0000200inline void handlePhysicalSecurityGetSubTree(
201 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
202 const boost::system::error_code& ec,
203 const dbus::utility::MapperGetSubTreeResponse& subtree)
Qiang XUc1819422019-02-27 13:51:32 +0800204{
Chau Ly7164bc62023-10-15 14:55:30 +0000205 if (ec)
206 {
207 // do not add err msg in redfish response, because this is not
208 // mandatory property
209 BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec);
210 return;
211 }
212 // Iterate over all retrieved ObjectPaths.
213 for (const auto& object : subtree)
214 {
215 if (!object.second.empty())
Ed Tanous002d39b2022-05-31 08:59:27 -0700216 {
Ed Tanous89144a32024-04-08 17:27:04 -0700217 const auto& service = object.second.front();
Chau Ly7164bc62023-10-15 14:55:30 +0000218
219 BMCWEB_LOG_DEBUG("Get intrusion status by service ");
220
Ed Tanousdeae6a72024-11-11 21:58:57 -0800221 dbus::utility::getProperty<std::string>(
222 service.first, object.first,
Chau Ly7164bc62023-10-15 14:55:30 +0000223 "xyz.openbmc_project.Chassis.Intrusion", "Status",
224 [asyncResp](const boost::system::error_code& ec1,
225 const std::string& value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400226 if (ec1)
227 {
228 // do not add err msg in redfish response, because this
229 // is not
230 // mandatory property
231 BMCWEB_LOG_ERROR("DBUS response error {}", ec1);
232 return;
233 }
234 asyncResp->res.jsonValue["PhysicalSecurity"]
235 ["IntrusionSensorNumber"] = 1;
236 asyncResp->res
237 .jsonValue["PhysicalSecurity"]["IntrusionSensor"] =
238 value;
239 });
Chau Ly7164bc62023-10-15 14:55:30 +0000240
Ed Tanous002d39b2022-05-31 08:59:27 -0700241 return;
242 }
Chau Ly7164bc62023-10-15 14:55:30 +0000243 }
Qiang XUc1819422019-02-27 13:51:32 +0800244}
245
Nan Zhoucf7eba02022-07-21 23:53:20 +0000246inline void handleChassisCollectionGet(
247 App& app, const crow::Request& req,
248 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
249{
250 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
251 {
252 return;
253 }
254 asyncResp->res.jsonValue["@odata.type"] =
255 "#ChassisCollection.ChassisCollection";
256 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
257 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
258
259 collection_util::getCollectionMembers(
Myung Bae3f95a272024-03-13 07:32:02 -0700260 asyncResp, boost::urls::url("/redfish/v1/Chassis"), chassisInterfaces,
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500261 "/xyz/openbmc_project/inventory");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000262}
263
Jie Yanga5617492021-06-29 12:59:14 -0700264inline void getChassisContainedBy(
265 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
266 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500267 const dbus::utility::MapperGetSubTreePathsResponse& upstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700268{
269 if (ec)
270 {
271 if (ec.value() != EBADR)
272 {
Ed Tanous62598e32023-07-17 17:06:25 -0700273 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700274 messages::internalError(asyncResp->res);
275 }
276 return;
277 }
278 if (upstreamChassisPaths.empty())
279 {
280 return;
281 }
282 if (upstreamChassisPaths.size() > 1)
283 {
Ed Tanous8ece0e42024-01-02 13:16:50 -0800284 BMCWEB_LOG_ERROR("{} is contained by multiple chassis", chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700285 messages::internalError(asyncResp->res);
286 return;
287 }
288
289 sdbusplus::message::object_path upstreamChassisPath(
290 upstreamChassisPaths[0]);
291 std::string upstreamChassis = upstreamChassisPath.filename();
292 if (upstreamChassis.empty())
293 {
Ed Tanous62598e32023-07-17 17:06:25 -0700294 BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}",
295 upstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700296 return;
297 }
298
299 asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] =
300 boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis);
301}
302
303inline void getChassisContains(
304 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
305 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500306 const dbus::utility::MapperGetSubTreePathsResponse& downstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700307{
308 if (ec)
309 {
310 if (ec.value() != EBADR)
311 {
Ed Tanous62598e32023-07-17 17:06:25 -0700312 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700313 messages::internalError(asyncResp->res);
314 }
315 return;
316 }
317 if (downstreamChassisPaths.empty())
318 {
319 return;
320 }
321 nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"];
322 if (!jValue.is_array())
323 {
324 // Create the array if it was empty
325 jValue = nlohmann::json::array();
326 }
327 for (const auto& p : downstreamChassisPaths)
328 {
329 sdbusplus::message::object_path downstreamChassisPath(p);
330 std::string downstreamChassis = downstreamChassisPath.filename();
331 if (downstreamChassis.empty())
332 {
Ed Tanous62598e32023-07-17 17:06:25 -0700333 BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}",
334 downstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700335 continue;
336 }
337 nlohmann::json link;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400338 link["@odata.id"] =
339 boost::urls::format("/redfish/v1/Chassis/{}", downstreamChassis);
Jie Yanga5617492021-06-29 12:59:14 -0700340 jValue.push_back(std::move(link));
341 }
342 asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size();
343}
344
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400345inline void getChassisConnectivity(
346 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
347 const std::string& chassisId, const std::string& chassisPath)
Jie Yanga5617492021-06-29 12:59:14 -0700348{
Ed Tanous62598e32023-07-17 17:06:25 -0700349 BMCWEB_LOG_DEBUG("Get chassis connectivity");
Jie Yanga5617492021-06-29 12:59:14 -0700350
Myung Bae28ee5632024-05-24 13:10:04 -0500351 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700352 chassisPath + "/contained_by",
Myung Bae28ee5632024-05-24 13:10:04 -0500353 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700354 chassisInterfaces,
Jie Yanga5617492021-06-29 12:59:14 -0700355 std::bind_front(getChassisContainedBy, asyncResp, chassisId));
356
Myung Bae28ee5632024-05-24 13:10:04 -0500357 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700358 chassisPath + "/containing",
Myung Bae28ee5632024-05-24 13:10:04 -0500359 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700360 chassisInterfaces,
361 std::bind_front(getChassisContains, asyncResp, chassisId));
Jie Yanga5617492021-06-29 12:59:14 -0700362}
363
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100364/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100365 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700366 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100367 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700368inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700369{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700370 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700371 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700372 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000373 std::bind_front(handleChassisCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700374}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100375
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400376inline void getChassisLocationCode(
377 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
378 const std::string& connectionName, const std::string& path)
Willy Tu308f70c2021-09-28 20:24:52 -0700379{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800380 dbus::utility::getProperty<std::string>(
381 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700382 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800383 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700384 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400385 if (ec)
386 {
387 BMCWEB_LOG_ERROR("DBUS response error for Location");
388 messages::internalError(asyncResp->res);
389 return;
390 }
Willy Tu308f70c2021-09-28 20:24:52 -0700391
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400392 asyncResp->res
393 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
394 property;
395 });
Willy Tu308f70c2021-09-28 20:24:52 -0700396}
397
398inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
399 const std::string& connectionName,
400 const std::string& path)
401{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800402 dbus::utility::getProperty<std::string>(
403 connectionName, path, "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800404 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700405 const std::string& chassisUUID) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400406 if (ec)
407 {
408 BMCWEB_LOG_ERROR("DBUS response error for UUID");
409 messages::internalError(asyncResp->res);
410 return;
411 }
412 asyncResp->res.jsonValue["UUID"] = chassisUUID;
413 });
Willy Tu308f70c2021-09-28 20:24:52 -0700414}
415
Chau Ly7164bc62023-10-15 14:55:30 +0000416inline void handleDecoratorAssetProperties(
417 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
418 const std::string& chassisId, const std::string& path,
419 const dbus::utility::DBusPropertiesMap& propertiesList)
420{
421 const std::string* partNumber = nullptr;
422 const std::string* serialNumber = nullptr;
423 const std::string* manufacturer = nullptr;
424 const std::string* model = nullptr;
425 const std::string* sparePartNumber = nullptr;
426
427 const bool success = sdbusplus::unpackPropertiesNoThrow(
428 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
429 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
430 "Model", model, "SparePartNumber", sparePartNumber);
431
432 if (!success)
433 {
434 messages::internalError(asyncResp->res);
435 return;
436 }
437
438 if (partNumber != nullptr)
439 {
440 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
441 }
442
443 if (serialNumber != nullptr)
444 {
445 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
446 }
447
448 if (manufacturer != nullptr)
449 {
450 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
451 }
452
453 if (model != nullptr)
454 {
455 asyncResp->res.jsonValue["Model"] = *model;
456 }
457
458 // SparePartNumber is optional on D-Bus
459 // so skip if it is empty
460 if (sparePartNumber != nullptr && !sparePartNumber->empty())
461 {
462 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
463 }
464
465 asyncResp->res.jsonValue["Name"] = chassisId;
466 asyncResp->res.jsonValue["Id"] = chassisId;
Ed Tanous25b54db2024-04-17 15:40:31 -0700467
468 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL)
469 {
470 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
471 boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId);
472 // Power object
473 asyncResp->res.jsonValue["Power"]["@odata.id"] =
474 boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId);
475 }
476
477 if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM)
478 {
479 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
480 boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem",
481 chassisId);
482 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
483 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem",
484 chassisId);
485 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
486 boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics",
487 chassisId);
488 }
Chau Ly7164bc62023-10-15 14:55:30 +0000489 // SensorCollection
490 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
491 boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -0700492 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
Chau Ly7164bc62023-10-15 14:55:30 +0000493
494 nlohmann::json::array_t computerSystems;
495 nlohmann::json::object_t system;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400496 system["@odata.id"] =
497 std::format("/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000498 computerSystems.emplace_back(std::move(system));
499 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
500 std::move(computerSystems);
501
502 nlohmann::json::array_t managedBy;
503 nlohmann::json::object_t manager;
Ed Tanous253f11b2024-05-16 09:38:31 -0700504 manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
505 BMCWEB_REDFISH_MANAGER_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000506 managedBy.emplace_back(std::move(manager));
507 asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
508 getChassisState(asyncResp);
509 getStorageLink(asyncResp, path);
510}
511
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700512inline void handleChassisProperties(
513 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
514 const dbus::utility::DBusPropertiesMap& propertiesList)
515{
516 const std::string* type = nullptr;
517
518 const bool success = sdbusplus::unpackPropertiesNoThrow(
519 dbus_utils::UnpackErrorPrinter(), propertiesList, "Type", type);
520
521 if (!success)
522 {
523 messages::internalError(asyncResp->res);
524 return;
525 }
526
Gunnar Mills19ea2862024-12-10 09:02:03 -0600527 // Chassis Type is a required property in Redfish
528 // If there is an error or some enum we don't support just sit it to Rack
529 // Mount
530 asyncResp->res.jsonValue["ChassisType"] = chassis::ChassisType::RackMount;
531
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700532 if (type != nullptr)
533 {
534 auto chassisType = translateChassisTypeToRedfish(*type);
535 if (chassisType != chassis::ChassisType::Invalid)
536 {
537 asyncResp->res.jsonValue["ChassisType"] = chassisType;
538 }
539 }
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700540}
541
Chau Ly7164bc62023-10-15 14:55:30 +0000542inline void handleChassisGetSubTree(
543 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
544 const std::string& chassisId, const boost::system::error_code& ec,
545 const dbus::utility::MapperGetSubTreeResponse& subtree)
546{
547 if (ec)
548 {
549 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
550 messages::internalError(asyncResp->res);
551 return;
552 }
553 // Iterate over all retrieved ObjectPaths.
554 for (const std::pair<
555 std::string,
556 std::vector<std::pair<std::string, std::vector<std::string>>>>&
557 object : subtree)
558 {
559 const std::string& path = object.first;
560 const std::vector<std::pair<std::string, std::vector<std::string>>>&
561 connectionNames = object.second;
562
563 sdbusplus::message::object_path objPath(path);
564 if (objPath.filename() != chassisId)
565 {
566 continue;
567 }
568
569 getChassisConnectivity(asyncResp, chassisId, path);
570
Chau Ly7164bc62023-10-15 14:55:30 +0000571 if (connectionNames.empty())
572 {
573 BMCWEB_LOG_ERROR("Got 0 Connection names");
574 continue;
575 }
576
577 asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis";
578 asyncResp->res.jsonValue["@odata.id"] =
579 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
580 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
Chau Ly7164bc62023-10-15 14:55:30 +0000581 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
582 boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset",
583 chassisId);
584 asyncResp->res
585 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
586 boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo",
587 chassisId);
Chau Ly7164bc62023-10-15 14:55:30 +0000588 dbus::utility::getAssociationEndPoints(
589 path + "/drive",
590 [asyncResp, chassisId](const boost::system::error_code& ec3,
591 const dbus::utility::MapperEndPoints& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400592 if (ec3 || resp.empty())
593 {
594 return; // no drives = no failures
595 }
Chau Ly7164bc62023-10-15 14:55:30 +0000596
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400597 nlohmann::json reference;
598 reference["@odata.id"] = boost::urls::format(
599 "/redfish/v1/Chassis/{}/Drives", chassisId);
600 asyncResp->res.jsonValue["Drives"] = std::move(reference);
601 });
Chau Ly7164bc62023-10-15 14:55:30 +0000602
603 const std::string& connectionName = connectionNames[0].first;
604
605 const std::vector<std::string>& interfaces2 = connectionNames[0].second;
George Liue5ae9c12021-11-16 10:31:23 +0800606 const std::array<const char*, 3> hasIndicatorLed = {
607 "xyz.openbmc_project.Inventory.Item.Chassis",
Chau Ly7164bc62023-10-15 14:55:30 +0000608 "xyz.openbmc_project.Inventory.Item.Panel",
609 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
610
611 const std::string assetTagInterface =
612 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
613 const std::string replaceableInterface =
614 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
Carson Labradob4d593f2024-02-16 22:34:32 +0000615 const std::string revisionInterface =
616 "xyz.openbmc_project.Inventory.Decorator.Revision";
Chau Ly7164bc62023-10-15 14:55:30 +0000617 for (const auto& interface : interfaces2)
618 {
619 if (interface == assetTagInterface)
620 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800621 dbus::utility::getProperty<std::string>(
622 connectionName, path, assetTagInterface, "AssetTag",
Chau Ly7164bc62023-10-15 14:55:30 +0000623 [asyncResp, chassisId](const boost::system::error_code& ec2,
624 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400625 if (ec2)
626 {
627 BMCWEB_LOG_ERROR(
628 "DBus response error for AssetTag: {}", ec2);
629 messages::internalError(asyncResp->res);
630 return;
631 }
632 asyncResp->res.jsonValue["AssetTag"] = property;
633 });
Chau Ly7164bc62023-10-15 14:55:30 +0000634 }
635 else if (interface == replaceableInterface)
636 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800637 dbus::utility::getProperty<bool>(
638 connectionName, path, replaceableInterface, "HotPluggable",
Chau Ly7164bc62023-10-15 14:55:30 +0000639 [asyncResp, chassisId](const boost::system::error_code& ec2,
640 const bool property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400641 if (ec2)
642 {
643 BMCWEB_LOG_ERROR(
644 "DBus response error for HotPluggable: {}",
645 ec2);
646 messages::internalError(asyncResp->res);
647 return;
648 }
649 asyncResp->res.jsonValue["HotPluggable"] = property;
650 });
Chau Ly7164bc62023-10-15 14:55:30 +0000651 }
Carson Labradob4d593f2024-02-16 22:34:32 +0000652 else if (interface == revisionInterface)
653 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800654 dbus::utility::getProperty<std::string>(
655 connectionName, path, revisionInterface, "Version",
Carson Labradob4d593f2024-02-16 22:34:32 +0000656 [asyncResp, chassisId](const boost::system::error_code& ec2,
657 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400658 if (ec2)
659 {
660 BMCWEB_LOG_ERROR(
661 "DBus response error for Version: {}", ec2);
662 messages::internalError(asyncResp->res);
663 return;
664 }
665 asyncResp->res.jsonValue["Version"] = property;
666 });
Carson Labradob4d593f2024-02-16 22:34:32 +0000667 }
Chau Ly7164bc62023-10-15 14:55:30 +0000668 }
669
670 for (const char* interface : hasIndicatorLed)
671 {
672 if (std::ranges::find(interfaces2, interface) != interfaces2.end())
673 {
674 getIndicatorLedState(asyncResp);
675 getSystemLocationIndicatorActive(asyncResp);
676 break;
677 }
678 }
679
Ed Tanousdeae6a72024-11-11 21:58:57 -0800680 dbus::utility::getAllProperties(
Chau Ly7164bc62023-10-15 14:55:30 +0000681 *crow::connections::systemBus, connectionName, path,
682 "xyz.openbmc_project.Inventory.Decorator.Asset",
683 [asyncResp, chassisId,
684 path](const boost::system::error_code&,
685 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400686 handleDecoratorAssetProperties(asyncResp, chassisId, path,
687 propertiesList);
688 });
Chau Ly7164bc62023-10-15 14:55:30 +0000689
Ed Tanous46f780f2025-02-09 09:35:23 -0800690 dbus::utility::getAllProperties(
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700691 *crow::connections::systemBus, connectionName, path,
692 "xyz.openbmc_project.Inventory.Item.Chassis",
693 [asyncResp](
694 const boost::system::error_code&,
695 const dbus::utility::DBusPropertiesMap& propertiesList) {
696 handleChassisProperties(asyncResp, propertiesList);
697 });
698
Chau Ly7164bc62023-10-15 14:55:30 +0000699 for (const auto& interface : interfaces2)
700 {
701 if (interface == "xyz.openbmc_project.Common.UUID")
702 {
703 getChassisUUID(asyncResp, connectionName, path);
704 }
705 else if (interface ==
706 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
707 {
708 getChassisLocationCode(asyncResp, connectionName, path);
709 }
710 }
711
712 return;
713 }
714
715 // Couldn't find an object with that name. return an error
716 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
717}
718
Patrick Williams504af5a2025-02-03 14:29:03 -0500719inline void handleChassisGet(
720 App& app, const crow::Request& req,
721 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
722 const std::string& chassisId)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000723{
724 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
725 {
726 return;
727 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000728
George Liue99073f2022-12-09 11:06:16 +0800729 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700730 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Chau Ly7164bc62023-10-15 14:55:30 +0000731 std::bind_front(handleChassisGetSubTree, asyncResp, chassisId));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000732
Chau Ly7164bc62023-10-15 14:55:30 +0000733 constexpr std::array<std::string_view, 1> interfaces2 = {
734 "xyz.openbmc_project.Chassis.Intrusion"};
Nan Zhoucf7eba02022-07-21 23:53:20 +0000735
Chau Ly7164bc62023-10-15 14:55:30 +0000736 dbus::utility::getSubTree(
737 "/xyz/openbmc_project", 0, interfaces2,
738 std::bind_front(handlePhysicalSecurityGetSubTree, asyncResp));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000739}
740
Patrick Williams504af5a2025-02-03 14:29:03 -0500741inline void handleChassisPatch(
742 App& app, const crow::Request& req,
743 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
744 const std::string& param)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000745{
746 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
747 {
748 return;
749 }
750 std::optional<bool> locationIndicatorActive;
751 std::optional<std::string> indicatorLed;
752
753 if (param.empty())
754 {
755 return;
756 }
757
Patrick Williams504af5a2025-02-03 14:29:03 -0500758 if (!json_util::readJsonPatch( //
759 req, asyncResp->res, //
760 "IndicatorLED", indicatorLed, //
Myung Baeafc474a2024-10-09 00:53:29 -0700761 "LocationIndicatorActive", locationIndicatorActive //
762 ))
Nan Zhoucf7eba02022-07-21 23:53:20 +0000763 {
764 return;
765 }
766
767 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
768 if (!locationIndicatorActive && !indicatorLed)
769 {
770 return; // delete this when we support more patch properties
771 }
772 if (indicatorLed)
773 {
774 asyncResp->res.addHeader(
775 boost::beast::http::field::warning,
776 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
777 }
778
Nan Zhoucf7eba02022-07-21 23:53:20 +0000779 const std::string& chassisId = param;
780
George Liue99073f2022-12-09 11:06:16 +0800781 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700782 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000783 [asyncResp, chassisId, locationIndicatorActive,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800784 indicatorLed](const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000785 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400786 if (ec)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000787 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400788 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
789 messages::internalError(asyncResp->res);
790 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000791 }
792
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400793 // Iterate over all retrieved ObjectPaths.
794 for (const std::pair<std::string,
795 std::vector<std::pair<
796 std::string, std::vector<std::string>>>>&
797 object : subtree)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000798 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400799 const std::string& path = object.first;
800 const std::vector<
801 std::pair<std::string, std::vector<std::string>>>&
802 connectionNames = object.second;
803
804 sdbusplus::message::object_path objPath(path);
805 if (objPath.filename() != chassisId)
806 {
807 continue;
808 }
809
810 if (connectionNames.empty())
811 {
812 BMCWEB_LOG_ERROR("Got 0 Connection names");
813 continue;
814 }
815
816 const std::vector<std::string>& interfaces3 =
817 connectionNames[0].second;
818
819 const std::array<const char*, 3> hasIndicatorLed = {
820 "xyz.openbmc_project.Inventory.Item.Chassis",
821 "xyz.openbmc_project.Inventory.Item.Panel",
822 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
823 bool indicatorChassis = false;
824 for (const char* interface : hasIndicatorLed)
825 {
826 if (std::ranges::find(interfaces3, interface) !=
827 interfaces3.end())
828 {
829 indicatorChassis = true;
830 break;
831 }
832 }
833 if (locationIndicatorActive)
834 {
835 if (indicatorChassis)
836 {
837 setSystemLocationIndicatorActive(
838 asyncResp, *locationIndicatorActive);
839 }
840 else
841 {
842 messages::propertyUnknown(asyncResp->res,
843 "LocationIndicatorActive");
844 }
845 }
846 if (indicatorLed)
847 {
848 if (indicatorChassis)
849 {
850 setIndicatorLedState(asyncResp, *indicatorLed);
851 }
852 else
853 {
854 messages::propertyUnknown(asyncResp->res,
855 "IndicatorLED");
856 }
857 }
858 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000859 }
860
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400861 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
862 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000863}
864
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100865/**
866 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700867 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100868 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700869inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700870{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700871 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700872 .privileges(redfish::privileges::getChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700873 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000874 std::bind_front(handleChassisGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700875
876 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700877 .privileges(redfish::privileges::patchChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700878 .methods(boost::beast::http::verb::patch)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000879 std::bind_front(handleChassisPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700880}
P.K. Leedd99e042020-06-17 19:43:16 +0800881
Patrick Williams504af5a2025-02-03 14:29:03 -0500882inline void doChassisPowerCycle(
883 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800884{
George Liu7a1dbc42022-12-07 16:03:22 +0800885 constexpr std::array<std::string_view, 1> interfaces = {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700886 "xyz.openbmc_project.State.Chassis"};
887
888 // Use mapper to get subtree paths.
George Liu7a1dbc42022-12-07 16:03:22 +0800889 dbus::utility::getSubTreePaths(
890 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800891 [asyncResp](
George Liu7a1dbc42022-12-07 16:03:22 +0800892 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800893 const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400894 if (ec)
895 {
896 BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec);
897 messages::internalError(asyncResp->res);
898 return;
899 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700900
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400901 const char* processName = "xyz.openbmc_project.State.Chassis";
902 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
903 const char* destProperty = "RequestedPowerTransition";
904 const std::string propertyValue =
905 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
906 std::string objectPath =
907 "/xyz/openbmc_project/state/chassis_system0";
Ed Tanous002d39b2022-05-31 08:59:27 -0700908
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400909 /* Look for system reset chassis path */
910 if ((std::ranges::find(chassisList, objectPath)) ==
911 chassisList.end())
912 {
913 /* We prefer to reset the full chassis_system, but if it doesn't
914 * exist on some platforms, fall back to a host-only power reset
915 */
916 objectPath = "/xyz/openbmc_project/state/chassis0";
917 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700918
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400919 setDbusProperty(asyncResp, "ResetType", processName, objectPath,
920 interfaceName, destProperty, propertyValue);
921 });
P.K. Leedd99e042020-06-17 19:43:16 +0800922}
923
Nan Zhoucf7eba02022-07-21 23:53:20 +0000924inline void handleChassisResetActionInfoPost(
925 App& app, const crow::Request& req,
926 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
927 const std::string& /*chassisId*/)
928{
929 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
930 {
931 return;
932 }
Ed Tanous62598e32023-07-17 17:06:25 -0700933 BMCWEB_LOG_DEBUG("Post Chassis Reset.");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000934
935 std::string resetType;
936
937 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
938 {
939 return;
940 }
941
942 if (resetType != "PowerCycle")
943 {
Ed Tanous62598e32023-07-17 17:06:25 -0700944 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000945 messages::actionParameterNotSupported(asyncResp->res, resetType,
946 "ResetType");
947
948 return;
949 }
950 doChassisPowerCycle(asyncResp);
951}
952
P.K. Leedd99e042020-06-17 19:43:16 +0800953/**
954 * ChassisResetAction class supports the POST method for the Reset
955 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700956 * Function handles POST method request.
957 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800958 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700959
960inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800961{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700962 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700963 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700964 .methods(boost::beast::http::verb::post)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000965 std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
966}
P.K. Leedd99e042020-06-17 19:43:16 +0800967
Nan Zhoucf7eba02022-07-21 23:53:20 +0000968inline void handleChassisResetActionInfoGet(
969 App& app, const crow::Request& req,
970 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
971 const std::string& chassisId)
972{
973 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
974 {
975 return;
976 }
977 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700978 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
979 "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000980 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
P.K. Leedd99e042020-06-17 19:43:16 +0800981
Nan Zhoucf7eba02022-07-21 23:53:20 +0000982 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
983 nlohmann::json::array_t parameters;
984 nlohmann::json::object_t parameter;
985 parameter["Name"] = "ResetType";
986 parameter["Required"] = true;
Ed Tanous539d8c62024-06-19 14:38:27 -0700987 parameter["DataType"] = action_info::ParameterTypes::String;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000988 nlohmann::json::array_t allowed;
Patrick Williamsad539542023-05-12 10:10:08 -0500989 allowed.emplace_back("PowerCycle");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000990 parameter["AllowableValues"] = std::move(allowed);
Patrick Williamsad539542023-05-12 10:10:08 -0500991 parameters.emplace_back(std::move(parameter));
P.K. Leedd99e042020-06-17 19:43:16 +0800992
Nan Zhoucf7eba02022-07-21 23:53:20 +0000993 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700994}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530995
996/**
997 * ChassisResetActionInfo derived class for delivering Chassis
998 * ResetType AllowableValues using ResetInfo schema.
999 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001000inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05301001{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001002 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -07001003 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001004 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +00001005 std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001006}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05301007
Ed Tanous1abe55e2018-09-05 08:30:59 -07001008} // namespace redfish