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