blob: 879ae38e5ef050643322467d7322d1264e9dffed [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{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700156 // crow::connections::systemBus->async_method_call(
Ed Tanousdeae6a72024-11-11 21:58:57 -0800157 dbus::utility::getProperty<std::string>(
158 "xyz.openbmc_project.State.Chassis",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700159 "/xyz/openbmc_project/state/chassis0",
160 "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec,
162 const std::string& chassisState) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400163 if (ec)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600164 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400165 if (ec == boost::system::errc::host_unreachable)
166 {
167 // Service not available, no error, just don't return
168 // chassis state info
169 BMCWEB_LOG_DEBUG("Service not available {}", ec);
170 return;
171 }
172 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
173 messages::internalError(asyncResp->res);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600174 return;
175 }
176
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400177 BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState);
178 // Verify Chassis State
179 if (chassisState ==
180 "xyz.openbmc_project.State.Chassis.PowerState.On")
181 {
182 asyncResp->res.jsonValue["PowerState"] =
183 resource::PowerState::On;
184 asyncResp->res.jsonValue["Status"]["State"] =
185 resource::State::Enabled;
186 }
187 else if (chassisState ==
188 "xyz.openbmc_project.State.Chassis.PowerState.Off")
189 {
190 asyncResp->res.jsonValue["PowerState"] =
191 resource::PowerState::Off;
192 asyncResp->res.jsonValue["Status"]["State"] =
193 resource::State::StandbyOffline;
194 }
195 });
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600196}
197
Qiang XUc1819422019-02-27 13:51:32 +0800198/**
199 * Retrieves physical security properties over dbus
200 */
Chau Ly7164bc62023-10-15 14:55:30 +0000201inline void handlePhysicalSecurityGetSubTree(
202 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
203 const boost::system::error_code& ec,
204 const dbus::utility::MapperGetSubTreeResponse& subtree)
Qiang XUc1819422019-02-27 13:51:32 +0800205{
Chau Ly7164bc62023-10-15 14:55:30 +0000206 if (ec)
207 {
208 // do not add err msg in redfish response, because this is not
209 // mandatory property
210 BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec);
211 return;
212 }
213 // Iterate over all retrieved ObjectPaths.
214 for (const auto& object : subtree)
215 {
216 if (!object.second.empty())
Ed Tanous002d39b2022-05-31 08:59:27 -0700217 {
Ed Tanous89144a32024-04-08 17:27:04 -0700218 const auto& service = object.second.front();
Chau Ly7164bc62023-10-15 14:55:30 +0000219
220 BMCWEB_LOG_DEBUG("Get intrusion status by service ");
221
Ed Tanousdeae6a72024-11-11 21:58:57 -0800222 dbus::utility::getProperty<std::string>(
223 service.first, object.first,
Chau Ly7164bc62023-10-15 14:55:30 +0000224 "xyz.openbmc_project.Chassis.Intrusion", "Status",
225 [asyncResp](const boost::system::error_code& ec1,
226 const std::string& value) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400227 if (ec1)
228 {
229 // do not add err msg in redfish response, because this
230 // is not
231 // mandatory property
232 BMCWEB_LOG_ERROR("DBUS response error {}", ec1);
233 return;
234 }
235 asyncResp->res.jsonValue["PhysicalSecurity"]
236 ["IntrusionSensorNumber"] = 1;
237 asyncResp->res
238 .jsonValue["PhysicalSecurity"]["IntrusionSensor"] =
239 value;
240 });
Chau Ly7164bc62023-10-15 14:55:30 +0000241
Ed Tanous002d39b2022-05-31 08:59:27 -0700242 return;
243 }
Chau Ly7164bc62023-10-15 14:55:30 +0000244 }
Qiang XUc1819422019-02-27 13:51:32 +0800245}
246
Nan Zhoucf7eba02022-07-21 23:53:20 +0000247inline void handleChassisCollectionGet(
248 App& app, const crow::Request& req,
249 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
250{
251 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
252 {
253 return;
254 }
255 asyncResp->res.jsonValue["@odata.type"] =
256 "#ChassisCollection.ChassisCollection";
257 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
258 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
259
260 collection_util::getCollectionMembers(
Myung Bae3f95a272024-03-13 07:32:02 -0700261 asyncResp, boost::urls::url("/redfish/v1/Chassis"), chassisInterfaces,
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500262 "/xyz/openbmc_project/inventory");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000263}
264
Jie Yanga5617492021-06-29 12:59:14 -0700265inline void getChassisContainedBy(
266 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
267 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500268 const dbus::utility::MapperGetSubTreePathsResponse& upstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700269{
270 if (ec)
271 {
272 if (ec.value() != EBADR)
273 {
Ed Tanous62598e32023-07-17 17:06:25 -0700274 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700275 messages::internalError(asyncResp->res);
276 }
277 return;
278 }
279 if (upstreamChassisPaths.empty())
280 {
281 return;
282 }
283 if (upstreamChassisPaths.size() > 1)
284 {
Ed Tanous8ece0e42024-01-02 13:16:50 -0800285 BMCWEB_LOG_ERROR("{} is contained by multiple chassis", chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700286 messages::internalError(asyncResp->res);
287 return;
288 }
289
290 sdbusplus::message::object_path upstreamChassisPath(
291 upstreamChassisPaths[0]);
292 std::string upstreamChassis = upstreamChassisPath.filename();
293 if (upstreamChassis.empty())
294 {
Ed Tanous62598e32023-07-17 17:06:25 -0700295 BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}",
296 upstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700297 return;
298 }
299
300 asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] =
301 boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis);
302}
303
304inline void getChassisContains(
305 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
306 const std::string& chassisId, const boost::system::error_code& ec,
Myung Bae28ee5632024-05-24 13:10:04 -0500307 const dbus::utility::MapperGetSubTreePathsResponse& downstreamChassisPaths)
Jie Yanga5617492021-06-29 12:59:14 -0700308{
309 if (ec)
310 {
311 if (ec.value() != EBADR)
312 {
Ed Tanous62598e32023-07-17 17:06:25 -0700313 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700314 messages::internalError(asyncResp->res);
315 }
316 return;
317 }
318 if (downstreamChassisPaths.empty())
319 {
320 return;
321 }
322 nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"];
323 if (!jValue.is_array())
324 {
325 // Create the array if it was empty
326 jValue = nlohmann::json::array();
327 }
328 for (const auto& p : downstreamChassisPaths)
329 {
330 sdbusplus::message::object_path downstreamChassisPath(p);
331 std::string downstreamChassis = downstreamChassisPath.filename();
332 if (downstreamChassis.empty())
333 {
Ed Tanous62598e32023-07-17 17:06:25 -0700334 BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}",
335 downstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700336 continue;
337 }
338 nlohmann::json link;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400339 link["@odata.id"] =
340 boost::urls::format("/redfish/v1/Chassis/{}", downstreamChassis);
Jie Yanga5617492021-06-29 12:59:14 -0700341 jValue.push_back(std::move(link));
342 }
343 asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size();
344}
345
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400346inline void getChassisConnectivity(
347 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
348 const std::string& chassisId, const std::string& chassisPath)
Jie Yanga5617492021-06-29 12:59:14 -0700349{
Ed Tanous62598e32023-07-17 17:06:25 -0700350 BMCWEB_LOG_DEBUG("Get chassis connectivity");
Jie Yanga5617492021-06-29 12:59:14 -0700351
Myung Bae28ee5632024-05-24 13:10:04 -0500352 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700353 chassisPath + "/contained_by",
Myung Bae28ee5632024-05-24 13:10:04 -0500354 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700355 chassisInterfaces,
Jie Yanga5617492021-06-29 12:59:14 -0700356 std::bind_front(getChassisContainedBy, asyncResp, chassisId));
357
Myung Bae28ee5632024-05-24 13:10:04 -0500358 dbus::utility::getAssociatedSubTreePaths(
Jie Yanga5617492021-06-29 12:59:14 -0700359 chassisPath + "/containing",
Myung Bae28ee5632024-05-24 13:10:04 -0500360 sdbusplus::message::object_path("/xyz/openbmc_project/inventory"), 0,
Myung Bae3f95a272024-03-13 07:32:02 -0700361 chassisInterfaces,
362 std::bind_front(getChassisContains, asyncResp, chassisId));
Jie Yanga5617492021-06-29 12:59:14 -0700363}
364
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100365/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100366 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700367 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100368 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700369inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700370{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700371 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700372 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700373 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000374 std::bind_front(handleChassisCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700375}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100376
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400377inline void getChassisLocationCode(
378 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
379 const std::string& connectionName, const std::string& path)
Willy Tu308f70c2021-09-28 20:24:52 -0700380{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800381 dbus::utility::getProperty<std::string>(
382 connectionName, path,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700383 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800384 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700385 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400386 if (ec)
387 {
388 BMCWEB_LOG_ERROR("DBUS response error for Location");
389 messages::internalError(asyncResp->res);
390 return;
391 }
Willy Tu308f70c2021-09-28 20:24:52 -0700392
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400393 asyncResp->res
394 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
395 property;
396 });
Willy Tu308f70c2021-09-28 20:24:52 -0700397}
398
399inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
400 const std::string& connectionName,
401 const std::string& path)
402{
Ed Tanousdeae6a72024-11-11 21:58:57 -0800403 dbus::utility::getProperty<std::string>(
404 connectionName, path, "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800405 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700406 const std::string& chassisUUID) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400407 if (ec)
408 {
409 BMCWEB_LOG_ERROR("DBUS response error for UUID");
410 messages::internalError(asyncResp->res);
411 return;
412 }
413 asyncResp->res.jsonValue["UUID"] = chassisUUID;
414 });
Willy Tu308f70c2021-09-28 20:24:52 -0700415}
416
Chau Ly7164bc62023-10-15 14:55:30 +0000417inline void handleDecoratorAssetProperties(
418 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
419 const std::string& chassisId, const std::string& path,
420 const dbus::utility::DBusPropertiesMap& propertiesList)
421{
422 const std::string* partNumber = nullptr;
423 const std::string* serialNumber = nullptr;
424 const std::string* manufacturer = nullptr;
425 const std::string* model = nullptr;
426 const std::string* sparePartNumber = nullptr;
427
428 const bool success = sdbusplus::unpackPropertiesNoThrow(
429 dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber",
430 partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer,
431 "Model", model, "SparePartNumber", sparePartNumber);
432
433 if (!success)
434 {
435 messages::internalError(asyncResp->res);
436 return;
437 }
438
439 if (partNumber != nullptr)
440 {
441 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
442 }
443
444 if (serialNumber != nullptr)
445 {
446 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
447 }
448
449 if (manufacturer != nullptr)
450 {
451 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
452 }
453
454 if (model != nullptr)
455 {
456 asyncResp->res.jsonValue["Model"] = *model;
457 }
458
459 // SparePartNumber is optional on D-Bus
460 // so skip if it is empty
461 if (sparePartNumber != nullptr && !sparePartNumber->empty())
462 {
463 asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber;
464 }
465
466 asyncResp->res.jsonValue["Name"] = chassisId;
467 asyncResp->res.jsonValue["Id"] = chassisId;
Ed Tanous25b54db2024-04-17 15:40:31 -0700468
469 if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_POWER_THERMAL)
470 {
471 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
472 boost::urls::format("/redfish/v1/Chassis/{}/Thermal", chassisId);
473 // Power object
474 asyncResp->res.jsonValue["Power"]["@odata.id"] =
475 boost::urls::format("/redfish/v1/Chassis/{}/Power", chassisId);
476 }
477
478 if constexpr (BMCWEB_REDFISH_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM)
479 {
480 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
481 boost::urls::format("/redfish/v1/Chassis/{}/ThermalSubsystem",
482 chassisId);
483 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
484 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem",
485 chassisId);
486 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
487 boost::urls::format("/redfish/v1/Chassis/{}/EnvironmentMetrics",
488 chassisId);
489 }
Chau Ly7164bc62023-10-15 14:55:30 +0000490 // SensorCollection
491 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
492 boost::urls::format("/redfish/v1/Chassis/{}/Sensors", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -0700493 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
Chau Ly7164bc62023-10-15 14:55:30 +0000494
495 nlohmann::json::array_t computerSystems;
496 nlohmann::json::object_t system;
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400497 system["@odata.id"] =
498 std::format("/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000499 computerSystems.emplace_back(std::move(system));
500 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
501 std::move(computerSystems);
502
503 nlohmann::json::array_t managedBy;
504 nlohmann::json::object_t manager;
Ed Tanous253f11b2024-05-16 09:38:31 -0700505 manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}",
506 BMCWEB_REDFISH_MANAGER_URI_NAME);
Chau Ly7164bc62023-10-15 14:55:30 +0000507 managedBy.emplace_back(std::move(manager));
508 asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy);
509 getChassisState(asyncResp);
510 getStorageLink(asyncResp, path);
511}
512
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700513inline void handleChassisProperties(
514 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
515 const dbus::utility::DBusPropertiesMap& propertiesList)
516{
517 const std::string* type = nullptr;
518
519 const bool success = sdbusplus::unpackPropertiesNoThrow(
520 dbus_utils::UnpackErrorPrinter(), propertiesList, "Type", type);
521
522 if (!success)
523 {
524 messages::internalError(asyncResp->res);
525 return;
526 }
527
Gunnar Mills19ea2862024-12-10 09:02:03 -0600528 // Chassis Type is a required property in Redfish
529 // If there is an error or some enum we don't support just sit it to Rack
530 // Mount
531 asyncResp->res.jsonValue["ChassisType"] = chassis::ChassisType::RackMount;
532
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700533 if (type != nullptr)
534 {
535 auto chassisType = translateChassisTypeToRedfish(*type);
536 if (chassisType != chassis::ChassisType::Invalid)
537 {
538 asyncResp->res.jsonValue["ChassisType"] = chassisType;
539 }
540 }
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700541}
542
Chau Ly7164bc62023-10-15 14:55:30 +0000543inline void handleChassisGetSubTree(
544 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
545 const std::string& chassisId, const boost::system::error_code& ec,
546 const dbus::utility::MapperGetSubTreeResponse& subtree)
547{
548 if (ec)
549 {
550 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
551 messages::internalError(asyncResp->res);
552 return;
553 }
554 // Iterate over all retrieved ObjectPaths.
555 for (const std::pair<
556 std::string,
557 std::vector<std::pair<std::string, std::vector<std::string>>>>&
558 object : subtree)
559 {
560 const std::string& path = object.first;
561 const std::vector<std::pair<std::string, std::vector<std::string>>>&
562 connectionNames = object.second;
563
564 sdbusplus::message::object_path objPath(path);
565 if (objPath.filename() != chassisId)
566 {
567 continue;
568 }
569
570 getChassisConnectivity(asyncResp, chassisId, path);
571
Chau Ly7164bc62023-10-15 14:55:30 +0000572 if (connectionNames.empty())
573 {
574 BMCWEB_LOG_ERROR("Got 0 Connection names");
575 continue;
576 }
577
578 asyncResp->res.jsonValue["@odata.type"] = "#Chassis.v1_22_0.Chassis";
579 asyncResp->res.jsonValue["@odata.id"] =
580 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
581 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
Chau Ly7164bc62023-10-15 14:55:30 +0000582 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
583 boost::urls::format("/redfish/v1/Chassis/{}/Actions/Chassis.Reset",
584 chassisId);
585 asyncResp->res
586 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
587 boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo",
588 chassisId);
Chau Ly7164bc62023-10-15 14:55:30 +0000589 dbus::utility::getAssociationEndPoints(
590 path + "/drive",
591 [asyncResp, chassisId](const boost::system::error_code& ec3,
592 const dbus::utility::MapperEndPoints& resp) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400593 if (ec3 || resp.empty())
594 {
595 return; // no drives = no failures
596 }
Chau Ly7164bc62023-10-15 14:55:30 +0000597
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400598 nlohmann::json reference;
599 reference["@odata.id"] = boost::urls::format(
600 "/redfish/v1/Chassis/{}/Drives", chassisId);
601 asyncResp->res.jsonValue["Drives"] = std::move(reference);
602 });
Chau Ly7164bc62023-10-15 14:55:30 +0000603
604 const std::string& connectionName = connectionNames[0].first;
605
606 const std::vector<std::string>& interfaces2 = connectionNames[0].second;
George Liue5ae9c12021-11-16 10:31:23 +0800607 const std::array<const char*, 3> hasIndicatorLed = {
608 "xyz.openbmc_project.Inventory.Item.Chassis",
Chau Ly7164bc62023-10-15 14:55:30 +0000609 "xyz.openbmc_project.Inventory.Item.Panel",
610 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
611
612 const std::string assetTagInterface =
613 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
614 const std::string replaceableInterface =
615 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
Carson Labradob4d593f2024-02-16 22:34:32 +0000616 const std::string revisionInterface =
617 "xyz.openbmc_project.Inventory.Decorator.Revision";
Chau Ly7164bc62023-10-15 14:55:30 +0000618 for (const auto& interface : interfaces2)
619 {
620 if (interface == assetTagInterface)
621 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800622 dbus::utility::getProperty<std::string>(
623 connectionName, path, assetTagInterface, "AssetTag",
Chau Ly7164bc62023-10-15 14:55:30 +0000624 [asyncResp, chassisId](const boost::system::error_code& ec2,
625 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400626 if (ec2)
627 {
628 BMCWEB_LOG_ERROR(
629 "DBus response error for AssetTag: {}", ec2);
630 messages::internalError(asyncResp->res);
631 return;
632 }
633 asyncResp->res.jsonValue["AssetTag"] = property;
634 });
Chau Ly7164bc62023-10-15 14:55:30 +0000635 }
636 else if (interface == replaceableInterface)
637 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800638 dbus::utility::getProperty<bool>(
639 connectionName, path, replaceableInterface, "HotPluggable",
Chau Ly7164bc62023-10-15 14:55:30 +0000640 [asyncResp, chassisId](const boost::system::error_code& ec2,
641 const bool property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400642 if (ec2)
643 {
644 BMCWEB_LOG_ERROR(
645 "DBus response error for HotPluggable: {}",
646 ec2);
647 messages::internalError(asyncResp->res);
648 return;
649 }
650 asyncResp->res.jsonValue["HotPluggable"] = property;
651 });
Chau Ly7164bc62023-10-15 14:55:30 +0000652 }
Carson Labradob4d593f2024-02-16 22:34:32 +0000653 else if (interface == revisionInterface)
654 {
Ed Tanousdeae6a72024-11-11 21:58:57 -0800655 dbus::utility::getProperty<std::string>(
656 connectionName, path, revisionInterface, "Version",
Carson Labradob4d593f2024-02-16 22:34:32 +0000657 [asyncResp, chassisId](const boost::system::error_code& ec2,
658 const std::string& property) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400659 if (ec2)
660 {
661 BMCWEB_LOG_ERROR(
662 "DBus response error for Version: {}", ec2);
663 messages::internalError(asyncResp->res);
664 return;
665 }
666 asyncResp->res.jsonValue["Version"] = property;
667 });
Carson Labradob4d593f2024-02-16 22:34:32 +0000668 }
Chau Ly7164bc62023-10-15 14:55:30 +0000669 }
670
671 for (const char* interface : hasIndicatorLed)
672 {
673 if (std::ranges::find(interfaces2, interface) != interfaces2.end())
674 {
675 getIndicatorLedState(asyncResp);
676 getSystemLocationIndicatorActive(asyncResp);
677 break;
678 }
679 }
680
Ed Tanousdeae6a72024-11-11 21:58:57 -0800681 dbus::utility::getAllProperties(
Chau Ly7164bc62023-10-15 14:55:30 +0000682 *crow::connections::systemBus, connectionName, path,
683 "xyz.openbmc_project.Inventory.Decorator.Asset",
684 [asyncResp, chassisId,
685 path](const boost::system::error_code&,
686 const dbus::utility::DBusPropertiesMap& propertiesList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400687 handleDecoratorAssetProperties(asyncResp, chassisId, path,
688 propertiesList);
689 });
Chau Ly7164bc62023-10-15 14:55:30 +0000690
Ed Tanous46f780f2025-02-09 09:35:23 -0800691 dbus::utility::getAllProperties(
Joseph-Jonathan Salzano2952f642024-11-19 12:00:06 -0700692 *crow::connections::systemBus, connectionName, path,
693 "xyz.openbmc_project.Inventory.Item.Chassis",
694 [asyncResp](
695 const boost::system::error_code&,
696 const dbus::utility::DBusPropertiesMap& propertiesList) {
697 handleChassisProperties(asyncResp, propertiesList);
698 });
699
Chau Ly7164bc62023-10-15 14:55:30 +0000700 for (const auto& interface : interfaces2)
701 {
702 if (interface == "xyz.openbmc_project.Common.UUID")
703 {
704 getChassisUUID(asyncResp, connectionName, path);
705 }
706 else if (interface ==
707 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
708 {
709 getChassisLocationCode(asyncResp, connectionName, path);
710 }
711 }
712
713 return;
714 }
715
716 // Couldn't find an object with that name. return an error
717 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
718}
719
Patrick Williams504af5a2025-02-03 14:29:03 -0500720inline void handleChassisGet(
721 App& app, const crow::Request& req,
722 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
723 const std::string& chassisId)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000724{
725 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
726 {
727 return;
728 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000729
George Liue99073f2022-12-09 11:06:16 +0800730 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700731 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Chau Ly7164bc62023-10-15 14:55:30 +0000732 std::bind_front(handleChassisGetSubTree, asyncResp, chassisId));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000733
Chau Ly7164bc62023-10-15 14:55:30 +0000734 constexpr std::array<std::string_view, 1> interfaces2 = {
735 "xyz.openbmc_project.Chassis.Intrusion"};
Nan Zhoucf7eba02022-07-21 23:53:20 +0000736
Chau Ly7164bc62023-10-15 14:55:30 +0000737 dbus::utility::getSubTree(
738 "/xyz/openbmc_project", 0, interfaces2,
739 std::bind_front(handlePhysicalSecurityGetSubTree, asyncResp));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000740}
741
Patrick Williams504af5a2025-02-03 14:29:03 -0500742inline void handleChassisPatch(
743 App& app, const crow::Request& req,
744 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
745 const std::string& param)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000746{
747 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
748 {
749 return;
750 }
751 std::optional<bool> locationIndicatorActive;
752 std::optional<std::string> indicatorLed;
753
754 if (param.empty())
755 {
756 return;
757 }
758
Patrick Williams504af5a2025-02-03 14:29:03 -0500759 if (!json_util::readJsonPatch( //
760 req, asyncResp->res, //
761 "IndicatorLED", indicatorLed, //
Myung Baeafc474a2024-10-09 00:53:29 -0700762 "LocationIndicatorActive", locationIndicatorActive //
763 ))
Nan Zhoucf7eba02022-07-21 23:53:20 +0000764 {
765 return;
766 }
767
768 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
769 if (!locationIndicatorActive && !indicatorLed)
770 {
771 return; // delete this when we support more patch properties
772 }
773 if (indicatorLed)
774 {
775 asyncResp->res.addHeader(
776 boost::beast::http::field::warning,
777 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
778 }
779
Nan Zhoucf7eba02022-07-21 23:53:20 +0000780 const std::string& chassisId = param;
781
George Liue99073f2022-12-09 11:06:16 +0800782 dbus::utility::getSubTree(
Myung Bae3f95a272024-03-13 07:32:02 -0700783 "/xyz/openbmc_project/inventory", 0, chassisInterfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000784 [asyncResp, chassisId, locationIndicatorActive,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800785 indicatorLed](const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000786 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400787 if (ec)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000788 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400789 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
790 messages::internalError(asyncResp->res);
791 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000792 }
793
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400794 // Iterate over all retrieved ObjectPaths.
795 for (const std::pair<std::string,
796 std::vector<std::pair<
797 std::string, std::vector<std::string>>>>&
798 object : subtree)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000799 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400800 const std::string& path = object.first;
801 const std::vector<
802 std::pair<std::string, std::vector<std::string>>>&
803 connectionNames = object.second;
804
805 sdbusplus::message::object_path objPath(path);
806 if (objPath.filename() != chassisId)
807 {
808 continue;
809 }
810
811 if (connectionNames.empty())
812 {
813 BMCWEB_LOG_ERROR("Got 0 Connection names");
814 continue;
815 }
816
817 const std::vector<std::string>& interfaces3 =
818 connectionNames[0].second;
819
820 const std::array<const char*, 3> hasIndicatorLed = {
821 "xyz.openbmc_project.Inventory.Item.Chassis",
822 "xyz.openbmc_project.Inventory.Item.Panel",
823 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
824 bool indicatorChassis = false;
825 for (const char* interface : hasIndicatorLed)
826 {
827 if (std::ranges::find(interfaces3, interface) !=
828 interfaces3.end())
829 {
830 indicatorChassis = true;
831 break;
832 }
833 }
834 if (locationIndicatorActive)
835 {
836 if (indicatorChassis)
837 {
838 setSystemLocationIndicatorActive(
839 asyncResp, *locationIndicatorActive);
840 }
841 else
842 {
843 messages::propertyUnknown(asyncResp->res,
844 "LocationIndicatorActive");
845 }
846 }
847 if (indicatorLed)
848 {
849 if (indicatorChassis)
850 {
851 setIndicatorLedState(asyncResp, *indicatorLed);
852 }
853 else
854 {
855 messages::propertyUnknown(asyncResp->res,
856 "IndicatorLED");
857 }
858 }
859 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000860 }
861
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400862 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
863 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000864}
865
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100866/**
867 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700868 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100869 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700870inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700871{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700872 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700873 .privileges(redfish::privileges::getChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700874 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000875 std::bind_front(handleChassisGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700876
877 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700878 .privileges(redfish::privileges::patchChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700879 .methods(boost::beast::http::verb::patch)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000880 std::bind_front(handleChassisPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700881}
P.K. Leedd99e042020-06-17 19:43:16 +0800882
Patrick Williams504af5a2025-02-03 14:29:03 -0500883inline void doChassisPowerCycle(
884 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800885{
George Liu7a1dbc42022-12-07 16:03:22 +0800886 constexpr std::array<std::string_view, 1> interfaces = {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700887 "xyz.openbmc_project.State.Chassis"};
888
889 // Use mapper to get subtree paths.
George Liu7a1dbc42022-12-07 16:03:22 +0800890 dbus::utility::getSubTreePaths(
891 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800892 [asyncResp](
George Liu7a1dbc42022-12-07 16:03:22 +0800893 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800894 const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400895 if (ec)
896 {
897 BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec);
898 messages::internalError(asyncResp->res);
899 return;
900 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700901
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400902 const char* processName = "xyz.openbmc_project.State.Chassis";
903 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
904 const char* destProperty = "RequestedPowerTransition";
905 const std::string propertyValue =
906 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
907 std::string objectPath =
908 "/xyz/openbmc_project/state/chassis_system0";
Ed Tanous002d39b2022-05-31 08:59:27 -0700909
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400910 /* Look for system reset chassis path */
911 if ((std::ranges::find(chassisList, objectPath)) ==
912 chassisList.end())
913 {
914 /* We prefer to reset the full chassis_system, but if it doesn't
915 * exist on some platforms, fall back to a host-only power reset
916 */
917 objectPath = "/xyz/openbmc_project/state/chassis0";
918 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700919
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400920 setDbusProperty(asyncResp, "ResetType", processName, objectPath,
921 interfaceName, destProperty, propertyValue);
922 });
P.K. Leedd99e042020-06-17 19:43:16 +0800923}
924
Nan Zhoucf7eba02022-07-21 23:53:20 +0000925inline void handleChassisResetActionInfoPost(
926 App& app, const crow::Request& req,
927 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
928 const std::string& /*chassisId*/)
929{
930 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
931 {
932 return;
933 }
Ed Tanous62598e32023-07-17 17:06:25 -0700934 BMCWEB_LOG_DEBUG("Post Chassis Reset.");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000935
936 std::string resetType;
937
938 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
939 {
940 return;
941 }
942
943 if (resetType != "PowerCycle")
944 {
Ed Tanous62598e32023-07-17 17:06:25 -0700945 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000946 messages::actionParameterNotSupported(asyncResp->res, resetType,
947 "ResetType");
948
949 return;
950 }
951 doChassisPowerCycle(asyncResp);
952}
953
P.K. Leedd99e042020-06-17 19:43:16 +0800954/**
955 * ChassisResetAction class supports the POST method for the Reset
956 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700957 * Function handles POST method request.
958 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800959 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700960
961inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800962{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700963 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700964 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700965 .methods(boost::beast::http::verb::post)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000966 std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
967}
P.K. Leedd99e042020-06-17 19:43:16 +0800968
Nan Zhoucf7eba02022-07-21 23:53:20 +0000969inline void handleChassisResetActionInfoGet(
970 App& app, const crow::Request& req,
971 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
972 const std::string& chassisId)
973{
974 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
975 {
976 return;
977 }
978 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700979 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
980 "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000981 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
P.K. Leedd99e042020-06-17 19:43:16 +0800982
Nan Zhoucf7eba02022-07-21 23:53:20 +0000983 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
984 nlohmann::json::array_t parameters;
985 nlohmann::json::object_t parameter;
986 parameter["Name"] = "ResetType";
987 parameter["Required"] = true;
Ed Tanous539d8c62024-06-19 14:38:27 -0700988 parameter["DataType"] = action_info::ParameterTypes::String;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000989 nlohmann::json::array_t allowed;
Patrick Williamsad539542023-05-12 10:10:08 -0500990 allowed.emplace_back("PowerCycle");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000991 parameter["AllowableValues"] = std::move(allowed);
Patrick Williamsad539542023-05-12 10:10:08 -0500992 parameters.emplace_back(std::move(parameter));
P.K. Leedd99e042020-06-17 19:43:16 +0800993
Nan Zhoucf7eba02022-07-21 23:53:20 +0000994 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700995}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530996
997/**
998 * ChassisResetActionInfo derived class for delivering Chassis
999 * ResetType AllowableValues using ResetInfo schema.
1000 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001001inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05301002{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001003 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -07001004 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001005 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +00001006 std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001007}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05301008
Ed Tanous1abe55e2018-09-05 08:30:59 -07001009} // namespace redfish