Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 1 | /* |
| 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 Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 18 | #include "bmcweb_config.h" |
| 19 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 20 | #include "app.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 21 | #include "dbus_utility.hpp" |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 22 | #include "health.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 23 | #include "led.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 24 | #include "query.hpp" |
| 25 | #include "registries/privilege_registry.hpp" |
| 26 | #include "utils/collection.hpp" |
| 27 | #include "utils/dbus_utils.hpp" |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 28 | #include "utils/json_utils.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 30 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 31 | #include <boost/url/format.hpp> |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 32 | #include <sdbusplus/asio/property.hpp> |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame^] | 33 | #include <sdbusplus/message.hpp> |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 34 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 35 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 36 | #include <array> |
| 37 | #include <string_view> |
| 38 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 39 | namespace redfish |
| 40 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 41 | |
| 42 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 43 | * @brief Retrieves chassis state properties over dbus |
| 44 | * |
| 45 | * @param[in] aResp - Shared pointer for completing asynchronous calls. |
| 46 | * |
| 47 | * @return None. |
| 48 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 49 | inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 50 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 51 | // crow::connections::systemBus->async_method_call( |
| 52 | sdbusplus::asio::getProperty<std::string>( |
| 53 | *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis", |
| 54 | "/xyz/openbmc_project/state/chassis0", |
| 55 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 56 | [aResp{std::move(aResp)}](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 57 | const std::string& chassisState) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 58 | if (ec) |
| 59 | { |
| 60 | if (ec == boost::system::errc::host_unreachable) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 61 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 62 | // Service not available, no error, just don't return |
| 63 | // chassis state info |
| 64 | BMCWEB_LOG_DEBUG << "Service not available " << ec; |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 65 | return; |
| 66 | } |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 67 | BMCWEB_LOG_ERROR << "DBUS response error " << ec; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 68 | messages::internalError(aResp->res); |
| 69 | return; |
| 70 | } |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 71 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 72 | BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState; |
| 73 | // Verify Chassis State |
| 74 | if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On") |
| 75 | { |
| 76 | aResp->res.jsonValue["PowerState"] = "On"; |
| 77 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 78 | } |
| 79 | else if (chassisState == |
| 80 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 81 | { |
| 82 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 83 | aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
| 84 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 85 | }); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 86 | } |
| 87 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 88 | inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 89 | const std::string& service, |
| 90 | const std::string& objPath) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 91 | { |
| 92 | BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; |
| 93 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 94 | sdbusplus::asio::getProperty<std::string>( |
| 95 | *crow::connections::systemBus, service, objPath, |
| 96 | "xyz.openbmc_project.Chassis.Intrusion", "Status", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 97 | [aResp{std::move(aResp)}](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 98 | const std::string& value) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 99 | if (ec) |
| 100 | { |
| 101 | // do not add err msg in redfish response, because this is not |
| 102 | // mandatory property |
| 103 | BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; |
| 104 | return; |
| 105 | } |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 106 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 107 | aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensorNumber"] = 1; |
| 108 | aResp->res.jsonValue["PhysicalSecurity"]["IntrusionSensor"] = value; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 109 | }); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Retrieves physical security properties over dbus |
| 114 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 115 | inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 116 | { |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 117 | constexpr std::array<std::string_view, 1> interfaces = { |
| 118 | "xyz.openbmc_project.Chassis.Intrusion"}; |
| 119 | dbus::utility::getSubTree( |
| 120 | "/xyz/openbmc_project/Intrusion", 1, interfaces, |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 121 | [aResp{std::move(aResp)}]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 122 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 123 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 124 | if (ec) |
| 125 | { |
| 126 | // do not add err msg in redfish response, because this is not |
| 127 | // mandatory property |
| 128 | BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec << "\n"; |
| 129 | return; |
| 130 | } |
| 131 | // Iterate over all retrieved ObjectPaths. |
| 132 | for (const auto& object : subtree) |
| 133 | { |
Patrick Williams | 840a9ff | 2023-05-12 10:18:43 -0500 | [diff] [blame] | 134 | if (!object.second.empty()) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 135 | { |
Patrick Williams | 840a9ff | 2023-05-12 10:18:43 -0500 | [diff] [blame] | 136 | const auto service = object.second.front(); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 137 | getIntrusionByService(aResp, service.first, object.first); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 138 | return; |
| 139 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 140 | } |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 141 | }); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 142 | } |
| 143 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 144 | inline void handleChassisCollectionGet( |
| 145 | App& app, const crow::Request& req, |
| 146 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 147 | { |
| 148 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | asyncResp->res.jsonValue["@odata.type"] = |
| 153 | "#ChassisCollection.ChassisCollection"; |
| 154 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
| 155 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 156 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 157 | constexpr std::array<std::string_view, 2> interfaces{ |
| 158 | "xyz.openbmc_project.Inventory.Item.Board", |
| 159 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 160 | collection_util::getCollectionMembers( |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 161 | asyncResp, boost::urls::url("/redfish/v1/Chassis"), interfaces); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 164 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 165 | * ChassisCollection derived class for delivering Chassis Collection Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 166 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 167 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 168 | inline void requestRoutesChassisCollection(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 169 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 170 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 171 | .privileges(redfish::privileges::getChassisCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 172 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 173 | std::bind_front(handleChassisCollectionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 174 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 175 | |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 176 | inline void |
| 177 | getChassisLocationCode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 178 | const std::string& connectionName, |
| 179 | const std::string& path) |
| 180 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 181 | sdbusplus::asio::getProperty<std::string>( |
| 182 | *crow::connections::systemBus, connectionName, path, |
| 183 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 184 | [asyncResp](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 185 | const std::string& property) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 186 | if (ec) |
| 187 | { |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 188 | BMCWEB_LOG_ERROR << "DBUS response error for Location"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 189 | messages::internalError(asyncResp->res); |
| 190 | return; |
| 191 | } |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 192 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 193 | asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 194 | property; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 195 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 199 | const std::string& connectionName, |
| 200 | const std::string& path) |
| 201 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 202 | sdbusplus::asio::getProperty<std::string>( |
| 203 | *crow::connections::systemBus, connectionName, path, |
| 204 | "xyz.openbmc_project.Common.UUID", "UUID", |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 205 | [asyncResp](const boost::system::error_code& ec, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 206 | const std::string& chassisUUID) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 207 | if (ec) |
| 208 | { |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 209 | BMCWEB_LOG_ERROR << "DBUS response error for UUID"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 210 | messages::internalError(asyncResp->res); |
| 211 | return; |
| 212 | } |
| 213 | asyncResp->res.jsonValue["UUID"] = chassisUUID; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 214 | }); |
Willy Tu | 308f70c | 2021-09-28 20:24:52 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 217 | inline void |
| 218 | handleChassisGet(App& app, const crow::Request& req, |
| 219 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 220 | const std::string& chassisId) |
| 221 | { |
| 222 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 223 | { |
| 224 | return; |
| 225 | } |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 226 | constexpr std::array<std::string_view, 2> interfaces = { |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 227 | "xyz.openbmc_project.Inventory.Item.Board", |
| 228 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 229 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 230 | dbus::utility::getSubTree( |
| 231 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 232 | [asyncResp, chassisId(std::string(chassisId))]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 233 | const boost::system::error_code& ec, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 234 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 235 | if (ec) |
| 236 | { |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 237 | BMCWEB_LOG_ERROR << "DBUS response error " << ec; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 238 | messages::internalError(asyncResp->res); |
| 239 | return; |
| 240 | } |
| 241 | // Iterate over all retrieved ObjectPaths. |
| 242 | for (const std::pair< |
| 243 | std::string, |
| 244 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 245 | object : subtree) |
| 246 | { |
| 247 | const std::string& path = object.first; |
| 248 | const std::vector<std::pair<std::string, std::vector<std::string>>>& |
| 249 | connectionNames = object.second; |
| 250 | |
| 251 | sdbusplus::message::object_path objPath(path); |
| 252 | if (objPath.filename() != chassisId) |
| 253 | { |
| 254 | continue; |
| 255 | } |
| 256 | |
| 257 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 258 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 259 | if constexpr (bmcwebEnableHealthPopulate) |
| 260 | { |
| 261 | dbus::utility::getAssociationEndPoints( |
| 262 | path + "/all_sensors", |
| 263 | [health](const boost::system::error_code& ec2, |
| 264 | const dbus::utility::MapperEndPoints& resp) { |
| 265 | if (ec2) |
| 266 | { |
| 267 | return; // no sensors = no failures |
| 268 | } |
| 269 | health->inventory = resp; |
| 270 | }); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 271 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 272 | health->populate(); |
| 273 | } |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 274 | |
| 275 | if (connectionNames.empty()) |
| 276 | { |
| 277 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 278 | continue; |
| 279 | } |
| 280 | |
| 281 | asyncResp->res.jsonValue["@odata.type"] = |
Logananth Sundararaj | 523d486 | 2023-01-24 11:56:28 +0530 | [diff] [blame] | 282 | "#Chassis.v1_22_0.Chassis"; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 283 | asyncResp->res.jsonValue["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 284 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 285 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 286 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
| 287 | asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"]["target"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 288 | boost::urls::format( |
| 289 | "/redfish/v1/Chassis/{}/Actions/Chassis.Reset", chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 290 | asyncResp->res |
| 291 | .jsonValue["Actions"]["#Chassis.Reset"]["@Redfish.ActionInfo"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 292 | boost::urls::format("/redfish/v1/Chassis/{}/ResetActionInfo", |
| 293 | chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 294 | asyncResp->res.jsonValue["PCIeDevices"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 295 | "/redfish/v1/Systems/system/PCIeDevices"; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 296 | |
George Liu | 6c3e945 | 2023-03-03 13:55:29 +0800 | [diff] [blame] | 297 | dbus::utility::getAssociationEndPoints( |
| 298 | path + "/drive", |
| 299 | [asyncResp, |
| 300 | chassisId](const boost::system::error_code& ec3, |
| 301 | const dbus::utility::MapperEndPoints& resp) { |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 302 | if (ec3 || resp.empty()) |
| 303 | { |
| 304 | return; // no drives = no failures |
| 305 | } |
| 306 | |
| 307 | nlohmann::json reference; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 308 | reference["@odata.id"] = boost::urls::format( |
| 309 | "/redfish/v1/Chassis/{}/Drives", chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 310 | asyncResp->res.jsonValue["Drives"] = std::move(reference); |
| 311 | }); |
| 312 | |
| 313 | const std::string& connectionName = connectionNames[0].first; |
| 314 | |
| 315 | const std::vector<std::string>& interfaces2 = |
| 316 | connectionNames[0].second; |
| 317 | const std::array<const char*, 2> hasIndicatorLed = { |
| 318 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 319 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 320 | |
| 321 | const std::string assetTagInterface = |
| 322 | "xyz.openbmc_project.Inventory.Decorator.AssetTag"; |
Logananth Sundararaj | 523d486 | 2023-01-24 11:56:28 +0530 | [diff] [blame] | 323 | const std::string replaceableInterface = |
| 324 | "xyz.openbmc_project.Inventory.Decorator.Replaceable"; |
| 325 | for (const auto& interface : interfaces2) |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 326 | { |
Logananth Sundararaj | 523d486 | 2023-01-24 11:56:28 +0530 | [diff] [blame] | 327 | if (interface == assetTagInterface) |
| 328 | { |
| 329 | sdbusplus::asio::getProperty<std::string>( |
| 330 | *crow::connections::systemBus, connectionName, path, |
| 331 | assetTagInterface, "AssetTag", |
| 332 | [asyncResp, |
| 333 | chassisId](const boost::system::error_code& ec2, |
| 334 | const std::string& property) { |
| 335 | if (ec2) |
| 336 | { |
| 337 | BMCWEB_LOG_ERROR |
| 338 | << "DBus response error for AssetTag: " << ec2; |
| 339 | messages::internalError(asyncResp->res); |
| 340 | return; |
| 341 | } |
| 342 | asyncResp->res.jsonValue["AssetTag"] = property; |
| 343 | }); |
| 344 | } |
| 345 | else if (interface == replaceableInterface) |
| 346 | { |
| 347 | sdbusplus::asio::getProperty<bool>( |
| 348 | *crow::connections::systemBus, connectionName, path, |
| 349 | replaceableInterface, "HotPluggable", |
| 350 | [asyncResp, |
| 351 | chassisId](const boost::system::error_code& ec2, |
| 352 | const bool property) { |
| 353 | if (ec2) |
| 354 | { |
| 355 | BMCWEB_LOG_ERROR |
| 356 | << "DBus response error for HotPluggable: " |
| 357 | << ec2; |
| 358 | messages::internalError(asyncResp->res); |
| 359 | return; |
| 360 | } |
| 361 | asyncResp->res.jsonValue["HotPluggable"] = property; |
| 362 | }); |
| 363 | } |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | for (const char* interface : hasIndicatorLed) |
| 367 | { |
| 368 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 369 | interface) != interfaces2.end()) |
| 370 | { |
| 371 | getIndicatorLedState(asyncResp); |
| 372 | getLocationIndicatorActive(asyncResp); |
| 373 | break; |
| 374 | } |
| 375 | } |
| 376 | |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 377 | sdbusplus::asio::getAllProperties( |
| 378 | *crow::connections::systemBus, connectionName, path, |
| 379 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 380 | [asyncResp, chassisId(std::string(chassisId))]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 381 | const boost::system::error_code& /*ec2*/, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 382 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 383 | const std::string* partNumber = nullptr; |
| 384 | const std::string* serialNumber = nullptr; |
| 385 | const std::string* manufacturer = nullptr; |
| 386 | const std::string* model = nullptr; |
| 387 | const std::string* sparePartNumber = nullptr; |
| 388 | |
| 389 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 390 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 391 | "PartNumber", partNumber, "SerialNumber", serialNumber, |
| 392 | "Manufacturer", manufacturer, "Model", model, |
| 393 | "SparePartNumber", sparePartNumber); |
| 394 | |
| 395 | if (!success) |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 396 | { |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 397 | messages::internalError(asyncResp->res); |
| 398 | return; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 399 | } |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 400 | |
| 401 | if (partNumber != nullptr) |
| 402 | { |
| 403 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 404 | } |
| 405 | |
| 406 | if (serialNumber != nullptr) |
| 407 | { |
| 408 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 409 | } |
| 410 | |
| 411 | if (manufacturer != nullptr) |
| 412 | { |
| 413 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 414 | } |
| 415 | |
| 416 | if (model != nullptr) |
| 417 | { |
| 418 | asyncResp->res.jsonValue["Model"] = *model; |
| 419 | } |
| 420 | |
| 421 | // SparePartNumber is optional on D-Bus |
| 422 | // so skip if it is empty |
| 423 | if (sparePartNumber != nullptr && !sparePartNumber->empty()) |
| 424 | { |
| 425 | asyncResp->res.jsonValue["SparePartNumber"] = |
| 426 | *sparePartNumber; |
| 427 | } |
| 428 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 429 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 430 | asyncResp->res.jsonValue["Id"] = chassisId; |
| 431 | #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL |
| 432 | asyncResp->res.jsonValue["Thermal"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 433 | boost::urls::format("/redfish/v1/Chassis/{}/Thermal", |
| 434 | chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 435 | // Power object |
| 436 | asyncResp->res.jsonValue["Power"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 437 | boost::urls::format("/redfish/v1/Chassis/{}/Power", |
| 438 | chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 439 | #endif |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 440 | #ifdef BMCWEB_NEW_POWERSUBSYSTEM_THERMALSUBSYSTEM |
| 441 | asyncResp->res.jsonValue["ThermalSubsystem"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 442 | boost::urls::format( |
| 443 | "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId); |
Chicago Duan | 77b3643 | 2021-02-05 15:48:26 +0800 | [diff] [blame] | 444 | asyncResp->res.jsonValue["PowerSubsystem"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 445 | boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", |
| 446 | chassisId); |
Albert Zhang | 4ca3ec3 | 2021-06-13 14:39:38 +0800 | [diff] [blame] | 447 | asyncResp->res.jsonValue["EnvironmentMetrics"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 448 | boost::urls::format( |
| 449 | "/redfish/v1/Chassis/{}/EnvironmentMetrics", chassisId); |
Xiaochao Ma | 2973963 | 2021-03-02 15:53:13 +0800 | [diff] [blame] | 450 | #endif |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 451 | // SensorCollection |
| 452 | asyncResp->res.jsonValue["Sensors"]["@odata.id"] = |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 453 | boost::urls::format("/redfish/v1/Chassis/{}/Sensors", |
| 454 | chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 455 | asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 456 | |
| 457 | nlohmann::json::array_t computerSystems; |
| 458 | nlohmann::json::object_t system; |
| 459 | system["@odata.id"] = "/redfish/v1/Systems/system"; |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 460 | computerSystems.emplace_back(std::move(system)); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 461 | asyncResp->res.jsonValue["Links"]["ComputerSystems"] = |
| 462 | std::move(computerSystems); |
| 463 | |
| 464 | nlohmann::json::array_t managedBy; |
| 465 | nlohmann::json::object_t manager; |
| 466 | manager["@odata.id"] = "/redfish/v1/Managers/bmc"; |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 467 | managedBy.emplace_back(std::move(manager)); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 468 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = |
| 469 | std::move(managedBy); |
| 470 | getChassisState(asyncResp); |
Krzysztof Grobelny | 86d89ed | 2022-08-29 14:49:20 +0200 | [diff] [blame] | 471 | }); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 472 | |
| 473 | for (const auto& interface : interfaces2) |
| 474 | { |
| 475 | if (interface == "xyz.openbmc_project.Common.UUID") |
| 476 | { |
| 477 | getChassisUUID(asyncResp, connectionName, path); |
| 478 | } |
| 479 | else if (interface == |
| 480 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
| 481 | { |
| 482 | getChassisLocationCode(asyncResp, connectionName, path); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | // Couldn't find an object with that name. return an error |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 490 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 491 | }); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 492 | |
| 493 | getPhysicalSecurityData(asyncResp); |
| 494 | } |
| 495 | |
| 496 | inline void |
| 497 | handleChassisPatch(App& app, const crow::Request& req, |
| 498 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 499 | const std::string& param) |
| 500 | { |
| 501 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 502 | { |
| 503 | return; |
| 504 | } |
| 505 | std::optional<bool> locationIndicatorActive; |
| 506 | std::optional<std::string> indicatorLed; |
| 507 | |
| 508 | if (param.empty()) |
| 509 | { |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | if (!json_util::readJsonPatch( |
| 514 | req, asyncResp->res, "LocationIndicatorActive", |
| 515 | locationIndicatorActive, "IndicatorLED", indicatorLed)) |
| 516 | { |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
| 521 | if (!locationIndicatorActive && !indicatorLed) |
| 522 | { |
| 523 | return; // delete this when we support more patch properties |
| 524 | } |
| 525 | if (indicatorLed) |
| 526 | { |
| 527 | asyncResp->res.addHeader( |
| 528 | boost::beast::http::field::warning, |
| 529 | "299 - \"IndicatorLED is deprecated. Use LocationIndicatorActive instead.\""); |
| 530 | } |
| 531 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 532 | constexpr std::array<std::string_view, 2> interfaces = { |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 533 | "xyz.openbmc_project.Inventory.Item.Board", |
| 534 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 535 | |
| 536 | const std::string& chassisId = param; |
| 537 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 538 | dbus::utility::getSubTree( |
| 539 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 540 | [asyncResp, chassisId, locationIndicatorActive, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 541 | indicatorLed](const boost::system::error_code& ec, |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 542 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 543 | if (ec) |
| 544 | { |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 545 | BMCWEB_LOG_ERROR << "DBUS response error " << ec; |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 546 | messages::internalError(asyncResp->res); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | // Iterate over all retrieved ObjectPaths. |
| 551 | for (const std::pair< |
| 552 | std::string, |
| 553 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 554 | object : subtree) |
| 555 | { |
| 556 | const std::string& path = object.first; |
| 557 | const std::vector<std::pair<std::string, std::vector<std::string>>>& |
| 558 | connectionNames = object.second; |
| 559 | |
| 560 | sdbusplus::message::object_path objPath(path); |
| 561 | if (objPath.filename() != chassisId) |
| 562 | { |
| 563 | continue; |
| 564 | } |
| 565 | |
| 566 | if (connectionNames.empty()) |
| 567 | { |
| 568 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 569 | continue; |
| 570 | } |
| 571 | |
| 572 | const std::vector<std::string>& interfaces3 = |
| 573 | connectionNames[0].second; |
| 574 | |
| 575 | const std::array<const char*, 2> hasIndicatorLed = { |
| 576 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 577 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 578 | bool indicatorChassis = false; |
| 579 | for (const char* interface : hasIndicatorLed) |
| 580 | { |
| 581 | if (std::find(interfaces3.begin(), interfaces3.end(), |
| 582 | interface) != interfaces3.end()) |
| 583 | { |
| 584 | indicatorChassis = true; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | if (locationIndicatorActive) |
| 589 | { |
| 590 | if (indicatorChassis) |
| 591 | { |
| 592 | setLocationIndicatorActive(asyncResp, |
| 593 | *locationIndicatorActive); |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | messages::propertyUnknown(asyncResp->res, |
| 598 | "LocationIndicatorActive"); |
| 599 | } |
| 600 | } |
| 601 | if (indicatorLed) |
| 602 | { |
| 603 | if (indicatorChassis) |
| 604 | { |
| 605 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | messages::propertyUnknown(asyncResp->res, "IndicatorLED"); |
| 610 | } |
| 611 | } |
| 612 | return; |
| 613 | } |
| 614 | |
Jiaqing Zhao | d8a5d5d | 2022-08-05 16:21:51 +0800 | [diff] [blame] | 615 | messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 616 | }); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 619 | /** |
| 620 | * Chassis override class for delivering Chassis Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 621 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 622 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 623 | inline void requestRoutesChassis(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 624 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 625 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 626 | .privileges(redfish::privileges::getChassis) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 627 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 628 | std::bind_front(handleChassisGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 629 | |
| 630 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 631 | .privileges(redfish::privileges::patchChassis) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 632 | .methods(boost::beast::http::verb::patch)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 633 | std::bind_front(handleChassisPatch, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 634 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 635 | |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame^] | 636 | /** |
| 637 | * Handle error responses from d-bus for chassis power cycles |
| 638 | */ |
| 639 | inline void handleChassisPowerCycleError(const boost::system::error_code& ec, |
| 640 | const sdbusplus::message_t& eMsg, |
| 641 | crow::Response& res) |
| 642 | { |
| 643 | if (eMsg.get_error() == nullptr) |
| 644 | { |
| 645 | BMCWEB_LOG_ERROR << "D-Bus response error: " << ec; |
| 646 | messages::internalError(res); |
| 647 | return; |
| 648 | } |
| 649 | std::string_view errorMessage = eMsg.get_error()->name; |
| 650 | |
| 651 | // If operation failed due to BMC not being in Ready state, tell |
| 652 | // user to retry in a bit |
| 653 | if (errorMessage == |
| 654 | std::string_view("xyz.openbmc_project.State.Chassis.Error.BMCNotReady")) |
| 655 | { |
| 656 | BMCWEB_LOG_DEBUG << "BMC not ready, operation not allowed right now"; |
| 657 | messages::serviceTemporarilyUnavailable(res, "10"); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | BMCWEB_LOG_ERROR << "Chassis Power Cycle fail " << ec |
| 662 | << " sdbusplus:" << errorMessage; |
| 663 | messages::internalError(res); |
| 664 | } |
| 665 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 666 | inline void |
| 667 | doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 668 | { |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 669 | constexpr std::array<std::string_view, 1> interfaces = { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 670 | "xyz.openbmc_project.State.Chassis"}; |
| 671 | |
| 672 | // Use mapper to get subtree paths. |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 673 | dbus::utility::getSubTreePaths( |
| 674 | "/", 0, interfaces, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 675 | [asyncResp]( |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 676 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 677 | const dbus::utility::MapperGetSubTreePathsResponse& chassisList) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 678 | if (ec) |
| 679 | { |
Andrew Geissler | 51dab2a | 2023-05-30 15:07:46 -0400 | [diff] [blame] | 680 | BMCWEB_LOG_ERROR << "[mapper] Bad D-Bus request error: " << ec; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 681 | messages::internalError(asyncResp->res); |
| 682 | return; |
| 683 | } |
| 684 | |
| 685 | const char* processName = "xyz.openbmc_project.State.Chassis"; |
| 686 | const char* interfaceName = "xyz.openbmc_project.State.Chassis"; |
| 687 | const char* destProperty = "RequestedPowerTransition"; |
| 688 | const std::string propertyValue = |
| 689 | "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; |
| 690 | std::string objectPath = "/xyz/openbmc_project/state/chassis_system0"; |
| 691 | |
| 692 | /* Look for system reset chassis path */ |
| 693 | if ((std::find(chassisList.begin(), chassisList.end(), objectPath)) == |
| 694 | chassisList.end()) |
| 695 | { |
| 696 | /* We prefer to reset the full chassis_system, but if it doesn't |
| 697 | * exist on some platforms, fall back to a host-only power reset |
| 698 | */ |
| 699 | objectPath = "/xyz/openbmc_project/state/chassis0"; |
| 700 | } |
| 701 | |
| 702 | crow::connections::systemBus->async_method_call( |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame^] | 703 | [asyncResp](const boost::system::error_code& ec2, |
| 704 | sdbusplus::message_t& sdbusErrMsg) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 705 | // Use "Set" method to set the property value. |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 706 | if (ec2) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 707 | { |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame^] | 708 | handleChassisPowerCycleError(ec2, sdbusErrMsg, asyncResp->res); |
| 709 | |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 713 | messages::success(asyncResp->res); |
| 714 | }, |
| 715 | processName, objectPath, "org.freedesktop.DBus.Properties", "Set", |
| 716 | interfaceName, destProperty, |
| 717 | dbus::utility::DbusVariantType{propertyValue}); |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 718 | }); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 719 | } |
| 720 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 721 | inline void handleChassisResetActionInfoPost( |
| 722 | App& app, const crow::Request& req, |
| 723 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 724 | const std::string& /*chassisId*/) |
| 725 | { |
| 726 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 727 | { |
| 728 | return; |
| 729 | } |
| 730 | BMCWEB_LOG_DEBUG << "Post Chassis Reset."; |
| 731 | |
| 732 | std::string resetType; |
| 733 | |
| 734 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) |
| 735 | { |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | if (resetType != "PowerCycle") |
| 740 | { |
| 741 | BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " |
| 742 | << resetType; |
| 743 | messages::actionParameterNotSupported(asyncResp->res, resetType, |
| 744 | "ResetType"); |
| 745 | |
| 746 | return; |
| 747 | } |
| 748 | doChassisPowerCycle(asyncResp); |
| 749 | } |
| 750 | |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 751 | /** |
| 752 | * ChassisResetAction class supports the POST method for the Reset |
| 753 | * action. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 754 | * Function handles POST method request. |
| 755 | * Analyzes POST body before sending Reset request data to D-Bus. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 756 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 757 | |
| 758 | inline void requestRoutesChassisResetAction(App& app) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 759 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 760 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 761 | .privileges(redfish::privileges::postChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 762 | .methods(boost::beast::http::verb::post)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 763 | std::bind_front(handleChassisResetActionInfoPost, std::ref(app))); |
| 764 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 765 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 766 | inline void handleChassisResetActionInfoGet( |
| 767 | App& app, const crow::Request& req, |
| 768 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 769 | const std::string& chassisId) |
| 770 | { |
| 771 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 772 | { |
| 773 | return; |
| 774 | } |
| 775 | asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 776 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 777 | "/redfish/v1/Chassis/{}/ResetActionInfo", chassisId); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 778 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 779 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 780 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 781 | nlohmann::json::array_t parameters; |
| 782 | nlohmann::json::object_t parameter; |
| 783 | parameter["Name"] = "ResetType"; |
| 784 | parameter["Required"] = true; |
| 785 | parameter["DataType"] = "String"; |
| 786 | nlohmann::json::array_t allowed; |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 787 | allowed.emplace_back("PowerCycle"); |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 788 | parameter["AllowableValues"] = std::move(allowed); |
Patrick Williams | ad53954 | 2023-05-12 10:10:08 -0500 | [diff] [blame] | 789 | parameters.emplace_back(std::move(parameter)); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 790 | |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 791 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 792 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 793 | |
| 794 | /** |
| 795 | * ChassisResetActionInfo derived class for delivering Chassis |
| 796 | * ResetType AllowableValues using ResetInfo schema. |
| 797 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 798 | inline void requestRoutesChassisResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 799 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 800 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 801 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 802 | .methods(boost::beast::http::verb::get)( |
Nan Zhou | cf7eba0 | 2022-07-21 23:53:20 +0000 | [diff] [blame] | 803 | std::bind_front(handleChassisResetActionInfoGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 804 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 805 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 806 | } // namespace redfish |