blob: 469c903bce974fbdace0ed22ec5f09ca2a7108ec [file] [log] [blame]
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Willy Tu13451e32023-05-24 16:08:18 -070018#include "bmcweb_config.h"
19
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080020#include "app.hpp"
George Liu7a1dbc42022-12-07 16:03:22 +080021#include "dbus_utility.hpp"
James Feistb49ac872019-05-21 15:12:01 -070022#include "health.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080023#include "led.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/collection.hpp"
27#include "utils/dbus_utils.hpp"
Nan Zhoucf7eba02022-07-21 23:53:20 +000028#include "utils/json_utils.hpp"
Ed Tanous1abe55e2018-09-05 08:30:59 -070029
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>
Jonathan Doman1e1e5982021-06-11 09:36:17 -070032#include <sdbusplus/asio/property.hpp>
Andrew Geisslerfc903b32023-05-31 14:15:42 -040033#include <sdbusplus/message.hpp>
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +020034#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050035
George Liu7a1dbc42022-12-07 16:03:22 +080036#include <array>
Ed Tanous3544d2a2023-08-06 18:12:20 -070037#include <ranges>
George Liu7a1dbc42022-12-07 16:03:22 +080038#include <string_view>
39
Ed Tanous1abe55e2018-09-05 08:30:59 -070040namespace redfish
41{
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +010042
43/**
Willy Tu5e577bc2022-07-26 00:41:55 +000044 * @brief Retrieves resources over dbus to link to the chassis
45 *
46 * @param[in] asyncResp - Shared pointer for completing asynchronous
47 * calls
48 * @param[in] path - Chassis dbus path to look for the storage.
49 *
50 * Calls the Association endpoints on the path + "/storage" and add the link of
51 * json["Links"]["Storage@odata.count"] =
52 * {"@odata.id", "/redfish/v1/Storage/" + resourceId}
53 *
54 * @return None.
55 */
56inline void getStorageLink(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
57 const sdbusplus::message::object_path& path)
58{
59 sdbusplus::asio::getProperty<std::vector<std::string>>(
60 *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper",
61 (path / "storage").str, "xyz.openbmc_project.Association", "endpoints",
Willy Tud4b054c2023-06-12 15:18:45 -070062 [asyncResp](const boost::system::error_code& ec,
Willy Tu5e577bc2022-07-26 00:41:55 +000063 const std::vector<std::string>& storageList) {
64 if (ec)
65 {
Ed Tanous62598e32023-07-17 17:06:25 -070066 BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error");
Willy Tu5e577bc2022-07-26 00:41:55 +000067 return;
68 }
69
70 nlohmann::json::array_t storages;
71 for (const std::string& storagePath : storageList)
72 {
73 std::string id =
74 sdbusplus::message::object_path(storagePath).filename();
75 if (id.empty())
76 {
77 continue;
78 }
79
80 nlohmann::json::object_t storage;
81 storage["@odata.id"] = boost::urls::format(
82 "/redfish/v1/Systems/system/Storage/{}", id);
83 storages.emplace_back(std::move(storage));
84 }
85 asyncResp->res.jsonValue["Links"]["Storage@odata.count"] =
86 storages.size();
87 asyncResp->res.jsonValue["Links"]["Storage"] = std::move(storages);
Patrick Williams5a39f772023-10-20 11:20:21 -050088 });
Willy Tu5e577bc2022-07-26 00:41:55 +000089}
90
91/**
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060092 * @brief Retrieves chassis state properties over dbus
93 *
Ed Tanousac106bf2023-06-07 09:24:59 -070094 * @param[in] asyncResp - Shared pointer for completing asynchronous calls.
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060095 *
96 * @return None.
97 */
Ed Tanousac106bf2023-06-07 09:24:59 -070098inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> asyncResp)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -060099{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700100 // crow::connections::systemBus->async_method_call(
101 sdbusplus::asio::getProperty<std::string>(
102 *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
103 "/xyz/openbmc_project/state/chassis0",
104 "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
Ed Tanousac106bf2023-06-07 09:24:59 -0700105 [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec,
106 const std::string& chassisState) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700107 if (ec)
108 {
109 if (ec == boost::system::errc::host_unreachable)
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600110 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700111 // Service not available, no error, just don't return
112 // chassis state info
Ed Tanous62598e32023-07-17 17:06:25 -0700113 BMCWEB_LOG_DEBUG("Service not available {}", ec);
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600114 return;
115 }
Ed Tanous62598e32023-07-17 17:06:25 -0700116 BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
Ed Tanousac106bf2023-06-07 09:24:59 -0700117 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700118 return;
119 }
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600120
Ed Tanous62598e32023-07-17 17:06:25 -0700121 BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState);
Ed Tanous002d39b2022-05-31 08:59:27 -0700122 // Verify Chassis State
123 if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On")
124 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700125 asyncResp->res.jsonValue["PowerState"] = "On";
126 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
Ed Tanous002d39b2022-05-31 08:59:27 -0700127 }
128 else if (chassisState ==
129 "xyz.openbmc_project.State.Chassis.PowerState.Off")
130 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700131 asyncResp->res.jsonValue["PowerState"] = "Off";
132 asyncResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
Ed Tanous002d39b2022-05-31 08:59:27 -0700133 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500134 });
Gunnar Millsbeeca0a2019-02-14 16:30:45 -0600135}
136
Ed Tanousac106bf2023-06-07 09:24:59 -0700137inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000138 const std::string& service,
139 const std::string& objPath)
Qiang XUc1819422019-02-27 13:51:32 +0800140{
Ed Tanous62598e32023-07-17 17:06:25 -0700141 BMCWEB_LOG_DEBUG("Get intrusion status by service ");
Qiang XUc1819422019-02-27 13:51:32 +0800142
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700143 sdbusplus::asio::getProperty<std::string>(
144 *crow::connections::systemBus, service, objPath,
145 "xyz.openbmc_project.Chassis.Intrusion", "Status",
Ed Tanousac106bf2023-06-07 09:24:59 -0700146 [asyncResp{std::move(asyncResp)}](const boost::system::error_code& ec,
147 const std::string& value) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700148 if (ec)
149 {
150 // do not add err msg in redfish response, because this is not
151 // mandatory property
Ed Tanous62598e32023-07-17 17:06:25 -0700152 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700153 return;
154 }
Qiang XUc1819422019-02-27 13:51:32 +0800155
Ed Tanousac106bf2023-06-07 09:24:59 -0700156 asyncResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] =
157 1;
158 asyncResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value;
Patrick Williams5a39f772023-10-20 11:20:21 -0500159 });
Qiang XUc1819422019-02-27 13:51:32 +0800160}
161
162/**
163 * Retrieves physical security properties over dbus
164 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700165inline void
166 getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> asyncResp)
Qiang XUc1819422019-02-27 13:51:32 +0800167{
George Liue99073f2022-12-09 11:06:16 +0800168 constexpr std::array<std::string_view, 1> interfaces = {
169 "xyz.openbmc_project.Chassis.Intrusion"};
170 dbus::utility::getSubTree(
Chau Ly630adcd2023-02-20 07:26:23 +0000171 "/xyz/openbmc_project", 0, interfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700172 [asyncResp{std::move(asyncResp)}](
George Liue99073f2022-12-09 11:06:16 +0800173 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800174 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700175 if (ec)
176 {
177 // do not add err msg in redfish response, because this is not
178 // mandatory property
Ed Tanous62598e32023-07-17 17:06:25 -0700179 BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700180 return;
181 }
182 // Iterate over all retrieved ObjectPaths.
183 for (const auto& object : subtree)
184 {
Patrick Williams840a9ff2023-05-12 10:18:43 -0500185 if (!object.second.empty())
Qiang XUc1819422019-02-27 13:51:32 +0800186 {
Patrick Williams840a9ff2023-05-12 10:18:43 -0500187 const auto service = object.second.front();
Ed Tanousac106bf2023-06-07 09:24:59 -0700188 getIntrusionByService(asyncResp, service.first, object.first);
Qiang XUc1819422019-02-27 13:51:32 +0800189 return;
190 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700191 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500192 });
Qiang XUc1819422019-02-27 13:51:32 +0800193}
194
Nan Zhoucf7eba02022-07-21 23:53:20 +0000195inline void handleChassisCollectionGet(
196 App& app, const crow::Request& req,
197 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
198{
199 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
200 {
201 return;
202 }
203 asyncResp->res.jsonValue["@odata.type"] =
204 "#ChassisCollection.ChassisCollection";
205 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
206 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
207
George Liu7a1dbc42022-12-07 16:03:22 +0800208 constexpr std::array<std::string_view, 2> interfaces{
209 "xyz.openbmc_project.Inventory.Item.Board",
210 "xyz.openbmc_project.Inventory.Item.Chassis"};
Nan Zhoucf7eba02022-07-21 23:53:20 +0000211 collection_util::getCollectionMembers(
Lakshmi Yadlapati36b5f1e2023-09-26 23:53:28 -0500212 asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces,
213 "/xyz/openbmc_project/inventory");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000214}
215
Jie Yanga5617492021-06-29 12:59:14 -0700216inline void getChassisContainedBy(
217 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
218 const std::string& chassisId, const boost::system::error_code& ec,
219 const dbus::utility::MapperEndPoints& upstreamChassisPaths)
220{
221 if (ec)
222 {
223 if (ec.value() != EBADR)
224 {
Ed Tanous62598e32023-07-17 17:06:25 -0700225 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700226 messages::internalError(asyncResp->res);
227 }
228 return;
229 }
230 if (upstreamChassisPaths.empty())
231 {
232 return;
233 }
234 if (upstreamChassisPaths.size() > 1)
235 {
Ed Tanous62598e32023-07-17 17:06:25 -0700236 BMCWEB_LOG_ERROR("{} is contained by mutliple chassis", chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700237 messages::internalError(asyncResp->res);
238 return;
239 }
240
241 sdbusplus::message::object_path upstreamChassisPath(
242 upstreamChassisPaths[0]);
243 std::string upstreamChassis = upstreamChassisPath.filename();
244 if (upstreamChassis.empty())
245 {
Ed Tanous62598e32023-07-17 17:06:25 -0700246 BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}",
247 upstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700248 return;
249 }
250
251 asyncResp->res.jsonValue["Links"]["ContainedBy"]["@odata.id"] =
252 boost::urls::format("/redfish/v1/Chassis/{}", upstreamChassis);
253}
254
255inline void getChassisContains(
256 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
257 const std::string& chassisId, const boost::system::error_code& ec,
258 const dbus::utility::MapperEndPoints& downstreamChassisPaths)
259{
260 if (ec)
261 {
262 if (ec.value() != EBADR)
263 {
Ed Tanous62598e32023-07-17 17:06:25 -0700264 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Jie Yanga5617492021-06-29 12:59:14 -0700265 messages::internalError(asyncResp->res);
266 }
267 return;
268 }
269 if (downstreamChassisPaths.empty())
270 {
271 return;
272 }
273 nlohmann::json& jValue = asyncResp->res.jsonValue["Links"]["Contains"];
274 if (!jValue.is_array())
275 {
276 // Create the array if it was empty
277 jValue = nlohmann::json::array();
278 }
279 for (const auto& p : downstreamChassisPaths)
280 {
281 sdbusplus::message::object_path downstreamChassisPath(p);
282 std::string downstreamChassis = downstreamChassisPath.filename();
283 if (downstreamChassis.empty())
284 {
Ed Tanous62598e32023-07-17 17:06:25 -0700285 BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}",
286 downstreamChassisPath.str, chassisId);
Jie Yanga5617492021-06-29 12:59:14 -0700287 continue;
288 }
289 nlohmann::json link;
290 link["@odata.id"] = boost::urls::format("/redfish/v1/Chassis/{}",
291 downstreamChassis);
292 jValue.push_back(std::move(link));
293 }
294 asyncResp->res.jsonValue["Links"]["Contains@odata.count"] = jValue.size();
295}
296
297inline void
298 getChassisConnectivity(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
299 const std::string& chassisId,
300 const std::string& chassisPath)
301{
Ed Tanous62598e32023-07-17 17:06:25 -0700302 BMCWEB_LOG_DEBUG("Get chassis connectivity");
Jie Yanga5617492021-06-29 12:59:14 -0700303
304 dbus::utility::getAssociationEndPoints(
305 chassisPath + "/contained_by",
306 std::bind_front(getChassisContainedBy, asyncResp, chassisId));
307
308 dbus::utility::getAssociationEndPoints(
309 chassisPath + "/containing",
310 std::bind_front(getChassisContains, asyncResp, chassisId));
311}
312
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100313/**
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100314 * ChassisCollection derived class for delivering Chassis Collection Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700315 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100316 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700317inline void requestRoutesChassisCollection(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700318{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700319 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/")
Ed Tanoused398212021-06-09 17:05:54 -0700320 .privileges(redfish::privileges::getChassisCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700321 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000322 std::bind_front(handleChassisCollectionGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700323}
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100324
Willy Tu308f70c2021-09-28 20:24:52 -0700325inline void
326 getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
327 const std::string& connectionName,
328 const std::string& path)
329{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700330 sdbusplus::asio::getProperty<std::string>(
331 *crow::connections::systemBus, connectionName, path,
332 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800333 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700334 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700335 if (ec)
336 {
Ed Tanous62598e32023-07-17 17:06:25 -0700337 BMCWEB_LOG_ERROR("DBUS response error for Location");
Ed Tanous002d39b2022-05-31 08:59:27 -0700338 messages::internalError(asyncResp->res);
339 return;
340 }
Willy Tu308f70c2021-09-28 20:24:52 -0700341
Ed Tanous002d39b2022-05-31 08:59:27 -0700342 asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
343 property;
Patrick Williams5a39f772023-10-20 11:20:21 -0500344 });
Willy Tu308f70c2021-09-28 20:24:52 -0700345}
346
347inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
348 const std::string& connectionName,
349 const std::string& path)
350{
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700351 sdbusplus::asio::getProperty<std::string>(
352 *crow::connections::systemBus, connectionName, path,
353 "xyz.openbmc_project.Common.UUID", "UUID",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800354 [asyncResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700355 const std::string& chassisUUID) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700356 if (ec)
357 {
Ed Tanous62598e32023-07-17 17:06:25 -0700358 BMCWEB_LOG_ERROR("DBUS response error for UUID");
Ed Tanous002d39b2022-05-31 08:59:27 -0700359 messages::internalError(asyncResp->res);
360 return;
361 }
362 asyncResp->res.jsonValue["UUID"] = chassisUUID;
Patrick Williams5a39f772023-10-20 11:20:21 -0500363 });
Willy Tu308f70c2021-09-28 20:24:52 -0700364}
365
Nan Zhoucf7eba02022-07-21 23:53:20 +0000366inline void
367 handleChassisGet(App& app, const crow::Request& req,
368 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
369 const std::string& chassisId)
370{
371 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
372 {
373 return;
374 }
George Liue99073f2022-12-09 11:06:16 +0800375 constexpr std::array<std::string_view, 2> interfaces = {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000376 "xyz.openbmc_project.Inventory.Item.Board",
377 "xyz.openbmc_project.Inventory.Item.Chassis"};
378
George Liue99073f2022-12-09 11:06:16 +0800379 dbus::utility::getSubTree(
380 "/xyz/openbmc_project/inventory", 0, interfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000381 [asyncResp, chassisId(std::string(chassisId))](
George Liue99073f2022-12-09 11:06:16 +0800382 const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000383 const dbus::utility::MapperGetSubTreeResponse& subtree) {
384 if (ec)
385 {
Ed Tanous62598e32023-07-17 17:06:25 -0700386 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000387 messages::internalError(asyncResp->res);
388 return;
389 }
390 // Iterate over all retrieved ObjectPaths.
391 for (const std::pair<
392 std::string,
393 std::vector<std::pair<std::string, std::vector<std::string>>>>&
394 object : subtree)
395 {
396 const std::string& path = object.first;
397 const std::vector<std::pair<std::string, std::vector<std::string>>>&
398 connectionNames = object.second;
399
400 sdbusplus::message::object_path objPath(path);
401 if (objPath.filename() != chassisId)
402 {
403 continue;
404 }
405
Jie Yanga5617492021-06-29 12:59:14 -0700406 getChassisConnectivity(asyncResp, chassisId, path);
407
Nan Zhoucf7eba02022-07-21 23:53:20 +0000408 auto health = std::make_shared<HealthPopulate>(asyncResp);
409
Willy Tu13451e32023-05-24 16:08:18 -0700410 if constexpr (bmcwebEnableHealthPopulate)
411 {
412 dbus::utility::getAssociationEndPoints(
413 path + "/all_sensors",
414 [health](const boost::system::error_code& ec2,
415 const dbus::utility::MapperEndPoints& resp) {
416 if (ec2)
417 {
418 return; // no sensors = no failures
419 }
420 health->inventory = resp;
Patrick Williams5a39f772023-10-20 11:20:21 -0500421 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000422
Willy Tu13451e32023-05-24 16:08:18 -0700423 health->populate();
424 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000425
426 if (connectionNames.empty())
427 {
Ed Tanous62598e32023-07-17 17:06:25 -0700428 BMCWEB_LOG_ERROR("Got 0 Connection names");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000429 continue;
430 }
431
432 asyncResp->res.jsonValue["@odata.type"] =
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530433 "#Chassis.v1_22_0.Chassis";
Nan Zhoucf7eba02022-07-21 23:53:20 +0000434 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700435 boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000436 asyncResp->res.jsonValue["Name"] = "Chassis Collection";
437 asyncResp->res.jsonValue["ChassisType"] = "RackMount";
438 asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700439 boost::urls::format(
440 "/redfish/v1/Chassis/{}/Actions/Chassis.Reset", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000441 asyncResp->res
442 .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700443 boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo",
444 chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000445 asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700446 "/redfish/v1/Systems/system/PCIeDevices";
Nan Zhoucf7eba02022-07-21 23:53:20 +0000447
George Liu6c3e9452023-03-03 13:55:29 +0800448 dbus::utility::getAssociationEndPoints(
449 path + "/drive",
450 [asyncResp,
451 chassisId](const boost::system::error_code& ec3,
452 const dbus::utility::MapperEndPoints& resp) {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000453 if (ec3 || resp.empty())
454 {
455 return; // no drives = no failures
456 }
457
458 nlohmann::json reference;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700459 reference["@odata.id"] = boost::urls::format(
460 "/redfish/v1/Chassis/{}/Drives", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000461 asyncResp->res.jsonValue["Drives"] = std::move(reference);
Patrick Williams5a39f772023-10-20 11:20:21 -0500462 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000463
464 const std::string& connectionName = connectionNames[0].first;
465
466 const std::vector<std::string>& interfaces2 =
467 connectionNames[0].second;
468 const std::array<const char*, 2> hasIndicatorLed = {
469 "xyz.openbmc_project.Inventory.Item.Panel",
470 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
471
472 const std::string assetTagInterface =
473 "xyz.openbmc_project.Inventory.Decorator.AssetTag";
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530474 const std::string replaceableInterface =
475 "xyz.openbmc_project.Inventory.Decorator.Replaceable";
476 for (const auto& interface : interfaces2)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000477 {
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530478 if (interface == assetTagInterface)
479 {
480 sdbusplus::asio::getProperty<std::string>(
481 *crow::connections::systemBus, connectionName, path,
482 assetTagInterface, "AssetTag",
483 [asyncResp,
484 chassisId](const boost::system::error_code& ec2,
485 const std::string& property) {
486 if (ec2)
487 {
Ed Tanous62598e32023-07-17 17:06:25 -0700488 BMCWEB_LOG_ERROR(
489 "DBus response error for AssetTag: {}", ec2);
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530490 messages::internalError(asyncResp->res);
491 return;
492 }
493 asyncResp->res.jsonValue["AssetTag"] = property;
Patrick Williams5a39f772023-10-20 11:20:21 -0500494 });
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530495 }
496 else if (interface == replaceableInterface)
497 {
498 sdbusplus::asio::getProperty<bool>(
499 *crow::connections::systemBus, connectionName, path,
500 replaceableInterface, "HotPluggable",
501 [asyncResp,
502 chassisId](const boost::system::error_code& ec2,
503 const bool property) {
504 if (ec2)
505 {
Ed Tanous62598e32023-07-17 17:06:25 -0700506 BMCWEB_LOG_ERROR(
507 "DBus response error for HotPluggable: {}",
508 ec2);
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530509 messages::internalError(asyncResp->res);
510 return;
511 }
512 asyncResp->res.jsonValue["HotPluggable"] = property;
Patrick Williams5a39f772023-10-20 11:20:21 -0500513 });
Logananth Sundararaj523d4862023-01-24 11:56:28 +0530514 }
Nan Zhoucf7eba02022-07-21 23:53:20 +0000515 }
516
517 for (const char* interface : hasIndicatorLed)
518 {
Ed Tanous3544d2a2023-08-06 18:12:20 -0700519 if (std::ranges::find(interfaces2, interface) !=
520 interfaces2.end())
Nan Zhoucf7eba02022-07-21 23:53:20 +0000521 {
522 getIndicatorLedState(asyncResp);
523 getLocationIndicatorActive(asyncResp);
524 break;
525 }
526 }
527
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200528 sdbusplus::asio::getAllProperties(
529 *crow::connections::systemBus, connectionName, path,
530 "xyz.openbmc_project.Inventory.Decorator.Asset",
Willy Tu5e577bc2022-07-26 00:41:55 +0000531 [asyncResp, chassisId(std::string(chassisId)),
532 path](const boost::system::error_code& /*ec2*/,
533 const dbus::utility::DBusPropertiesMap& propertiesList) {
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200534 const std::string* partNumber = nullptr;
535 const std::string* serialNumber = nullptr;
536 const std::string* manufacturer = nullptr;
537 const std::string* model = nullptr;
538 const std::string* sparePartNumber = nullptr;
539
540 const bool success = sdbusplus::unpackPropertiesNoThrow(
541 dbus_utils::UnpackErrorPrinter(), propertiesList,
542 "PartNumber", partNumber, "SerialNumber", serialNumber,
543 "Manufacturer", manufacturer, "Model", model,
544 "SparePartNumber", sparePartNumber);
545
546 if (!success)
Nan Zhoucf7eba02022-07-21 23:53:20 +0000547 {
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200548 messages::internalError(asyncResp->res);
549 return;
Nan Zhoucf7eba02022-07-21 23:53:20 +0000550 }
Krzysztof Grobelny86d89ed2022-08-29 14:49:20 +0200551
552 if (partNumber != nullptr)
553 {
554 asyncResp->res.jsonValue["PartNumber"] = *partNumber;
555 }
556
557 if (serialNumber != nullptr)
558 {
559 asyncResp->res.jsonValue["SerialNumber"] = *serialNumber;
560 }
561
562 if (manufacturer != nullptr)
563 {
564 asyncResp->res.jsonValue["Manufacturer"] = *manufacturer;
565 }
566
567 if (model != nullptr)
568 {
569 asyncResp->res.jsonValue["Model"] = *model;
570 }
571
572 // SparePartNumber is optional on D-Bus
573 // so skip if it is empty
574 if (sparePartNumber != nullptr && !sparePartNumber->empty())
575 {
576 asyncResp->res.jsonValue["SparePartNumber"] =
577 *sparePartNumber;
578 }
579
Nan Zhoucf7eba02022-07-21 23:53:20 +0000580 asyncResp->res.jsonValue["Name"] = chassisId;
581 asyncResp->res.jsonValue["Id"] = chassisId;
582#ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL
583 asyncResp->res.jsonValue["Thermal"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700584 boost::urls::format("/redfish/v1/Chassis/{}/Thermal",
585 chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000586 // Power object
587 asyncResp->res.jsonValue["Power"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700588 boost::urls::format("/redfish/v1/Chassis/{}/Power",
589 chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000590#endif
Xiaochao Ma29739632021-03-02 15:53:13 +0800591#ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM
592 asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700593 boost::urls::format(
594 "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
Chicago Duan77b36432021-02-05 15:48:26 +0800595 asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700596 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem",
597 chassisId);
Albert Zhang4ca3ec32021-06-13 14:39:38 +0800598 asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700599 boost::urls::format(
600 "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId);
Xiaochao Ma29739632021-03-02 15:53:13 +0800601#endif
Nan Zhoucf7eba02022-07-21 23:53:20 +0000602 // SensorCollection
603 asyncResp->res.jsonValue["Sensors"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -0700604 boost::urls::format("/redfish/v1/Chassis/{}/Sensors",
605 chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000606 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
607
608 nlohmann::json::array_t computerSystems;
609 nlohmann::json::object_t system;
610 system["@odata.id"] = "/redfish/v1/Systems/system";
Patrick Williamsad539542023-05-12 10:10:08 -0500611 computerSystems.emplace_back(std::move(system));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000612 asyncResp->res.jsonValue["Links"]["ComputerSystems"] =
613 std::move(computerSystems);
614
615 nlohmann::json::array_t managedBy;
616 nlohmann::json::object_t manager;
617 manager["@odata.id"] = "/redfish/v1/Managers/bmc";
Patrick Williamsad539542023-05-12 10:10:08 -0500618 managedBy.emplace_back(std::move(manager));
Nan Zhoucf7eba02022-07-21 23:53:20 +0000619 asyncResp->res.jsonValue["Links"]["ManagedBy"] =
620 std::move(managedBy);
621 getChassisState(asyncResp);
Willy Tu5e577bc2022-07-26 00:41:55 +0000622 getStorageLink(asyncResp, path);
Patrick Williams5a39f772023-10-20 11:20:21 -0500623 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000624
625 for (const auto& interface : interfaces2)
626 {
627 if (interface == "xyz.openbmc_project.Common.UUID")
628 {
629 getChassisUUID(asyncResp, connectionName, path);
630 }
631 else if (interface ==
632 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
633 {
634 getChassisLocationCode(asyncResp, connectionName, path);
635 }
636 }
637
638 return;
639 }
640
641 // Couldn't find an object with that name. return an error
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800642 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
Patrick Williams5a39f772023-10-20 11:20:21 -0500643 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000644
645 getPhysicalSecurityData(asyncResp);
646}
647
648inline void
649 handleChassisPatch(App& app, const crow::Request& req,
650 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
651 const std::string& param)
652{
653 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
654 {
655 return;
656 }
657 std::optional<bool> locationIndicatorActive;
658 std::optional<std::string> indicatorLed;
659
660 if (param.empty())
661 {
662 return;
663 }
664
665 if (!json_util::readJsonPatch(
666 req, asyncResp->res, "LocationIndicatorActive",
667 locationIndicatorActive, "IndicatorLED", indicatorLed))
668 {
669 return;
670 }
671
672 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
673 if (!locationIndicatorActive && !indicatorLed)
674 {
675 return; // delete this when we support more patch properties
676 }
677 if (indicatorLed)
678 {
679 asyncResp->res.addHeader(
680 boost::beast::http::field::warning,
681 "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\"");
682 }
683
George Liue99073f2022-12-09 11:06:16 +0800684 constexpr std::array<std::string_view, 2> interfaces = {
Nan Zhoucf7eba02022-07-21 23:53:20 +0000685 "xyz.openbmc_project.Inventory.Item.Board",
686 "xyz.openbmc_project.Inventory.Item.Chassis"};
687
688 const std::string& chassisId = param;
689
George Liue99073f2022-12-09 11:06:16 +0800690 dbus::utility::getSubTree(
691 "/xyz/openbmc_project/inventory", 0, interfaces,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000692 [asyncResp, chassisId, locationIndicatorActive,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800693 indicatorLed](const boost::system::error_code& ec,
Nan Zhoucf7eba02022-07-21 23:53:20 +0000694 const dbus::utility::MapperGetSubTreeResponse& subtree) {
695 if (ec)
696 {
Ed Tanous62598e32023-07-17 17:06:25 -0700697 BMCWEB_LOG_ERROR("DBUS response error {}", ec);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000698 messages::internalError(asyncResp->res);
699 return;
700 }
701
702 // Iterate over all retrieved ObjectPaths.
703 for (const std::pair<
704 std::string,
705 std::vector<std::pair<std::string, std::vector<std::string>>>>&
706 object : subtree)
707 {
708 const std::string& path = object.first;
709 const std::vector<std::pair<std::string, std::vector<std::string>>>&
710 connectionNames = object.second;
711
712 sdbusplus::message::object_path objPath(path);
713 if (objPath.filename() != chassisId)
714 {
715 continue;
716 }
717
718 if (connectionNames.empty())
719 {
Ed Tanous62598e32023-07-17 17:06:25 -0700720 BMCWEB_LOG_ERROR("Got 0 Connection names");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000721 continue;
722 }
723
724 const std::vector<std::string>& interfaces3 =
725 connectionNames[0].second;
726
727 const std::array<const char*, 2> hasIndicatorLed = {
728 "xyz.openbmc_project.Inventory.Item.Panel",
729 "xyz.openbmc_project.Inventory.Item.Board.Motherboard"};
730 bool indicatorChassis = false;
731 for (const char* interface : hasIndicatorLed)
732 {
Ed Tanous3544d2a2023-08-06 18:12:20 -0700733 if (std::ranges::find(interfaces3, interface) !=
734 interfaces3.end())
Nan Zhoucf7eba02022-07-21 23:53:20 +0000735 {
736 indicatorChassis = true;
737 break;
738 }
739 }
740 if (locationIndicatorActive)
741 {
742 if (indicatorChassis)
743 {
744 setLocationIndicatorActive(asyncResp,
745 *locationIndicatorActive);
746 }
747 else
748 {
749 messages::propertyUnknown(asyncResp->res,
750 "LocationIndicatorActive");
751 }
752 }
753 if (indicatorLed)
754 {
755 if (indicatorChassis)
756 {
757 setIndicatorLedState(asyncResp, *indicatorLed);
758 }
759 else
760 {
761 messages::propertyUnknown(asyncResp->res, "IndicatorLED");
762 }
763 }
764 return;
765 }
766
Jiaqing Zhaod8a5d5d2022-08-05 16:21:51 +0800767 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
Patrick Williams5a39f772023-10-20 11:20:21 -0500768 });
Nan Zhoucf7eba02022-07-21 23:53:20 +0000769}
770
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100771/**
772 * Chassis override class for delivering Chassis Schema
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700773 * Functions triggers appropriate requests on DBus
Rapkiewicz, Pawele37f8452018-03-09 13:49:50 +0100774 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700775inline void requestRoutesChassis(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700776{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700777 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700778 .privileges(redfish::privileges::getChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700779 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000780 std::bind_front(handleChassisGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700781
782 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700783 .privileges(redfish::privileges::patchChassis)
Ed Tanous002d39b2022-05-31 08:59:27 -0700784 .methods(boost::beast::http::verb::patch)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000785 std::bind_front(handleChassisPatch, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700786}
P.K. Leedd99e042020-06-17 19:43:16 +0800787
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400788/**
789 * Handle error responses from d-bus for chassis power cycles
790 */
791inline void handleChassisPowerCycleError(const boost::system::error_code& ec,
792 const sdbusplus::message_t& eMsg,
793 crow::Response& res)
794{
795 if (eMsg.get_error() == nullptr)
796 {
Ed Tanous62598e32023-07-17 17:06:25 -0700797 BMCWEB_LOG_ERROR("D-Bus response error: {}", ec);
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400798 messages::internalError(res);
799 return;
800 }
801 std::string_view errorMessage = eMsg.get_error()->name;
802
803 // If operation failed due to BMC not being in Ready state, tell
804 // user to retry in a bit
805 if (errorMessage ==
806 std::string_view("xyz.openbmc_project.State.Chassis.Error.BMCNotReady"))
807 {
Ed Tanous62598e32023-07-17 17:06:25 -0700808 BMCWEB_LOG_DEBUG("BMC not ready, operation not allowed right now");
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400809 messages::serviceTemporarilyUnavailable(res, "10");
810 return;
811 }
812
Ed Tanous62598e32023-07-17 17:06:25 -0700813 BMCWEB_LOG_ERROR("Chassis Power Cycle fail {} sdbusplus:{}", ec,
814 errorMessage);
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400815 messages::internalError(res);
816}
817
zhanghch058d1b46d2021-04-01 11:18:24 +0800818inline void
819 doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
P.K. Leedd99e042020-06-17 19:43:16 +0800820{
George Liu7a1dbc42022-12-07 16:03:22 +0800821 constexpr std::array<std::string_view, 1> interfaces = {
Vijay Khemkac3b3c922020-09-22 23:00:12 -0700822 "xyz.openbmc_project.State.Chassis"};
823
824 // Use mapper to get subtree paths.
George Liu7a1dbc42022-12-07 16:03:22 +0800825 dbus::utility::getSubTreePaths(
826 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800827 [asyncResp](
George Liu7a1dbc42022-12-07 16:03:22 +0800828 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800829 const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700830 if (ec)
831 {
Ed Tanous62598e32023-07-17 17:06:25 -0700832 BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -0700833 messages::internalError(asyncResp->res);
834 return;
835 }
836
837 const char* processName = "xyz.openbmc_project.State.Chassis";
838 const char* interfaceName = "xyz.openbmc_project.State.Chassis";
839 const char* destProperty = "RequestedPowerTransition";
840 const std::string propertyValue =
841 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
842 std::string objectPath = "/xyz/openbmc_project/state/chassis_system0";
843
844 /* Look for system reset chassis path */
Ed Tanous3544d2a2023-08-06 18:12:20 -0700845 if ((std::ranges::find(chassisList, objectPath)) == chassisList.end())
Ed Tanous002d39b2022-05-31 08:59:27 -0700846 {
847 /* We prefer to reset the full chassis_system, but if it doesn't
848 * exist on some platforms, fall back to a host-only power reset
849 */
850 objectPath = "/xyz/openbmc_project/state/chassis0";
851 }
852
George Liu9ae226f2023-06-21 17:56:46 +0800853 sdbusplus::asio::setProperty(
854 *crow::connections::systemBus, processName, objectPath,
855 interfaceName, destProperty, propertyValue,
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400856 [asyncResp](const boost::system::error_code& ec2,
857 sdbusplus::message_t& sdbusErrMsg) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700858 // Use "Set" method to set the property value.
Ed Tanous8a592812022-06-04 09:06:59 -0700859 if (ec2)
P.K. Leedd99e042020-06-17 19:43:16 +0800860 {
Andrew Geisslerfc903b32023-05-31 14:15:42 -0400861 handleChassisPowerCycleError(ec2, sdbusErrMsg, asyncResp->res);
862
P.K. Leedd99e042020-06-17 19:43:16 +0800863 return;
864 }
865
Ed Tanous002d39b2022-05-31 08:59:27 -0700866 messages::success(asyncResp->res);
George Liu7a1dbc42022-12-07 16:03:22 +0800867 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500868 });
P.K. Leedd99e042020-06-17 19:43:16 +0800869}
870
Nan Zhoucf7eba02022-07-21 23:53:20 +0000871inline void handleChassisResetActionInfoPost(
872 App& app, const crow::Request& req,
873 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
874 const std::string& /*chassisId*/)
875{
876 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
877 {
878 return;
879 }
Ed Tanous62598e32023-07-17 17:06:25 -0700880 BMCWEB_LOG_DEBUG("Post Chassis Reset.");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000881
882 std::string resetType;
883
884 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType))
885 {
886 return;
887 }
888
889 if (resetType != "PowerCycle")
890 {
Ed Tanous62598e32023-07-17 17:06:25 -0700891 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000892 messages::actionParameterNotSupported(asyncResp->res, resetType,
893 "ResetType");
894
895 return;
896 }
897 doChassisPowerCycle(asyncResp);
898}
899
P.K. Leedd99e042020-06-17 19:43:16 +0800900/**
901 * ChassisResetAction class supports the POST method for the Reset
902 * action.
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700903 * Function handles POST method request.
904 * Analyzes POST body before sending Reset request data to D-Bus.
P.K. Leedd99e042020-06-17 19:43:16 +0800905 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700906
907inline void requestRoutesChassisResetAction(App& app)
P.K. Leedd99e042020-06-17 19:43:16 +0800908{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700909 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700910 .privileges(redfish::privileges::postChassis)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700911 .methods(boost::beast::http::verb::post)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000912 std::bind_front(handleChassisResetActionInfoPost, std::ref(app)));
913}
P.K. Leedd99e042020-06-17 19:43:16 +0800914
Nan Zhoucf7eba02022-07-21 23:53:20 +0000915inline void handleChassisResetActionInfoGet(
916 App& app, const crow::Request& req,
917 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
918 const std::string& chassisId)
919{
920 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
921 {
922 return;
923 }
924 asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700925 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
926 "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId);
Nan Zhoucf7eba02022-07-21 23:53:20 +0000927 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
P.K. Leedd99e042020-06-17 19:43:16 +0800928
Nan Zhoucf7eba02022-07-21 23:53:20 +0000929 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
930 nlohmann::json::array_t parameters;
931 nlohmann::json::object_t parameter;
932 parameter["Name"] = "ResetType";
933 parameter["Required"] = true;
934 parameter["DataType"] = "String";
935 nlohmann::json::array_t allowed;
Patrick Williamsad539542023-05-12 10:10:08 -0500936 allowed.emplace_back("PowerCycle");
Nan Zhoucf7eba02022-07-21 23:53:20 +0000937 parameter["AllowableValues"] = std::move(allowed);
Patrick Williamsad539542023-05-12 10:10:08 -0500938 parameters.emplace_back(std::move(parameter));
P.K. Leedd99e042020-06-17 19:43:16 +0800939
Nan Zhoucf7eba02022-07-21 23:53:20 +0000940 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700941}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530942
943/**
944 * ChassisResetActionInfo derived class for delivering Chassis
945 * ResetType AllowableValues using ResetInfo schema.
946 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700947inline void requestRoutesChassisResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530948{
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700949 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700950 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700951 .methods(boost::beast::http::verb::get)(
Nan Zhoucf7eba02022-07-21 23:53:20 +0000952 std::bind_front(handleChassisResetActionInfoGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700953}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530954
Ed Tanous1abe55e2018-09-05 08:30:59 -0700955} // namespace redfish