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 | */ |
| 36 | void getChassisState(std::shared_ptr<AsyncResp> aResp) |
| 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 | |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 88 | void getIntrusionByService(std::shared_ptr<AsyncResp> aResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 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 | { |
| 99 | // do not add err msg in redfish response, becaues this is not |
| 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 | */ |
| 123 | void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp) |
| 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 | { |
| 134 | // do not add err msg in redfish response, becaues this is not |
| 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: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 163 | ChassisCollection(CrowApp& 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 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 178 | void doGet(crow::Response& res, const crow::Request& req, |
| 179 | const std::vector<std::string>& params) 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; |
| 207 | continue; |
| 208 | } |
| 209 | chassisArray.push_back( |
| 210 | {{"@odata.id", "/redfish/v1/Chassis/" + |
| 211 | objpath.substr(lastPos + 1)}}); |
| 212 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 213 | |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 214 | asyncResp->res.jsonValue["Members@odata.count"] = |
| 215 | chassisArray.size(); |
| 216 | }, |
| 217 | "xyz.openbmc_project.ObjectMapper", |
| 218 | "/xyz/openbmc_project/object_mapper", |
| 219 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 220 | "/xyz/openbmc_project/inventory", 0, interfaces); |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 221 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /** |
| 225 | * Chassis override class for delivering Chassis Schema |
| 226 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 227 | class Chassis : public Node |
| 228 | { |
| 229 | public: |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 230 | Chassis(CrowApp& app) : |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 231 | Node(app, "/redfish/v1/Chassis/<str>/", std::string()) |
| 232 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 233 | entityPrivileges = { |
| 234 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 235 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 236 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 237 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 238 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 239 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 240 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 241 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 242 | private: |
| 243 | /** |
| 244 | * Functions triggers appropriate requests on DBus |
| 245 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 246 | void doGet(crow::Response& res, const crow::Request& req, |
| 247 | const std::vector<std::string>& params) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 248 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 249 | const std::array<const char*, 2> interfaces = { |
Gunnar Mills | 734bfe9 | 2019-01-21 16:33:50 -0600 | [diff] [blame] | 250 | "xyz.openbmc_project.Inventory.Item.Board", |
Shawn McCarney | adc4f0d | 2019-07-24 09:21:50 -0500 | [diff] [blame] | 251 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Gunnar Mills | 734bfe9 | 2019-01-21 16:33:50 -0600 | [diff] [blame] | 252 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 253 | // Check if there is required param, truly entering this shall be |
| 254 | // impossible. |
| 255 | if (params.size() != 1) |
| 256 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 257 | messages::internalError(res); |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 258 | res.end(); |
| 259 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 260 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 261 | const std::string& chassisId = params[0]; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 262 | |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 263 | auto asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 264 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 265 | [asyncResp, chassisId(std::string(chassisId))]( |
| 266 | const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 267 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 268 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 269 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 270 | messages::internalError(asyncResp->res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | // Iterate over all retrieved ObjectPaths. |
| 274 | for (const std::pair< |
| 275 | std::string, |
| 276 | std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 277 | std::pair<std::string, std::vector<std::string>>>>& |
| 278 | object : subtree) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 279 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 280 | const std::string& path = object.first; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 281 | const std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 282 | std::pair<std::string, std::vector<std::string>>>& |
| 283 | connectionNames = object.second; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 284 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 285 | if (!boost::ends_with(path, chassisId)) |
| 286 | { |
| 287 | continue; |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 288 | } |
Shawn McCarney | 26f0389 | 2019-05-03 13:20:24 -0500 | [diff] [blame] | 289 | |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 290 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 291 | |
| 292 | crow::connections::systemBus->async_method_call( |
| 293 | [health](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 294 | std::variant<std::vector<std::string>>& resp) { |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 295 | if (ec) |
| 296 | { |
| 297 | return; // no sensors = no failures |
| 298 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 299 | std::vector<std::string>* data = |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 300 | std::get_if<std::vector<std::string>>(&resp); |
| 301 | if (data == nullptr) |
| 302 | { |
| 303 | return; |
| 304 | } |
| 305 | health->inventory = std::move(*data); |
| 306 | }, |
| 307 | "xyz.openbmc_project.ObjectMapper", |
| 308 | path + "/all_sensors", |
| 309 | "org.freedesktop.DBus.Properties", "Get", |
| 310 | "xyz.openbmc_project.Association", "endpoints"); |
| 311 | |
| 312 | health->populate(); |
| 313 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 314 | if (connectionNames.size() < 1) |
| 315 | { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 316 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 317 | continue; |
| 318 | } |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 319 | |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 320 | asyncResp->res.jsonValue["@odata.type"] = |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 321 | "#Chassis.v1_10_0.Chassis"; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 322 | asyncResp->res.jsonValue["@odata.id"] = |
| 323 | "/redfish/v1/Chassis/" + chassisId; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 324 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 325 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 326 | asyncResp->res.jsonValue["PCIeDevices"] = { |
| 327 | {"@odata.id", |
| 328 | "/redfish/v1/Systems/system/PCIeDevices"}}; |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 329 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 330 | const std::string& connectionName = |
Johnathan Mantey | 49c53ac | 2019-05-02 09:22:38 -0700 | [diff] [blame] | 331 | connectionNames[0].first; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 332 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 333 | const std::vector<std::string>& interfaces = |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 334 | connectionNames[0].second; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 335 | const std::array<const char*, 2> hasIndicatorLed = { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 336 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 337 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"}; |
| 338 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 339 | for (const char* interface : hasIndicatorLed) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 340 | { |
| 341 | if (std::find(interfaces.begin(), interfaces.end(), |
| 342 | interface) != interfaces.end()) |
| 343 | { |
| 344 | getIndicatorLedState(asyncResp); |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 349 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 350 | [asyncResp, chassisId(std::string(chassisId))]( |
| 351 | const boost::system::error_code ec, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 352 | const std::vector<std::pair< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 353 | std::string, VariantType>>& propertiesList) { |
| 354 | for (const std::pair<std::string, VariantType>& |
| 355 | property : propertiesList) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 356 | { |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 357 | // Store DBus properties that are also Redfish |
| 358 | // properties with same name and a string value |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 359 | const std::string& propertyName = |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 360 | property.first; |
| 361 | if ((propertyName == "PartNumber") || |
| 362 | (propertyName == "SerialNumber") || |
| 363 | (propertyName == "Manufacturer") || |
| 364 | (propertyName == "Model")) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 365 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 366 | const std::string* value = |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 367 | std::get_if<std::string>( |
| 368 | &property.second); |
| 369 | if (value != nullptr) |
| 370 | { |
| 371 | asyncResp->res.jsonValue[propertyName] = |
| 372 | *value; |
| 373 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 376 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 377 | asyncResp->res.jsonValue["Id"] = chassisId; |
| 378 | asyncResp->res.jsonValue["Thermal"] = { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 379 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 380 | chassisId + "/Thermal"}}; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 381 | // Power object |
| 382 | asyncResp->res.jsonValue["Power"] = { |
| 383 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 384 | chassisId + "/Power"}}; |
Anthony Wilson | 95a3eca | 2019-06-11 10:44:47 -0500 | [diff] [blame] | 385 | // SensorCollection |
| 386 | asyncResp->res.jsonValue["Sensors"] = { |
| 387 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 388 | chassisId + "/Sensors"}}; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 389 | asyncResp->res.jsonValue["Status"] = { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 390 | {"State", "Enabled"}, |
| 391 | }; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 392 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 393 | asyncResp->res |
| 394 | .jsonValue["Links"]["ComputerSystems"] = { |
| 395 | {{"@odata.id", "/redfish/v1/Systems/system"}}}; |
| 396 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = { |
| 397 | {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 398 | getChassisState(asyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 399 | }, |
| 400 | connectionName, path, "org.freedesktop.DBus.Properties", |
| 401 | "GetAll", |
| 402 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 403 | return; |
| 404 | } |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 405 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 406 | // Couldn't find an object with that name. return an error |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 407 | messages::resourceNotFound( |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 408 | asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 409 | }, |
| 410 | "xyz.openbmc_project.ObjectMapper", |
| 411 | "/xyz/openbmc_project/object_mapper", |
| 412 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 413 | "/xyz/openbmc_project/inventory", 0, interfaces); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 414 | |
| 415 | getPhysicalSecurityData(asyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 416 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 417 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 418 | void doPatch(crow::Response& res, const crow::Request& req, |
| 419 | const std::vector<std::string>& params) override |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 420 | { |
| 421 | std::optional<std::string> indicatorLed; |
| 422 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 423 | |
| 424 | if (params.size() != 1) |
| 425 | { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed)) |
| 430 | { |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | if (!indicatorLed) |
| 435 | { |
| 436 | return; // delete this when we support more patch properties |
| 437 | } |
| 438 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 439 | const std::array<const char*, 2> interfaces = { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 440 | "xyz.openbmc_project.Inventory.Item.Board", |
| 441 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 442 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 443 | const std::string& chassisId = params[0]; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 444 | |
| 445 | crow::connections::systemBus->async_method_call( |
| 446 | [asyncResp, chassisId, indicatorLed]( |
| 447 | const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 448 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 449 | if (ec) |
| 450 | { |
| 451 | messages::internalError(asyncResp->res); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | // Iterate over all retrieved ObjectPaths. |
| 456 | for (const std::pair< |
| 457 | std::string, |
| 458 | std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 459 | std::pair<std::string, std::vector<std::string>>>>& |
| 460 | object : subtree) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 461 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 462 | const std::string& path = object.first; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 463 | const std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 464 | std::pair<std::string, std::vector<std::string>>>& |
| 465 | connectionNames = object.second; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 466 | |
| 467 | if (!boost::ends_with(path, chassisId)) |
| 468 | { |
| 469 | continue; |
| 470 | } |
| 471 | |
| 472 | if (connectionNames.size() < 1) |
| 473 | { |
| 474 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 475 | continue; |
| 476 | } |
| 477 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 478 | const std::vector<std::string>& interfaces = |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 479 | connectionNames[0].second; |
| 480 | |
| 481 | if (indicatorLed) |
| 482 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 483 | const std::array<const char*, 2> hasIndicatorLed = { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 484 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 485 | "xyz.openbmc_project.Inventory.Item.Board." |
| 486 | "Motherboard"}; |
| 487 | bool indicatorChassis = false; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 488 | for (const char* interface : hasIndicatorLed) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 489 | { |
| 490 | if (std::find(interfaces.begin(), interfaces.end(), |
| 491 | interface) != interfaces.end()) |
| 492 | { |
| 493 | indicatorChassis = true; |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | if (indicatorChassis) |
| 498 | { |
| 499 | setIndicatorLedState(asyncResp, |
| 500 | std::move(*indicatorLed)); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | messages::propertyUnknown(asyncResp->res, |
| 505 | "IndicatorLED"); |
| 506 | } |
| 507 | } |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | messages::resourceNotFound( |
| 512 | asyncResp->res, "#Chassis.v1_10_0.Chassis", chassisId); |
| 513 | }, |
| 514 | "xyz.openbmc_project.ObjectMapper", |
| 515 | "/xyz/openbmc_project/object_mapper", |
| 516 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 517 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 518 | } |
Ed Tanous | 62d5e2e | 2018-09-05 16:17:25 -0700 | [diff] [blame] | 519 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 520 | } // namespace redfish |