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