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