Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [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 | |
| 18 | #include <boost/container/flat_map.hpp> |
| 19 | #include <node.hpp> |
| 20 | #include <utils/json_utils.hpp> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 21 | #include <variant> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 22 | |
| 23 | namespace redfish |
| 24 | { |
| 25 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 26 | void getResourceList(std::shared_ptr<AsyncResp> aResp, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 27 | const std::string &subclass, |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 28 | const std::vector<const char *> &collectionName) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 29 | { |
| 30 | BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources."; |
| 31 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 32 | [subclass, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 33 | const boost::system::error_code ec, |
| 34 | const boost::container::flat_map< |
| 35 | std::string, boost::container::flat_map< |
| 36 | std::string, std::vector<std::string>>> |
| 37 | &subtree) { |
| 38 | if (ec) |
| 39 | { |
| 40 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 41 | messages::internalError(aResp->res); |
| 42 | return; |
| 43 | } |
| 44 | nlohmann::json &members = aResp->res.jsonValue["Members"]; |
| 45 | members = nlohmann::json::array(); |
| 46 | |
| 47 | for (const auto &object : subtree) |
| 48 | { |
| 49 | auto iter = object.first.rfind("/"); |
| 50 | if ((iter != std::string::npos) && (iter < object.first.size())) |
| 51 | { |
| 52 | members.push_back( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 53 | {{"@odata.id", "/redfish/v1/Systems/system/" + |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 54 | subclass + "/" + |
| 55 | object.first.substr(iter + 1)}}); |
| 56 | } |
| 57 | } |
| 58 | aResp->res.jsonValue["Members@odata.count"] = members.size(); |
| 59 | }, |
| 60 | "xyz.openbmc_project.ObjectMapper", |
| 61 | "/xyz/openbmc_project/object_mapper", |
| 62 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 63 | "/xyz/openbmc_project/inventory", int32_t(0), collectionName); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void getCpuDataByService(std::shared_ptr<AsyncResp> aResp, |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 67 | const std::string &cpuId, const std::string &service, |
| 68 | const std::string &objPath) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 69 | { |
| 70 | BMCWEB_LOG_DEBUG << "Get available system cpu resources by service."; |
| 71 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 72 | [cpuId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 73 | const boost::system::error_code ec, |
| 74 | const boost::container::flat_map< |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 75 | std::string, std::variant<std::string, uint32_t, uint16_t>> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 76 | &properties) { |
| 77 | if (ec) |
| 78 | { |
| 79 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 80 | messages::internalError(aResp->res); |
| 81 | |
| 82 | return; |
| 83 | } |
| 84 | aResp->res.jsonValue["Id"] = cpuId; |
| 85 | aResp->res.jsonValue["Name"] = "Processor"; |
| 86 | const auto coresCountProperty = |
| 87 | properties.find("ProcessorCoreCount"); |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 88 | if (coresCountProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 89 | { |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 90 | const uint16_t *coresCount = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 91 | std::get_if<uint16_t>(&coresCountProperty->second); |
Ed Tanous | 883b311 | 2018-12-06 16:13:35 -0800 | [diff] [blame] | 92 | if (coresCount == nullptr) |
| 93 | { |
| 94 | // Important property not in desired type |
| 95 | messages::internalError(aResp->res); |
| 96 | return; |
| 97 | } |
| 98 | if (*coresCount == 0) |
| 99 | { |
| 100 | // Slot is not populated, set status end return |
| 101 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 102 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 103 | // HTTP Code will be set up automatically, just return |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | aResp->res.jsonValue["TotalCores"] = *coresCount; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 110 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 111 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 112 | |
| 113 | for (const auto &property : properties) |
| 114 | { |
| 115 | if (property.first == "ProcessorType") |
| 116 | { |
| 117 | aResp->res.jsonValue["Name"] = property.second; |
| 118 | } |
| 119 | else if (property.first == "ProcessorManufacturer") |
| 120 | { |
| 121 | aResp->res.jsonValue["Manufacturer"] = property.second; |
| 122 | const std::string *value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 123 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 124 | if (value != nullptr) |
| 125 | { |
| 126 | // Otherwise would be unexpected. |
| 127 | if (value->find("Intel") != std::string::npos) |
| 128 | { |
| 129 | aResp->res.jsonValue["ProcessorArchitecture"] = |
| 130 | "x86"; |
| 131 | aResp->res.jsonValue["InstructionSet"] = "x86-64"; |
| 132 | } |
Gunnar Mills | b957ba5 | 2019-01-31 15:58:15 -0600 | [diff] [blame] | 133 | else if (value->find("IBM") != std::string::npos) |
| 134 | { |
| 135 | aResp->res.jsonValue["ProcessorArchitecture"] = |
| 136 | "Power"; |
| 137 | aResp->res.jsonValue["InstructionSet"] = "PowerISA"; |
| 138 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | else if (property.first == "ProcessorMaxSpeed") |
| 142 | { |
| 143 | aResp->res.jsonValue["MaxSpeedMHz"] = property.second; |
| 144 | } |
| 145 | else if (property.first == "ProcessorThreadCount") |
| 146 | { |
| 147 | aResp->res.jsonValue["TotalThreads"] = property.second; |
| 148 | } |
| 149 | else if (property.first == "ProcessorVersion") |
| 150 | { |
| 151 | aResp->res.jsonValue["Model"] = property.second; |
| 152 | } |
| 153 | } |
| 154 | }, |
| 155 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 156 | } |
| 157 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 158 | void getAcceleratorDataByService(std::shared_ptr<AsyncResp> aResp, |
| 159 | const std::string &acclrtrId, |
| 160 | const std::string &service, |
| 161 | const std::string &objPath) |
| 162 | { |
| 163 | BMCWEB_LOG_DEBUG |
| 164 | << "Get available system Accelerator resources by service."; |
| 165 | crow::connections::systemBus->async_method_call( |
| 166 | [acclrtrId, aResp{std::move(aResp)}]( |
| 167 | const boost::system::error_code ec, |
| 168 | const boost::container::flat_map< |
| 169 | std::string, std::variant<std::string, uint32_t, uint16_t>> |
| 170 | &properties) { |
| 171 | if (ec) |
| 172 | { |
| 173 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 174 | messages::internalError(aResp->res); |
| 175 | return; |
| 176 | } |
| 177 | aResp->res.jsonValue["Id"] = acclrtrId; |
| 178 | aResp->res.jsonValue["Name"] = "Processor"; |
| 179 | const std::string *accPresent = nullptr; |
| 180 | const std::string *accFunctional = nullptr; |
| 181 | std::string state = ""; |
| 182 | |
| 183 | for (const auto &property : properties) |
| 184 | { |
| 185 | if (property.first == "Functional") |
| 186 | { |
| 187 | accFunctional = std::get_if<std::string>(&property.second); |
| 188 | } |
| 189 | else if (property.first == "Present") |
| 190 | { |
| 191 | accPresent = std::get_if<std::string>(&property.second); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | if (!accPresent || !accFunctional) |
| 196 | { |
| 197 | BMCWEB_LOG_DEBUG << "Required properties missing in DBUS " |
| 198 | "response"; |
| 199 | messages::internalError(aResp->res); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if ((*accPresent == "Present") && (*accFunctional == "Functional")) |
| 204 | { |
| 205 | state = "Enabled"; |
| 206 | } |
| 207 | else if (*accPresent == "Present") |
| 208 | { |
| 209 | state = "UnavailableOffline"; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | state = "Absent"; |
| 214 | } |
| 215 | aResp->res.jsonValue["Status"]["State"] = state; |
| 216 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 217 | aResp->res.jsonValue["ProcessorType"] = "Accelerator"; |
| 218 | }, |
| 219 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 220 | } |
| 221 | |
| 222 | void getCpuData(std::shared_ptr<AsyncResp> aResp, const std::string &cpuId, |
| 223 | const std::vector<const char *> inventoryItems) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 224 | { |
| 225 | BMCWEB_LOG_DEBUG << "Get available system cpu resources."; |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 226 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 227 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 228 | [cpuId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 229 | const boost::system::error_code ec, |
| 230 | const boost::container::flat_map< |
| 231 | std::string, boost::container::flat_map< |
| 232 | std::string, std::vector<std::string>>> |
| 233 | &subtree) { |
| 234 | if (ec) |
| 235 | { |
| 236 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 237 | messages::internalError(aResp->res); |
| 238 | return; |
| 239 | } |
| 240 | for (const auto &object : subtree) |
| 241 | { |
| 242 | if (boost::ends_with(object.first, cpuId)) |
| 243 | { |
| 244 | for (const auto &service : object.second) |
| 245 | { |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 246 | for (const auto &inventory : service.second) |
| 247 | if (inventory == |
| 248 | "xyz.openbmc_project.Inventory.Item.Cpu") |
| 249 | { |
| 250 | getCpuDataByService(aResp, cpuId, service.first, |
| 251 | object.first); |
| 252 | } |
| 253 | else if (inventory == "xyz.openbmc_project." |
| 254 | "Inventory.Item.Accelerator") |
| 255 | { |
| 256 | getAcceleratorDataByService( |
| 257 | aResp, cpuId, service.first, object.first); |
| 258 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | // Object not found |
| 264 | messages::resourceNotFound(aResp->res, "Processor", cpuId); |
| 265 | return; |
| 266 | }, |
| 267 | "xyz.openbmc_project.ObjectMapper", |
| 268 | "/xyz/openbmc_project/object_mapper", |
| 269 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 270 | "/xyz/openbmc_project/inventory", int32_t(0), inventoryItems); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 274 | const std::string &dimmId, const std::string &service, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 275 | const std::string &objPath) |
| 276 | { |
| 277 | BMCWEB_LOG_DEBUG << "Get available system components."; |
| 278 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 279 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 280 | const boost::system::error_code ec, |
| 281 | const boost::container::flat_map< |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 282 | std::string, std::variant<std::string, uint32_t, uint16_t>> |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 283 | &properties) { |
| 284 | if (ec) |
| 285 | { |
| 286 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 287 | messages::internalError(aResp->res); |
| 288 | |
| 289 | return; |
| 290 | } |
| 291 | aResp->res.jsonValue["Id"] = dimmId; |
| 292 | aResp->res.jsonValue["Name"] = "DIMM Slot"; |
| 293 | |
| 294 | const auto memorySizeProperty = properties.find("MemorySizeInKB"); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 295 | if (memorySizeProperty != properties.end()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 296 | { |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 297 | const uint32_t *memorySize = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 298 | std::get_if<uint32_t>(&memorySizeProperty->second); |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 299 | if (memorySize == nullptr) |
| 300 | { |
| 301 | // Important property not in desired type |
| 302 | messages::internalError(aResp->res); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 303 | |
Gunnar Mills | aceb7fc | 2018-12-10 15:17:20 -0600 | [diff] [blame] | 304 | return; |
| 305 | } |
| 306 | if (*memorySize == 0) |
| 307 | { |
| 308 | // Slot is not populated, set status end return |
| 309 | aResp->res.jsonValue["Status"]["State"] = "Absent"; |
| 310 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 311 | // HTTP Code will be set up automatically, just return |
| 312 | return; |
| 313 | } |
| 314 | aResp->res.jsonValue["CapacityMiB"] = (*memorySize >> 10); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 315 | } |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 316 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 317 | aResp->res.jsonValue["Status"]["Health"] = "OK"; |
| 318 | |
| 319 | for (const auto &property : properties) |
| 320 | { |
| 321 | if (property.first == "MemoryDataWidth") |
| 322 | { |
| 323 | aResp->res.jsonValue["DataWidthBits"] = property.second; |
| 324 | } |
| 325 | else if (property.first == "MemoryType") |
| 326 | { |
| 327 | const auto *value = |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 328 | std::get_if<std::string>(&property.second); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 329 | if (value != nullptr) |
| 330 | { |
| 331 | aResp->res.jsonValue["MemoryDeviceType"] = *value; |
| 332 | if (boost::starts_with(*value, "DDR")) |
| 333 | { |
| 334 | aResp->res.jsonValue["MemoryType"] = "DRAM"; |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | }, |
| 340 | service, objPath, "org.freedesktop.DBus.Properties", "GetAll", ""); |
| 341 | } |
| 342 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 343 | void getDimmData(std::shared_ptr<AsyncResp> aResp, const std::string &dimmId) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 344 | { |
| 345 | BMCWEB_LOG_DEBUG << "Get available system dimm resources."; |
| 346 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 347 | [dimmId, aResp{std::move(aResp)}]( |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 348 | const boost::system::error_code ec, |
| 349 | const boost::container::flat_map< |
| 350 | std::string, boost::container::flat_map< |
| 351 | std::string, std::vector<std::string>>> |
| 352 | &subtree) { |
| 353 | if (ec) |
| 354 | { |
| 355 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
| 356 | messages::internalError(aResp->res); |
| 357 | |
| 358 | return; |
| 359 | } |
| 360 | for (const auto &object : subtree) |
| 361 | { |
| 362 | if (boost::ends_with(object.first, dimmId)) |
| 363 | { |
| 364 | for (const auto &service : object.second) |
| 365 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 366 | getDimmDataByService(aResp, dimmId, service.first, |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 367 | object.first); |
| 368 | return; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | // Object not found |
| 373 | messages::resourceNotFound(aResp->res, "Memory", dimmId); |
| 374 | return; |
| 375 | }, |
| 376 | "xyz.openbmc_project.ObjectMapper", |
| 377 | "/xyz/openbmc_project/object_mapper", |
| 378 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 379 | "/xyz/openbmc_project/inventory", int32_t(0), |
| 380 | std::array<const char *, 1>{"xyz.openbmc_project.Inventory.Item.Dimm"}); |
| 381 | }; |
| 382 | |
| 383 | class ProcessorCollection : public Node |
| 384 | { |
| 385 | public: |
| 386 | /* |
| 387 | * Default Constructor |
| 388 | */ |
| 389 | ProcessorCollection(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 390 | Node(app, "/redfish/v1/Systems/system/Processors/") |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 391 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 392 | entityPrivileges = { |
| 393 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 394 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 395 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 396 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 397 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 398 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 399 | } |
| 400 | |
| 401 | private: |
| 402 | /** |
| 403 | * Functions triggers appropriate requests on DBus |
| 404 | */ |
| 405 | void doGet(crow::Response &res, const crow::Request &req, |
| 406 | const std::vector<std::string> ¶ms) override |
| 407 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 408 | res.jsonValue["@odata.type"] = |
| 409 | "#ProcessorCollection.ProcessorCollection"; |
| 410 | res.jsonValue["Name"] = "Processor Collection"; |
| 411 | res.jsonValue["@odata.context"] = |
| 412 | "/redfish/v1/$metadata#ProcessorCollection.ProcessorCollection"; |
| 413 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 414 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 415 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 416 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 417 | getResourceList(asyncResp, "Processors", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 418 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 419 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 420 | } |
| 421 | }; |
| 422 | |
| 423 | class Processor : public Node |
| 424 | { |
| 425 | public: |
| 426 | /* |
| 427 | * Default Constructor |
| 428 | */ |
| 429 | Processor(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 430 | Node(app, "/redfish/v1/Systems/system/Processors/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 431 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 432 | entityPrivileges = { |
| 433 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 434 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 435 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 436 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 437 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 438 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 439 | } |
| 440 | |
| 441 | private: |
| 442 | /** |
| 443 | * Functions triggers appropriate requests on DBus |
| 444 | */ |
| 445 | void doGet(crow::Response &res, const crow::Request &req, |
| 446 | const std::vector<std::string> ¶ms) override |
| 447 | { |
| 448 | // Check if there is required param, truly entering this shall be |
| 449 | // impossible |
| 450 | if (params.size() != 1) |
| 451 | { |
| 452 | messages::internalError(res); |
| 453 | |
| 454 | res.end(); |
| 455 | return; |
| 456 | } |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 457 | const std::string &processorId = params[0]; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 458 | res.jsonValue["@odata.type"] = "#Processor.v1_3_1.Processor"; |
| 459 | res.jsonValue["@odata.context"] = |
| 460 | "/redfish/v1/$metadata#Processor.Processor"; |
| 461 | res.jsonValue["@odata.id"] = |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 462 | "/redfish/v1/Systems/system/Processors/" + processorId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 463 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 464 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 465 | |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 466 | getCpuData(asyncResp, processorId, |
| 467 | {"xyz.openbmc_project.Inventory.Item.Cpu", |
| 468 | "xyz.openbmc_project.Inventory.Item.Accelerator"}); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 469 | } |
| 470 | }; |
| 471 | |
| 472 | class MemoryCollection : public Node |
| 473 | { |
| 474 | public: |
| 475 | /* |
| 476 | * Default Constructor |
| 477 | */ |
| 478 | MemoryCollection(CrowApp &app) : |
| 479 | Node(app, "/redfish/v1/Systems/system/Memory/") |
| 480 | { |
| 481 | entityPrivileges = { |
| 482 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 483 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 484 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 485 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 486 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 487 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 488 | } |
| 489 | |
| 490 | private: |
| 491 | /** |
| 492 | * Functions triggers appropriate requests on DBus |
| 493 | */ |
| 494 | void doGet(crow::Response &res, const crow::Request &req, |
| 495 | const std::vector<std::string> ¶ms) override |
| 496 | { |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 497 | res.jsonValue["@odata.type"] = "#MemoryCollection.MemoryCollection"; |
| 498 | res.jsonValue["Name"] = "Memory Module Collection"; |
| 499 | res.jsonValue["@odata.context"] = |
| 500 | "/redfish/v1/$metadata#MemoryCollection.MemoryCollection"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 501 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory/"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 502 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 503 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 504 | getResourceList(asyncResp, "Memory", |
Alpana Kumari | 32bee76 | 2019-04-25 04:47:57 -0500 | [diff] [blame^] | 505 | {"xyz.openbmc_project.Inventory.Item.Dimm"}); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 506 | } |
| 507 | }; |
| 508 | |
| 509 | class Memory : public Node |
| 510 | { |
| 511 | public: |
| 512 | /* |
| 513 | * Default Constructor |
| 514 | */ |
| 515 | Memory(CrowApp &app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 516 | Node(app, "/redfish/v1/Systems/system/Memory/<str>/", std::string()) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 517 | { |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 518 | entityPrivileges = { |
| 519 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 520 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 521 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 522 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 523 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 524 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 525 | } |
| 526 | |
| 527 | private: |
| 528 | /** |
| 529 | * Functions triggers appropriate requests on DBus |
| 530 | */ |
| 531 | void doGet(crow::Response &res, const crow::Request &req, |
| 532 | const std::vector<std::string> ¶ms) override |
| 533 | { |
| 534 | // Check if there is required param, truly entering this shall be |
| 535 | // impossible |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 536 | if (params.size() != 1) |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 537 | { |
| 538 | messages::internalError(res); |
| 539 | res.end(); |
| 540 | return; |
| 541 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 542 | const std::string &dimmId = params[0]; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 543 | |
Rapkiewicz, Pawel | bb3d994 | 2018-11-22 10:59:11 +0100 | [diff] [blame] | 544 | res.jsonValue["@odata.type"] = "#Memory.v1_6_0.Memory"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 545 | res.jsonValue["@odata.context"] = "/redfish/v1/$metadata#Memory.Memory"; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 546 | res.jsonValue["@odata.id"] = |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 547 | "/redfish/v1/Systems/system/Memory/" + dimmId; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 548 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 549 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 550 | getDimmData(asyncResp, dimmId); |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 551 | } |
| 552 | }; |
| 553 | |
| 554 | } // namespace redfish |