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> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 23 | #include <variant> |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 24 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 25 | namespace redfish |
| 26 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 27 | |
| 28 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 29 | * @brief Retrieves chassis state properties over dbus |
| 30 | * |
| 31 | * @param[in] aResp - Shared pointer for completing asynchronous calls. |
| 32 | * |
| 33 | * @return None. |
| 34 | */ |
| 35 | void getChassisState(std::shared_ptr<AsyncResp> aResp) |
| 36 | { |
| 37 | crow::connections::systemBus->async_method_call( |
| 38 | [aResp{std::move(aResp)}]( |
| 39 | const boost::system::error_code ec, |
| 40 | const std::variant<std::string> &chassisState) { |
| 41 | if (ec) |
| 42 | { |
| 43 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 44 | messages::internalError(aResp->res); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | const std::string *s = std::get_if<std::string>(&chassisState); |
| 49 | BMCWEB_LOG_DEBUG << "Chassis state: " << *s; |
| 50 | if (s != nullptr) |
| 51 | { |
| 52 | // Verify Chassis State |
| 53 | if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") |
| 54 | { |
| 55 | aResp->res.jsonValue["PowerState"] = "On"; |
| 56 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 57 | } |
| 58 | else if (*s == |
| 59 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 60 | { |
| 61 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 62 | aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
| 63 | } |
| 64 | } |
| 65 | }, |
| 66 | "xyz.openbmc_project.State.Chassis", |
| 67 | "/xyz/openbmc_project/state/chassis0", |
| 68 | "org.freedesktop.DBus.Properties", "Get", |
| 69 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); |
| 70 | } |
| 71 | |
| 72 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 73 | * DBus types primitives for several generic DBus interfaces |
| 74 | * TODO(Pawel) consider move this to separate file into boost::dbus |
| 75 | */ |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 76 | // 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] | 77 | // values, it should be as simple as possible |
| 78 | // TODO(ed) invent a nullvariant type |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 79 | using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>; |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 80 | using ManagedObjectsType = std::vector<std::pair< |
| 81 | sdbusplus::message::object_path, |
| 82 | std::vector<std::pair<std::string, |
| 83 | std::vector<std::pair<std::string, VariantType>>>>>>; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 84 | |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 85 | using PropertiesType = boost::container::flat_map<std::string, VariantType>; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 86 | |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 87 | void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, |
| 88 | const std::string &service, |
| 89 | const std::string &objPath) |
| 90 | { |
| 91 | BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; |
| 92 | |
| 93 | crow::connections::systemBus->async_method_call( |
| 94 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
| 95 | const std::variant<std::string> &value) { |
| 96 | if (ec) |
| 97 | { |
| 98 | // do not add err msg in redfish response, becaues this is not |
| 99 | // mandatory property |
| 100 | BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | const std::string *status = std::get_if<std::string>(&value); |
| 105 | |
| 106 | if (status == nullptr) |
| 107 | { |
| 108 | BMCWEB_LOG_ERROR << "intrusion status read error \n"; |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | aResp->res.jsonValue["PhysicalSecurity"] = { |
| 113 | {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}}; |
| 114 | }, |
| 115 | service, objPath, "org.freedesktop.DBus.Properties", "Get", |
| 116 | "xyz.openbmc_project.Chassis.Intrusion", "Status"); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Retrieves physical security properties over dbus |
| 121 | */ |
| 122 | void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp) |
| 123 | { |
| 124 | crow::connections::systemBus->async_method_call( |
| 125 | [aResp{std::move(aResp)}]( |
| 126 | const boost::system::error_code ec, |
| 127 | const std::vector<std::pair< |
| 128 | std::string, |
| 129 | std::vector<std::pair<std::string, std::vector<std::string>>>>> |
| 130 | &subtree) { |
| 131 | if (ec) |
| 132 | { |
| 133 | // do not add err msg in redfish response, becaues this is not |
| 134 | // mandatory property |
| 135 | BMCWEB_LOG_ERROR << "DBUS error: no matched iface " << ec |
| 136 | << "\n"; |
| 137 | return; |
| 138 | } |
| 139 | // Iterate over all retrieved ObjectPaths. |
| 140 | for (const auto &object : subtree) |
| 141 | { |
| 142 | for (const auto &service : object.second) |
| 143 | { |
| 144 | getIntrusionByService(aResp, service.first, object.first); |
| 145 | return; |
| 146 | } |
| 147 | } |
| 148 | }, |
| 149 | "xyz.openbmc_project.ObjectMapper", |
| 150 | "/xyz/openbmc_project/object_mapper", |
| 151 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 152 | "/xyz/openbmc_project/Intrusion", 1, |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 153 | std::array<const char *, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); |
| 154 | } |
| 155 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 156 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 157 | * ChassisCollection derived class for delivering Chassis Collection Schema |
| 158 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 159 | class ChassisCollection : public Node |
| 160 | { |
| 161 | public: |
| 162 | ChassisCollection(CrowApp &app) : Node(app, "/redfish/v1/Chassis/") |
| 163 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 164 | entityPrivileges = { |
| 165 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 166 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 167 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 168 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 169 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 170 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 171 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 172 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 173 | private: |
| 174 | /** |
| 175 | * Functions triggers appropriate requests on DBus |
| 176 | */ |
| 177 | void doGet(crow::Response &res, const crow::Request &req, |
| 178 | const std::vector<std::string> ¶ms) override |
| 179 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 180 | res.jsonValue["@odata.type"] = "#ChassisCollection.ChassisCollection"; |
| 181 | res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 182 | res.jsonValue["Name"] = "Chassis Collection"; |
| 183 | |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 184 | const std::array<const char *, 2> interfaces = { |
Gunnar Mills | 603a664 | 2019-01-21 17:03:51 -0600 | [diff] [blame] | 185 | "xyz.openbmc_project.Inventory.Item.Board", |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 186 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Gunnar Mills | 603a664 | 2019-01-21 17:03:51 -0600 | [diff] [blame] | 187 | |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 188 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 189 | crow::connections::systemBus->async_method_call( |
| 190 | [asyncResp](const boost::system::error_code ec, |
| 191 | const std::vector<std::string> &chassisList) { |
| 192 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 193 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 194 | messages::internalError(asyncResp->res); |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 195 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 196 | } |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 197 | nlohmann::json &chassisArray = |
| 198 | asyncResp->res.jsonValue["Members"]; |
| 199 | chassisArray = nlohmann::json::array(); |
| 200 | for (const std::string &objpath : chassisList) |
| 201 | { |
| 202 | std::size_t lastPos = objpath.rfind("/"); |
| 203 | if (lastPos == std::string::npos) |
| 204 | { |
| 205 | BMCWEB_LOG_ERROR << "Failed to find '/' in " << objpath; |
| 206 | continue; |
| 207 | } |
| 208 | chassisArray.push_back( |
| 209 | {{"@odata.id", "/redfish/v1/Chassis/" + |
| 210 | objpath.substr(lastPos + 1)}}); |
| 211 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 212 | |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 213 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 214 | chassisArray.size(); |
| 215 | }, |
| 216 | "xyz.openbmc_project.ObjectMapper", |
| 217 | "/xyz/openbmc_project/object_mapper", |
| 218 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 219 | "/xyz/openbmc_project/inventory", 0, interfaces); |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 220 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | /** |
| 224 | * Chassis override class for delivering Chassis Schema |
| 225 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 226 | class Chassis : public Node |
| 227 | { |
| 228 | public: |
| 229 | Chassis(CrowApp &app) : |
| 230 | Node(app, "/redfish/v1/Chassis/<str>/", std::string()) |
| 231 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 232 | entityPrivileges = { |
| 233 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 234 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 235 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 236 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 237 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 238 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 239 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 240 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 241 | private: |
| 242 | /** |
| 243 | * Functions triggers appropriate requests on DBus |
| 244 | */ |
| 245 | void doGet(crow::Response &res, const crow::Request &req, |
| 246 | const std::vector<std::string> ¶ms) override |
| 247 | { |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 248 | const std::array<const char *, 2> interfaces = { |
Gunnar Mills | 734bfe9 | 2019-01-21 16:33:50 -0600 | [diff] [blame] | 249 | "xyz.openbmc_project.Inventory.Item.Board", |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 250 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Gunnar Mills | 734bfe9 | 2019-01-21 16:33:50 -0600 | [diff] [blame] | 251 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 252 | // Check if there is required param, truly entering this shall be |
| 253 | // impossible. |
| 254 | if (params.size() != 1) |
| 255 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 256 | messages::internalError(res); |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 257 | res.end(); |
| 258 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 259 | } |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 260 | const std::string &chassisId = params[0]; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 261 | |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 262 | auto asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 263 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 264 | [asyncResp, chassisId(std::string(chassisId))]( |
| 265 | const boost::system::error_code ec, |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 266 | const crow::openbmc_mapper::GetSubTreeType &subtree) { |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 267 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 268 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 269 | messages::internalError(asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | // Iterate over all retrieved ObjectPaths. |
| 273 | for (const std::pair< |
| 274 | std::string, |
| 275 | std::vector< |
| 276 | std::pair<std::string, std::vector<std::string>>>> |
| 277 | &object : subtree) |
| 278 | { |
| 279 | const std::string &path = object.first; |
| 280 | const std::vector< |
| 281 | std::pair<std::string, std::vector<std::string>>> |
| 282 | &connectionNames = object.second; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 283 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 284 | if (!boost::ends_with(path, chassisId)) |
| 285 | { |
| 286 | continue; |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 287 | } |
Shawn McCarney | 26f0389 | 2019-05-03 13:20:24 -0500 | [diff] [blame] | 288 | |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 289 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 290 | |
| 291 | crow::connections::systemBus->async_method_call( |
| 292 | [health](const boost::system::error_code ec, |
| 293 | std::variant<std::vector<std::string>> &resp) { |
| 294 | if (ec) |
| 295 | { |
| 296 | return; // no sensors = no failures |
| 297 | } |
| 298 | std::vector<std::string> *data = |
| 299 | std::get_if<std::vector<std::string>>(&resp); |
| 300 | if (data == nullptr) |
| 301 | { |
| 302 | return; |
| 303 | } |
| 304 | health->inventory = std::move(*data); |
| 305 | }, |
| 306 | "xyz.openbmc_project.ObjectMapper", |
| 307 | path + "/all_sensors", |
| 308 | "org.freedesktop.DBus.Properties", "Get", |
| 309 | "xyz.openbmc_project.Association", "endpoints"); |
| 310 | |
| 311 | health->populate(); |
| 312 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 313 | if (connectionNames.size() < 1) |
| 314 | { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 315 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 316 | continue; |
| 317 | } |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 318 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 319 | asyncResp->res.jsonValue["@odata.type"] = |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 320 | "#Chassis.v1_10_0.Chassis"; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 321 | asyncResp->res.jsonValue["@odata.id"] = |
| 322 | "/redfish/v1/Chassis/" + chassisId; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 323 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 324 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 325 | asyncResp->res.jsonValue["PCIeDevices"] = { |
| 326 | {"@odata.id", |
| 327 | "/redfish/v1/Systems/system/PCIeDevices"}}; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 328 | |
| 329 | const std::string &connectionName = |
| 330 | connectionNames[0].first; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 331 | |
| 332 | const std::vector<std::string> &interfaces = |
| 333 | connectionNames[0].second; |
| 334 | const std::array<const char *, 2> hasIndicatorLed = { |
| 335 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 336 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 337 | |
| 338 | for (const char *interface : hasIndicatorLed) |
| 339 | { |
| 340 | if (std::find(interfaces.begin(), interfaces.end(), |
| 341 | interface) != interfaces.end()) |
| 342 | { |
| 343 | getIndicatorLedState(asyncResp); |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 348 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 349 | [asyncResp, chassisId(std::string(chassisId))]( |
| 350 | const boost::system::error_code ec, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 351 | const std::vector<std::pair< |
| 352 | std::string, VariantType>> &propertiesList) { |
| 353 | for (const std::pair<std::string, VariantType> |
| 354 | &property : propertiesList) |
| 355 | { |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 356 | // Store DBus properties that are also Redfish |
| 357 | // properties with same name and a string value |
| 358 | const std::string &propertyName = |
| 359 | property.first; |
| 360 | if ((propertyName == "PartNumber") || |
| 361 | (propertyName == "SerialNumber") || |
| 362 | (propertyName == "Manufacturer") || |
| 363 | (propertyName == "Model")) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 364 | { |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 365 | const std::string *value = |
| 366 | std::get_if<std::string>( |
| 367 | &property.second); |
| 368 | if (value != nullptr) |
| 369 | { |
| 370 | asyncResp->res.jsonValue[propertyName] = |
| 371 | *value; |
| 372 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 375 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 376 | asyncResp->res.jsonValue["Id"] = chassisId; |
| 377 | asyncResp->res.jsonValue["Thermal"] = { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 378 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 379 | chassisId + "/Thermal"}}; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 380 | // Power object |
| 381 | asyncResp->res.jsonValue["Power"] = { |
| 382 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 383 | chassisId + "/Power"}}; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 384 | // SensorCollection |
| 385 | asyncResp->res.jsonValue["Sensors"] = { |
| 386 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 387 | chassisId + "/Sensors"}}; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 388 | asyncResp->res.jsonValue["Status"] = { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 389 | {"State", "Enabled"}, |
| 390 | }; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 391 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 392 | asyncResp->res |
| 393 | .jsonValue["Links"]["ComputerSystems"] = { |
| 394 | {{"@odata.id", "/redfish/v1/Systems/system"}}}; |
| 395 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = { |
| 396 | {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 397 | getChassisState(asyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 398 | }, |
| 399 | connectionName, path, "org.freedesktop.DBus.Properties", |
| 400 | "GetAll", |
| 401 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 402 | return; |
| 403 | } |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 404 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 405 | // Couldn't find an object with that name. return an error |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 406 | messages::resourceNotFound( |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 407 | asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 408 | }, |
| 409 | "xyz.openbmc_project.ObjectMapper", |
| 410 | "/xyz/openbmc_project/object_mapper", |
| 411 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 412 | "/xyz/openbmc_project/inventory", 0, interfaces); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 413 | |
| 414 | getPhysicalSecurityData(asyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 415 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 416 | |
| 417 | void doPatch(crow::Response &res, const crow::Request &req, |
| 418 | const std::vector<std::string> ¶ms) override |
| 419 | { |
| 420 | std::optional<std::string> indicatorLed; |
| 421 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 422 | |
| 423 | if (params.size() != 1) |
| 424 | { |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed)) |
| 429 | { |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | if (!indicatorLed) |
| 434 | { |
| 435 | return; // delete this when we support more patch properties |
| 436 | } |
| 437 | |
| 438 | const std::array<const char *, 2> interfaces = { |
| 439 | "xyz.openbmc_project.Inventory.Item.Board", |
| 440 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 441 | |
| 442 | const std::string &chassisId = params[0]; |
| 443 | |
| 444 | crow::connections::systemBus->async_method_call( |
| 445 | [asyncResp, chassisId, indicatorLed]( |
| 446 | const boost::system::error_code ec, |
| 447 | const crow::openbmc_mapper::GetSubTreeType &subtree) { |
| 448 | if (ec) |
| 449 | { |
| 450 | messages::internalError(asyncResp->res); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | // Iterate over all retrieved ObjectPaths. |
| 455 | for (const std::pair< |
| 456 | std::string, |
| 457 | std::vector< |
| 458 | std::pair<std::string, std::vector<std::string>>>> |
| 459 | &object : subtree) |
| 460 | { |
| 461 | const std::string &path = object.first; |
| 462 | const std::vector< |
| 463 | std::pair<std::string, std::vector<std::string>>> |
| 464 | &connectionNames = object.second; |
| 465 | |
| 466 | if (!boost::ends_with(path, chassisId)) |
| 467 | { |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | if (connectionNames.size() < 1) |
| 472 | { |
| 473 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 474 | continue; |
| 475 | } |
| 476 | |
| 477 | const std::vector<std::string> &interfaces = |
| 478 | connectionNames[0].second; |
| 479 | |
| 480 | if (indicatorLed) |
| 481 | { |
| 482 | const std::array<const char *, 2> hasIndicatorLed = { |
| 483 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 484 | "xyz.openbmc_project.Inventory.Item.Board." |
| 485 | "Motherboard"}; |
| 486 | bool indicatorChassis = false; |
| 487 | for (const char *interface : hasIndicatorLed) |
| 488 | { |
| 489 | if (std::find(interfaces.begin(), interfaces.end(), |
| 490 | interface) != interfaces.end()) |
| 491 | { |
| 492 | indicatorChassis = true; |
| 493 | break; |
| 494 | } |
| 495 | } |
| 496 | if (indicatorChassis) |
| 497 | { |
| 498 | setIndicatorLedState(asyncResp, |
| 499 | std::move(*indicatorLed)); |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | messages::propertyUnknown(asyncResp->res, |
| 504 | "IndicatorLED"); |
| 505 | } |
| 506 | } |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | messages::resourceNotFound( |
| 511 | asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); |
| 512 | }, |
| 513 | "xyz.openbmc_project.ObjectMapper", |
| 514 | "/xyz/openbmc_project/object_mapper", |
| 515 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 516 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 517 | } |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 518 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 519 | } // namespace redfish |