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