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