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