Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +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 | |
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" |
Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 20 | #include "pcie.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 21 | #include "redfish_util.hpp" |
| 22 | |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 23 | #include <boost/container/flat_map.hpp> |
| 24 | #include <node.hpp> |
Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 25 | #include <utils/fw_utils.hpp> |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 26 | #include <utils/json_utils.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 27 | |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 28 | #include <variant> |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 29 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 30 | namespace redfish |
| 31 | { |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 32 | |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 33 | /** |
| 34 | * @brief Updates the Functional State of DIMMs |
| 35 | * |
| 36 | * @param[in] aResp Shared pointer for completing asynchronous calls |
| 37 | * @param[in] dimmState Dimm's Functional state, true/false |
| 38 | * |
| 39 | * @return None. |
| 40 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 41 | inline void updateDimmProperties(std::shared_ptr<AsyncResp> aResp, |
| 42 | const std::variant<bool>& dimmState) |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 43 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 44 | const bool* isDimmFunctional = std::get_if<bool>(&dimmState); |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 45 | if (isDimmFunctional == nullptr) |
| 46 | { |
| 47 | messages::internalError(aResp->res); |
| 48 | return; |
| 49 | } |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 50 | BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 51 | |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 52 | // Set it as Enabled if at least one DIMM is functional |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 53 | // Update STATE only if previous State was DISABLED and current Dimm is |
| 54 | // ENABLED. |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 55 | nlohmann::json& prevMemSummary = |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 56 | aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; |
| 57 | if (prevMemSummary == "Disabled") |
| 58 | { |
| 59 | if (*isDimmFunctional == true) |
| 60 | { |
| 61 | aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = |
| 62 | "Enabled"; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 67 | /* |
| 68 | * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState |
| 69 | * |
| 70 | * @param[in] aResp Shared pointer for completing asynchronous calls |
| 71 | * @param[in] cpuPresenceState CPU present or not |
| 72 | * |
| 73 | * @return None. |
| 74 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 75 | inline void modifyCpuPresenceState(std::shared_ptr<AsyncResp> aResp, |
| 76 | const std::variant<bool>& cpuPresenceState) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 77 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 78 | const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 79 | |
| 80 | if (isCpuPresent == nullptr) |
| 81 | { |
| 82 | messages::internalError(aResp->res); |
| 83 | return; |
| 84 | } |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 85 | BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 86 | |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 87 | if (*isCpuPresent == true) |
| 88 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 89 | nlohmann::json& procCount = |
James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 90 | aResp->res.jsonValue["ProcessorSummary"]["Count"]; |
| 91 | auto procCountPtr = |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 92 | procCount.get_ptr<nlohmann::json::number_integer_t*>(); |
James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 93 | if (procCountPtr != nullptr) |
| 94 | { |
| 95 | // shouldn't be possible to be nullptr |
| 96 | *procCountPtr += 1; |
| 97 | } |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 98 | } |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * @brief Update "ProcessorSummary" "Status" "State" based on |
| 103 | * CPU Functional State |
| 104 | * |
| 105 | * @param[in] aResp Shared pointer for completing asynchronous calls |
| 106 | * @param[in] cpuFunctionalState is CPU functional true/false |
| 107 | * |
| 108 | * @return None. |
| 109 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 110 | inline void |
| 111 | modifyCpuFunctionalState(std::shared_ptr<AsyncResp> aResp, |
| 112 | const std::variant<bool>& cpuFunctionalState) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 113 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 114 | const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 115 | |
| 116 | if (isCpuFunctional == nullptr) |
| 117 | { |
| 118 | messages::internalError(aResp->res); |
| 119 | return; |
| 120 | } |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 121 | BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 122 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 123 | nlohmann::json& prevProcState = |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 124 | aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; |
| 125 | |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 126 | // Set it as Enabled if at least one CPU is functional |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 127 | // Update STATE only if previous State was Non_Functional and current CPU is |
| 128 | // Functional. |
| 129 | if (prevProcState == "Disabled") |
| 130 | { |
| 131 | if (*isCpuFunctional == true) |
| 132 | { |
| 133 | aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = |
| 134 | "Enabled"; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /* |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 140 | * @brief Retrieves computer system properties over dbus |
| 141 | * |
| 142 | * @param[in] aResp Shared pointer for completing asynchronous calls |
| 143 | * @param[in] name Computer system name from request |
| 144 | * |
| 145 | * @return None. |
| 146 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 147 | inline void getComputerSystem(std::shared_ptr<AsyncResp> aResp, |
| 148 | std::shared_ptr<HealthPopulate> systemHealth) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 149 | { |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 150 | BMCWEB_LOG_DEBUG << "Get available system components."; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 151 | |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 152 | crow::connections::systemBus->async_method_call( |
James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 153 | [aResp, systemHealth]( |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 154 | const boost::system::error_code ec, |
| 155 | const std::vector<std::pair< |
| 156 | std::string, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 157 | std::vector<std::pair<std::string, std::vector<std::string>>>>>& |
| 158 | subtree) { |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 159 | if (ec) |
| 160 | { |
| 161 | BMCWEB_LOG_DEBUG << "DBUS response error"; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 162 | messages::internalError(aResp->res); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 163 | return; |
| 164 | } |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 165 | // Iterate over all retrieved ObjectPaths. |
| 166 | for (const std::pair<std::string, |
| 167 | std::vector<std::pair< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 168 | std::string, std::vector<std::string>>>>& |
| 169 | object : subtree) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 170 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 171 | const std::string& path = object.first; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 172 | BMCWEB_LOG_DEBUG << "Got path: " << path; |
| 173 | const std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 174 | std::pair<std::string, std::vector<std::string>>>& |
| 175 | connectionNames = object.second; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 176 | if (connectionNames.size() < 1) |
| 177 | { |
| 178 | continue; |
| 179 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 180 | |
James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 181 | auto memoryHealth = std::make_shared<HealthPopulate>( |
| 182 | aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); |
| 183 | |
| 184 | auto cpuHealth = std::make_shared<HealthPopulate>( |
| 185 | aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); |
| 186 | |
| 187 | systemHealth->children.emplace_back(memoryHealth); |
| 188 | systemHealth->children.emplace_back(cpuHealth); |
| 189 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 190 | // This is not system, so check if it's cpu, dimm, UUID or |
| 191 | // BiosVer |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 192 | for (const auto& connection : connectionNames) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 193 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 194 | for (const auto& interfaceName : connection.second) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 195 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 196 | if (interfaceName == |
| 197 | "xyz.openbmc_project.Inventory.Item.Dimm") |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 198 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 199 | BMCWEB_LOG_DEBUG |
| 200 | << "Found Dimm, now get its properties."; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 201 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 202 | crow::connections::systemBus->async_method_call( |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 203 | [aResp, service{connection.first}, |
| 204 | path(std::move(path))]( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 205 | const boost::system::error_code ec2, |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 206 | const std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 207 | std::pair<std::string, VariantType>>& |
| 208 | properties) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 209 | if (ec2) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 210 | { |
| 211 | BMCWEB_LOG_ERROR |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 212 | << "DBUS response error " << ec2; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 213 | messages::internalError(aResp->res); |
| 214 | return; |
| 215 | } |
| 216 | BMCWEB_LOG_DEBUG << "Got " |
| 217 | << properties.size() |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 218 | << " Dimm properties."; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 219 | |
| 220 | if (properties.size() > 0) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 221 | { |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 222 | for (const std::pair<std::string, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 223 | VariantType>& |
| 224 | property : properties) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 225 | { |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 226 | if (property.first != |
| 227 | "MemorySizeInKB") |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 228 | { |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 229 | continue; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 230 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 231 | const uint32_t* value = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 232 | std::get_if<uint32_t>( |
| 233 | &property.second); |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 234 | if (value == nullptr) |
| 235 | { |
| 236 | BMCWEB_LOG_DEBUG |
| 237 | << "Find incorrect type of " |
| 238 | "MemorySize"; |
| 239 | continue; |
| 240 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 241 | nlohmann::json& totalMemory = |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 242 | aResp->res |
| 243 | .jsonValue["MemorySummar" |
| 244 | "y"] |
| 245 | ["TotalSystemMe" |
| 246 | "moryGiB"]; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 247 | uint64_t* preValue = |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 248 | totalMemory |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 249 | .get_ptr<uint64_t*>(); |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 250 | if (preValue == nullptr) |
| 251 | { |
| 252 | continue; |
| 253 | } |
| 254 | aResp->res |
| 255 | .jsonValue["MemorySummary"] |
| 256 | ["TotalSystemMemoryGi" |
| 257 | "B"] = |
| 258 | *value / (1024 * 1024) + |
| 259 | *preValue; |
| 260 | aResp->res |
| 261 | .jsonValue["MemorySummary"] |
| 262 | ["Status"]["State"] = |
| 263 | "Enabled"; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 264 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 265 | } |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 266 | else |
| 267 | { |
| 268 | auto getDimmProperties = |
| 269 | [aResp]( |
| 270 | const boost::system::error_code |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 271 | ec3, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 272 | const std::variant<bool>& |
| 273 | dimmState) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 274 | if (ec3) |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 275 | { |
| 276 | BMCWEB_LOG_ERROR |
| 277 | << "DBUS response " |
| 278 | "error " |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 279 | << ec3; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 280 | return; |
| 281 | } |
| 282 | updateDimmProperties(aResp, |
| 283 | dimmState); |
| 284 | }; |
| 285 | crow::connections::systemBus |
| 286 | ->async_method_call( |
| 287 | std::move(getDimmProperties), |
| 288 | service, path, |
| 289 | "org.freedesktop.DBus." |
| 290 | "Properties", |
| 291 | "Get", |
| 292 | "xyz.openbmc_project.State." |
| 293 | "Decorator.OperationalStatus", |
| 294 | "Functional"); |
| 295 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 296 | }, |
| 297 | connection.first, path, |
| 298 | "org.freedesktop.DBus.Properties", "GetAll", |
| 299 | "xyz.openbmc_project.Inventory.Item.Dimm"); |
James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 300 | |
| 301 | memoryHealth->inventory.emplace_back(path); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 302 | } |
| 303 | else if (interfaceName == |
| 304 | "xyz.openbmc_project.Inventory.Item.Cpu") |
| 305 | { |
| 306 | BMCWEB_LOG_DEBUG |
| 307 | << "Found Cpu, now get its properties."; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 308 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 309 | crow::connections::systemBus->async_method_call( |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 310 | [aResp, service{connection.first}, |
| 311 | path(std::move(path))]( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 312 | const boost::system::error_code ec2, |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 313 | const std::vector< |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 314 | std::pair<std::string, VariantType>>& |
| 315 | properties) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 316 | if (ec2) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 317 | { |
| 318 | BMCWEB_LOG_ERROR |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 319 | << "DBUS response error " << ec2; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 320 | messages::internalError(aResp->res); |
| 321 | return; |
| 322 | } |
| 323 | BMCWEB_LOG_DEBUG << "Got " |
| 324 | << properties.size() |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 325 | << " Cpu properties."; |
Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 326 | |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 327 | if (properties.size() > 0) |
| 328 | { |
Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 329 | const uint64_t* processorId = nullptr; |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 330 | const std::string* procFamily = nullptr; |
| 331 | nlohmann::json& procSummary = |
| 332 | aResp->res.jsonValue["ProcessorSumm" |
| 333 | "ary"]; |
| 334 | nlohmann::json& procCount = |
| 335 | procSummary["Count"]; |
| 336 | |
| 337 | auto procCountPtr = procCount.get_ptr< |
| 338 | nlohmann::json:: |
| 339 | number_integer_t*>(); |
| 340 | if (procCountPtr == nullptr) |
| 341 | { |
| 342 | messages::internalError(aResp->res); |
| 343 | return; |
| 344 | } |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 345 | for (const auto& property : properties) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 346 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 347 | |
Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 348 | if (property.first == "Id") |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 349 | { |
| 350 | processorId = |
Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 351 | std::get_if<uint64_t>( |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 352 | &property.second); |
| 353 | if (nullptr != procFamily) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 354 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 355 | break; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 356 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 357 | continue; |
| 358 | } |
| 359 | |
Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 360 | if (property.first == "Family") |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 361 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 362 | procFamily = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 363 | std::get_if<std::string>( |
| 364 | &property.second); |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 365 | if (nullptr != processorId) |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 366 | { |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 367 | break; |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 368 | } |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 369 | continue; |
| 370 | } |
| 371 | } |
James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 372 | |
Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 373 | if (procFamily != nullptr && |
| 374 | processorId != nullptr) |
| 375 | { |
| 376 | if (procCountPtr != nullptr && |
| 377 | *processorId != 0) |
| 378 | { |
| 379 | *procCountPtr += 1; |
| 380 | procSummary["Status"]["State"] = |
| 381 | "Enabled"; |
| 382 | |
| 383 | procSummary["Model"] = |
| 384 | *procFamily; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 387 | } |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 388 | else |
| 389 | { |
| 390 | auto getCpuPresenceState = |
| 391 | [aResp]( |
| 392 | const boost::system::error_code |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 393 | ec3, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 394 | const std::variant<bool>& |
| 395 | cpuPresenceCheck) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 396 | if (ec3) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 397 | { |
| 398 | BMCWEB_LOG_ERROR |
| 399 | << "DBUS response " |
| 400 | "error " |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 401 | << ec3; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 402 | return; |
| 403 | } |
| 404 | modifyCpuPresenceState( |
| 405 | aResp, cpuPresenceCheck); |
| 406 | }; |
| 407 | |
| 408 | auto getCpuFunctionalState = |
| 409 | [aResp]( |
| 410 | const boost::system::error_code |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 411 | ec3, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 412 | const std::variant<bool>& |
| 413 | cpuFunctionalCheck) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 414 | if (ec3) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 415 | { |
| 416 | BMCWEB_LOG_ERROR |
| 417 | << "DBUS response " |
| 418 | "error " |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 419 | << ec3; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 420 | return; |
| 421 | } |
| 422 | modifyCpuFunctionalState( |
| 423 | aResp, cpuFunctionalCheck); |
| 424 | }; |
| 425 | // Get the Presence of CPU |
| 426 | crow::connections::systemBus |
| 427 | ->async_method_call( |
| 428 | std::move(getCpuPresenceState), |
| 429 | service, path, |
| 430 | "org.freedesktop.DBus." |
| 431 | "Properties", |
| 432 | "Get", |
| 433 | "xyz.openbmc_project.Inventory." |
| 434 | "Item", |
| 435 | "Present"); |
| 436 | |
| 437 | // Get the Functional State |
| 438 | crow::connections::systemBus |
| 439 | ->async_method_call( |
| 440 | std::move( |
| 441 | getCpuFunctionalState), |
| 442 | service, path, |
| 443 | "org.freedesktop.DBus." |
| 444 | "Properties", |
| 445 | "Get", |
| 446 | "xyz.openbmc_project.State." |
| 447 | "Decorator." |
| 448 | "OperationalStatus", |
| 449 | "Functional"); |
| 450 | |
| 451 | // Get the MODEL from |
| 452 | // xyz.openbmc_project.Inventory.Decorator.Asset |
| 453 | // support it later as Model is Empty |
| 454 | // currently. |
| 455 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 456 | }, |
| 457 | connection.first, path, |
| 458 | "org.freedesktop.DBus.Properties", "GetAll", |
| 459 | "xyz.openbmc_project.Inventory.Item.Cpu"); |
James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 460 | |
| 461 | cpuHealth->inventory.emplace_back(path); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 462 | } |
| 463 | else if (interfaceName == |
| 464 | "xyz.openbmc_project.Common.UUID") |
| 465 | { |
| 466 | BMCWEB_LOG_DEBUG |
| 467 | << "Found UUID, now get its properties."; |
| 468 | crow::connections::systemBus->async_method_call( |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 469 | [aResp]( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 470 | const boost::system::error_code ec3, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 471 | const std::vector< |
| 472 | std::pair<std::string, VariantType>>& |
| 473 | properties) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 474 | if (ec3) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 475 | { |
| 476 | BMCWEB_LOG_DEBUG |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 477 | << "DBUS response error " << ec3; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 478 | messages::internalError(aResp->res); |
| 479 | return; |
| 480 | } |
| 481 | BMCWEB_LOG_DEBUG << "Got " |
| 482 | << properties.size() |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 483 | << " UUID properties."; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 484 | for (const std::pair<std::string, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 485 | VariantType>& |
| 486 | property : properties) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 487 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 488 | if (property.first == "UUID") |
| 489 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 490 | const std::string* value = |
Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 491 | std::get_if<std::string>( |
| 492 | &property.second); |
Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 493 | |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 494 | if (value != nullptr) |
| 495 | { |
| 496 | std::string valueStr = *value; |
| 497 | if (valueStr.size() == 32) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 498 | { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 499 | valueStr.insert(8, 1, '-'); |
| 500 | valueStr.insert(13, 1, '-'); |
| 501 | valueStr.insert(18, 1, '-'); |
| 502 | valueStr.insert(23, 1, '-'); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 503 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 504 | BMCWEB_LOG_DEBUG << "UUID = " |
| 505 | << valueStr; |
| 506 | aResp->res.jsonValue["UUID"] = |
| 507 | valueStr; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 510 | } |
| 511 | }, |
| 512 | connection.first, path, |
| 513 | "org.freedesktop.DBus.Properties", "GetAll", |
| 514 | "xyz.openbmc_project.Common.UUID"); |
| 515 | } |
| 516 | else if (interfaceName == |
| 517 | "xyz.openbmc_project.Inventory.Item.System") |
| 518 | { |
| 519 | crow::connections::systemBus->async_method_call( |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 520 | [aResp]( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 521 | const boost::system::error_code ec2, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 522 | const std::vector< |
| 523 | std::pair<std::string, VariantType>>& |
| 524 | propertiesList) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 525 | if (ec2) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 526 | { |
James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 527 | // doesn't have to include this |
| 528 | // interface |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 529 | return; |
| 530 | } |
Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 531 | BMCWEB_LOG_DEBUG |
| 532 | << "Got " << propertiesList.size() |
| 533 | << " properties for system"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 534 | for (const std::pair<std::string, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 535 | VariantType>& |
| 536 | property : propertiesList) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 537 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 538 | const std::string& propertyName = |
beccabroek | fc5afcf | 2019-03-05 14:35:15 -0600 | [diff] [blame] | 539 | property.first; |
| 540 | if ((propertyName == "PartNumber") || |
| 541 | (propertyName == "SerialNumber") || |
| 542 | (propertyName == "Manufacturer") || |
| 543 | (propertyName == "Model")) |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 544 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 545 | const std::string* value = |
beccabroek | fc5afcf | 2019-03-05 14:35:15 -0600 | [diff] [blame] | 546 | std::get_if<std::string>( |
| 547 | &property.second); |
| 548 | if (value != nullptr) |
| 549 | { |
| 550 | aResp->res |
| 551 | .jsonValue[propertyName] = |
| 552 | *value; |
| 553 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 554 | } |
| 555 | } |
Gunnar Mills | c1e236a | 2020-04-14 21:36:33 -0500 | [diff] [blame] | 556 | |
Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 557 | // Grab the bios version |
Gunnar Mills | f97ddba | 2020-08-20 15:57:40 -0500 | [diff] [blame] | 558 | fw_util::populateFirmwareInformation( |
Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 559 | aResp, fw_util::biosPurpose, |
Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame] | 560 | "BiosVersion", false); |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 561 | }, |
| 562 | connection.first, path, |
| 563 | "org.freedesktop.DBus.Properties", "GetAll", |
| 564 | "xyz.openbmc_project.Inventory.Decorator." |
| 565 | "Asset"); |
James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 566 | |
| 567 | crow::connections::systemBus->async_method_call( |
| 568 | [aResp]( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 569 | const boost::system::error_code ec2, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 570 | const std::variant<std::string>& property) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 571 | if (ec2) |
James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 572 | { |
| 573 | // doesn't have to include this |
| 574 | // interface |
| 575 | return; |
| 576 | } |
| 577 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 578 | const std::string* value = |
James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 579 | std::get_if<std::string>(&property); |
| 580 | if (value != nullptr) |
| 581 | { |
| 582 | aResp->res.jsonValue["AssetTag"] = |
| 583 | *value; |
| 584 | } |
| 585 | }, |
| 586 | connection.first, path, |
| 587 | "org.freedesktop.DBus.Properties", "Get", |
| 588 | "xyz.openbmc_project.Inventory.Decorator." |
| 589 | "AssetTag", |
| 590 | "AssetTag"); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | } |
| 594 | } |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 595 | }, |
| 596 | "xyz.openbmc_project.ObjectMapper", |
| 597 | "/xyz/openbmc_project/object_mapper", |
| 598 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 599 | "/xyz/openbmc_project/inventory", int32_t(0), |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 600 | std::array<const char*, 5>{ |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 601 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 602 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 603 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 604 | "xyz.openbmc_project.Inventory.Item.System", |
| 605 | "xyz.openbmc_project.Common.UUID", |
| 606 | }); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /** |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 610 | * @brief Retrieves host state properties over dbus |
| 611 | * |
| 612 | * @param[in] aResp Shared pointer for completing asynchronous calls. |
| 613 | * |
| 614 | * @return None. |
| 615 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 616 | inline void getHostState(std::shared_ptr<AsyncResp> aResp) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 617 | { |
| 618 | BMCWEB_LOG_DEBUG << "Get host information."; |
| 619 | crow::connections::systemBus->async_method_call( |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 620 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 621 | const std::variant<std::string>& hostState) { |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 622 | if (ec) |
| 623 | { |
| 624 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 625 | messages::internalError(aResp->res); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 626 | return; |
| 627 | } |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 628 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 629 | const std::string* s = std::get_if<std::string>(&hostState); |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 630 | BMCWEB_LOG_DEBUG << "Host state: " << *s; |
| 631 | if (s != nullptr) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 632 | { |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 633 | // Verify Host State |
Andrew Geissler | 9473266 | 2019-01-08 19:32:16 -0800 | [diff] [blame] | 634 | if (*s == "xyz.openbmc_project.State.Host.HostState.Running") |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 635 | { |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 636 | aResp->res.jsonValue["PowerState"] = "On"; |
| 637 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 638 | } |
Andrew Geissler | 83935af | 2020-02-13 10:24:53 -0600 | [diff] [blame] | 639 | else if (*s == "xyz.openbmc_project.State.Host.HostState." |
Gunnar Mills | 8c88860 | 2020-05-01 14:25:09 -0500 | [diff] [blame] | 640 | "Quiesced") |
| 641 | { |
| 642 | aResp->res.jsonValue["PowerState"] = "On"; |
| 643 | aResp->res.jsonValue["Status"]["State"] = "Quiesced"; |
| 644 | } |
| 645 | else if (*s == "xyz.openbmc_project.State.Host.HostState." |
Andrew Geissler | 83935af | 2020-02-13 10:24:53 -0600 | [diff] [blame] | 646 | "DiagnosticMode") |
| 647 | { |
| 648 | aResp->res.jsonValue["PowerState"] = "On"; |
| 649 | aResp->res.jsonValue["Status"]["State"] = "InTest"; |
| 650 | } |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 651 | else |
| 652 | { |
| 653 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 654 | aResp->res.jsonValue["Status"]["State"] = "Disabled"; |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | }, |
| 658 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 659 | "org.freedesktop.DBus.Properties", "Get", |
| 660 | "xyz.openbmc_project.State.Host", "CurrentHostState"); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 664 | * @brief Translates boot source DBUS property value to redfish. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 665 | * |
| 666 | * @param[in] dbusSource The boot source in DBUS speak. |
| 667 | * |
| 668 | * @return Returns as a string, the boot source in Redfish terms. If translation |
| 669 | * cannot be done, returns an empty string. |
| 670 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 671 | inline std::string dbusToRfBootSource(const std::string& dbusSource) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 672 | { |
| 673 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") |
| 674 | { |
| 675 | return "None"; |
| 676 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 677 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 678 | { |
| 679 | return "Hdd"; |
| 680 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 681 | if (dbusSource == |
| 682 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 683 | { |
| 684 | return "Cd"; |
| 685 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 686 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 687 | { |
| 688 | return "Pxe"; |
| 689 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 690 | if (dbusSource == |
| 691 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 692 | { |
| 693 | return "Usb"; |
| 694 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 695 | return ""; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 699 | * @brief Translates boot mode DBUS property value to redfish. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 700 | * |
| 701 | * @param[in] dbusMode The boot mode in DBUS speak. |
| 702 | * |
| 703 | * @return Returns as a string, the boot mode in Redfish terms. If translation |
| 704 | * cannot be done, returns an empty string. |
| 705 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 706 | inline std::string dbusToRfBootMode(const std::string& dbusMode) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 707 | { |
| 708 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") |
| 709 | { |
| 710 | return "None"; |
| 711 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 712 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 713 | { |
| 714 | return "Diags"; |
| 715 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 716 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 717 | { |
| 718 | return "BiosSetup"; |
| 719 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 720 | return ""; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 724 | * @brief Translates boot source from Redfish to the DBus boot paths. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 725 | * |
| 726 | * @param[in] rfSource The boot source in Redfish. |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 727 | * @param[out] bootSource The DBus source |
| 728 | * @param[out] bootMode the DBus boot mode |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 729 | * |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 730 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 731 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 732 | inline int assignBootParameters(std::shared_ptr<AsyncResp> aResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 733 | const std::string& rfSource, |
| 734 | std::string& bootSource, std::string& bootMode) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 735 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 736 | // The caller has initialized the bootSource and bootMode to: |
| 737 | // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
| 738 | // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; |
| 739 | // Only modify the bootSource/bootMode variable needed to achieve the |
| 740 | // desired boot action. |
| 741 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 742 | if (rfSource == "None") |
| 743 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 744 | return 0; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 745 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 746 | if (rfSource == "Pxe") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 747 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 748 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; |
| 749 | } |
| 750 | else if (rfSource == "Hdd") |
| 751 | { |
| 752 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; |
| 753 | } |
| 754 | else if (rfSource == "Diags") |
| 755 | { |
| 756 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; |
| 757 | } |
| 758 | else if (rfSource == "Cd") |
| 759 | { |
| 760 | bootSource = |
| 761 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; |
| 762 | } |
| 763 | else if (rfSource == "BiosSetup") |
| 764 | { |
| 765 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 766 | } |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 767 | else if (rfSource == "Usb") |
| 768 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 769 | bootSource = |
| 770 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 771 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 772 | else |
| 773 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 774 | BMCWEB_LOG_DEBUG << "Invalid property value for " |
| 775 | "BootSourceOverrideTarget: " |
| 776 | << bootSource; |
| 777 | messages::propertyValueNotInList(aResp->res, rfSource, |
| 778 | "BootSourceTargetOverride"); |
| 779 | return -1; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 780 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 781 | return 0; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /** |
| 785 | * @brief Retrieves boot mode over DBUS and fills out the response |
| 786 | * |
| 787 | * @param[in] aResp Shared pointer for generating response message. |
| 788 | * @param[in] bootDbusObj The dbus object to query for boot properties. |
| 789 | * |
| 790 | * @return None. |
| 791 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 792 | inline void getBootMode(std::shared_ptr<AsyncResp> aResp, |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 793 | std::string bootDbusObj) |
| 794 | { |
| 795 | crow::connections::systemBus->async_method_call( |
| 796 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 797 | const std::variant<std::string>& bootMode) { |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 798 | if (ec) |
| 799 | { |
| 800 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 801 | messages::internalError(aResp->res); |
| 802 | return; |
| 803 | } |
| 804 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 805 | const std::string* bootModeStr = |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 806 | std::get_if<std::string>(&bootMode); |
| 807 | |
| 808 | if (!bootModeStr) |
| 809 | { |
| 810 | messages::internalError(aResp->res); |
| 811 | return; |
| 812 | } |
| 813 | |
| 814 | BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; |
| 815 | |
| 816 | // TODO (Santosh): Do we need to support override mode? |
| 817 | aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; |
| 818 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." |
| 819 | "AllowableValues"] = { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 820 | "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 821 | |
| 822 | if (*bootModeStr != |
| 823 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") |
| 824 | { |
| 825 | auto rfMode = dbusToRfBootMode(*bootModeStr); |
| 826 | if (!rfMode.empty()) |
| 827 | { |
| 828 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = |
| 829 | rfMode; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | // If the BootSourceOverrideTarget is still "None" at the end, |
| 834 | // reset the BootSourceOverrideEnabled to indicate that |
| 835 | // overrides are disabled |
| 836 | if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == |
| 837 | "None") |
| 838 | { |
| 839 | aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = |
| 840 | "Disabled"; |
| 841 | } |
| 842 | }, |
| 843 | "xyz.openbmc_project.Settings", bootDbusObj, |
| 844 | "org.freedesktop.DBus.Properties", "Get", |
| 845 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * @brief Retrieves boot source over DBUS |
| 850 | * |
| 851 | * @param[in] aResp Shared pointer for generating response message. |
| 852 | * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. |
| 853 | * |
| 854 | * @return None. |
| 855 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 856 | inline void getBootSource(std::shared_ptr<AsyncResp> aResp, bool oneTimeEnabled) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 857 | { |
| 858 | std::string bootDbusObj = |
| 859 | oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" |
| 860 | : "/xyz/openbmc_project/control/host0/boot"; |
| 861 | |
| 862 | BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; |
| 863 | aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = |
| 864 | (oneTimeEnabled) ? "Once" : "Continuous"; |
| 865 | |
| 866 | crow::connections::systemBus->async_method_call( |
| 867 | [aResp, bootDbusObj](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 868 | const std::variant<std::string>& bootSource) { |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 869 | if (ec) |
| 870 | { |
| 871 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 872 | messages::internalError(aResp->res); |
| 873 | return; |
| 874 | } |
| 875 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 876 | const std::string* bootSourceStr = |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 877 | std::get_if<std::string>(&bootSource); |
| 878 | |
| 879 | if (!bootSourceStr) |
| 880 | { |
| 881 | messages::internalError(aResp->res); |
| 882 | return; |
| 883 | } |
| 884 | BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; |
| 885 | |
| 886 | auto rfSource = dbusToRfBootSource(*bootSourceStr); |
| 887 | if (!rfSource.empty()) |
| 888 | { |
| 889 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = |
| 890 | rfSource; |
| 891 | } |
| 892 | }, |
| 893 | "xyz.openbmc_project.Settings", bootDbusObj, |
| 894 | "org.freedesktop.DBus.Properties", "Get", |
| 895 | "xyz.openbmc_project.Control.Boot.Source", "BootSource"); |
| 896 | getBootMode(std::move(aResp), std::move(bootDbusObj)); |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * @brief Retrieves "One time" enabled setting over DBUS and calls function to |
| 901 | * get boot source and boot mode. |
| 902 | * |
| 903 | * @param[in] aResp Shared pointer for generating response message. |
| 904 | * |
| 905 | * @return None. |
| 906 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 907 | inline void getBootProperties(std::shared_ptr<AsyncResp> aResp) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 908 | { |
| 909 | BMCWEB_LOG_DEBUG << "Get boot information."; |
| 910 | |
| 911 | crow::connections::systemBus->async_method_call( |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 912 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 913 | const std::variant<bool>& oneTime) { |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 914 | if (ec) |
| 915 | { |
| 916 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
James Feist | 2a833c7 | 2019-07-19 10:17:13 -0700 | [diff] [blame] | 917 | // not an error, don't have to have the interface |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 918 | return; |
| 919 | } |
| 920 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 921 | const bool* oneTimePtr = std::get_if<bool>(&oneTime); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 922 | |
| 923 | if (!oneTimePtr) |
| 924 | { |
| 925 | messages::internalError(aResp->res); |
| 926 | return; |
| 927 | } |
| 928 | getBootSource(aResp, *oneTimePtr); |
| 929 | }, |
| 930 | "xyz.openbmc_project.Settings", |
| 931 | "/xyz/openbmc_project/control/host0/boot/one_time", |
| 932 | "org.freedesktop.DBus.Properties", "Get", |
| 933 | "xyz.openbmc_project.Object.Enable", "Enabled"); |
| 934 | } |
| 935 | |
| 936 | /** |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 937 | * @brief Retrieves the Last Reset Time |
| 938 | * |
| 939 | * "Reset" is an overloaded term in Redfish, "Reset" includes power on |
| 940 | * and power off. Even though this is the "system" Redfish object look at the |
| 941 | * chassis D-Bus interface for the LastStateChangeTime since this has the |
| 942 | * last power operation time. |
| 943 | * |
| 944 | * @param[in] aResp Shared pointer for generating response message. |
| 945 | * |
| 946 | * @return None. |
| 947 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 948 | inline void getLastResetTime(std::shared_ptr<AsyncResp> aResp) |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 949 | { |
| 950 | BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; |
| 951 | |
| 952 | crow::connections::systemBus->async_method_call( |
| 953 | [aResp](const boost::system::error_code ec, |
| 954 | std::variant<uint64_t>& lastResetTime) { |
| 955 | if (ec) |
| 956 | { |
| 957 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; |
| 958 | return; |
| 959 | } |
| 960 | |
| 961 | const uint64_t* lastResetTimePtr = |
| 962 | std::get_if<uint64_t>(&lastResetTime); |
| 963 | |
| 964 | if (!lastResetTimePtr) |
| 965 | { |
| 966 | messages::internalError(aResp->res); |
| 967 | return; |
| 968 | } |
| 969 | // LastStateChangeTime is epoch time, in milliseconds |
| 970 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 |
| 971 | time_t lastResetTimeStamp = |
| 972 | static_cast<time_t>(*lastResetTimePtr / 1000); |
| 973 | |
| 974 | // Convert to ISO 8601 standard |
| 975 | aResp->res.jsonValue["LastResetTime"] = |
| 976 | crow::utility::getDateTime(lastResetTimeStamp); |
| 977 | }, |
| 978 | "xyz.openbmc_project.State.Chassis", |
| 979 | "/xyz/openbmc_project/state/chassis0", |
| 980 | "org.freedesktop.DBus.Properties", "Get", |
| 981 | "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); |
| 982 | } |
| 983 | |
| 984 | /** |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 985 | * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. |
| 986 | * |
| 987 | * @param[in] aResp Shared pointer for generating response message. |
| 988 | * |
| 989 | * @return None. |
| 990 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 991 | inline void getAutomaticRetry(std::shared_ptr<AsyncResp> aResp) |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 992 | { |
| 993 | BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; |
| 994 | |
| 995 | crow::connections::systemBus->async_method_call( |
| 996 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 997 | std::variant<bool>& autoRebootEnabled) { |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 998 | if (ec) |
| 999 | { |
| 1000 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; |
| 1001 | return; |
| 1002 | } |
| 1003 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1004 | const bool* autoRebootEnabledPtr = |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1005 | std::get_if<bool>(&autoRebootEnabled); |
| 1006 | |
| 1007 | if (!autoRebootEnabledPtr) |
| 1008 | { |
| 1009 | messages::internalError(aResp->res); |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; |
| 1014 | if (*autoRebootEnabledPtr == true) |
| 1015 | { |
| 1016 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = |
| 1017 | "RetryAttempts"; |
| 1018 | // If AutomaticRetry (AutoReboot) is enabled see how many |
| 1019 | // attempts are left |
| 1020 | crow::connections::systemBus->async_method_call( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1021 | [aResp](const boost::system::error_code ec2, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1022 | std::variant<uint32_t>& autoRebootAttemptsLeft) { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1023 | if (ec2) |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1024 | { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1025 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1026 | return; |
| 1027 | } |
| 1028 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1029 | const uint32_t* autoRebootAttemptsLeftPtr = |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1030 | std::get_if<uint32_t>(&autoRebootAttemptsLeft); |
| 1031 | |
| 1032 | if (!autoRebootAttemptsLeftPtr) |
| 1033 | { |
| 1034 | messages::internalError(aResp->res); |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " |
| 1039 | << *autoRebootAttemptsLeftPtr; |
| 1040 | |
| 1041 | aResp->res |
| 1042 | .jsonValue["Boot"] |
| 1043 | ["RemainingAutomaticRetryAttempts"] = |
| 1044 | *autoRebootAttemptsLeftPtr; |
| 1045 | }, |
| 1046 | "xyz.openbmc_project.State.Host", |
| 1047 | "/xyz/openbmc_project/state/host0", |
| 1048 | "org.freedesktop.DBus.Properties", "Get", |
| 1049 | "xyz.openbmc_project.Control.Boot.RebootAttempts", |
| 1050 | "AttemptsLeft"); |
| 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = |
| 1055 | "Disabled"; |
| 1056 | } |
| 1057 | |
| 1058 | // Not on D-Bus. Hardcoded here: |
| 1059 | // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 |
| 1060 | aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1061 | |
| 1062 | // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, |
| 1063 | // and RetryAttempts. OpenBMC only supports Disabled and |
| 1064 | // RetryAttempts. |
| 1065 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." |
| 1066 | "AllowableValues"] = {"Disabled", |
| 1067 | "RetryAttempts"}; |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1068 | }, |
| 1069 | "xyz.openbmc_project.Settings", |
| 1070 | "/xyz/openbmc_project/control/host0/auto_reboot", |
| 1071 | "org.freedesktop.DBus.Properties", "Get", |
| 1072 | "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); |
| 1073 | } |
| 1074 | |
| 1075 | /** |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1076 | * @brief Retrieves power restore policy over DBUS. |
| 1077 | * |
| 1078 | * @param[in] aResp Shared pointer for generating response message. |
| 1079 | * |
| 1080 | * @return None. |
| 1081 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1082 | inline void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp) |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1083 | { |
| 1084 | BMCWEB_LOG_DEBUG << "Get power restore policy"; |
| 1085 | |
| 1086 | crow::connections::systemBus->async_method_call( |
| 1087 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1088 | std::variant<std::string>& policy) { |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1089 | if (ec) |
| 1090 | { |
| 1091 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | const boost::container::flat_map<std::string, std::string> |
| 1096 | policyMaps = { |
| 1097 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1098 | "AlwaysOn", |
| 1099 | "AlwaysOn"}, |
| 1100 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1101 | "AlwaysOff", |
| 1102 | "AlwaysOff"}, |
| 1103 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1104 | "LastState", |
| 1105 | "LastState"}}; |
| 1106 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1107 | const std::string* policyPtr = std::get_if<std::string>(&policy); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1108 | |
| 1109 | if (!policyPtr) |
| 1110 | { |
| 1111 | messages::internalError(aResp->res); |
| 1112 | return; |
| 1113 | } |
| 1114 | |
| 1115 | auto policyMapsIt = policyMaps.find(*policyPtr); |
| 1116 | if (policyMapsIt == policyMaps.end()) |
| 1117 | { |
| 1118 | messages::internalError(aResp->res); |
| 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; |
| 1123 | }, |
| 1124 | "xyz.openbmc_project.Settings", |
| 1125 | "/xyz/openbmc_project/control/host0/power_restore_policy", |
| 1126 | "org.freedesktop.DBus.Properties", "Get", |
| 1127 | "xyz.openbmc_project.Control.Power.RestorePolicy", |
| 1128 | "PowerRestorePolicy"); |
| 1129 | } |
| 1130 | |
| 1131 | /** |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1132 | * @brief Sets boot properties into DBUS object(s). |
| 1133 | * |
| 1134 | * @param[in] aResp Shared pointer for generating response message. |
| 1135 | * @param[in] oneTimeEnabled Is "one-time" setting already enabled. |
| 1136 | * @param[in] bootSource The boot source to set. |
| 1137 | * @param[in] bootEnable The source override "enable" to set. |
| 1138 | * |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1139 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1140 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1141 | inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1142 | bool oneTimeEnabled, |
| 1143 | std::optional<std::string> bootSource, |
| 1144 | std::optional<std::string> bootEnable) |
| 1145 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1146 | std::string bootSourceStr = |
| 1147 | "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; |
| 1148 | std::string bootModeStr = |
| 1149 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1150 | bool oneTimeSetting = oneTimeEnabled; |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1151 | bool useBootSource = true; |
| 1152 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1153 | // Validate incoming parameters |
| 1154 | if (bootEnable) |
| 1155 | { |
| 1156 | if (*bootEnable == "Once") |
| 1157 | { |
| 1158 | oneTimeSetting = true; |
| 1159 | } |
| 1160 | else if (*bootEnable == "Continuous") |
| 1161 | { |
| 1162 | oneTimeSetting = false; |
| 1163 | } |
| 1164 | else if (*bootEnable == "Disabled") |
| 1165 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1166 | BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1167 | oneTimeSetting = false; |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1168 | useBootSource = false; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1169 | } |
| 1170 | else |
| 1171 | { |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1172 | BMCWEB_LOG_DEBUG << "Unsupported value for " |
| 1173 | "BootSourceOverrideEnabled: " |
| 1174 | << *bootEnable; |
| 1175 | messages::propertyValueNotInList(aResp->res, *bootEnable, |
| 1176 | "BootSourceOverrideEnabled"); |
| 1177 | return; |
| 1178 | } |
| 1179 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1180 | |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1181 | if (bootSource && useBootSource) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1182 | { |
| 1183 | // Source target specified |
| 1184 | BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; |
| 1185 | // Figure out which DBUS interface and property to use |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1186 | if (assignBootParameters(aResp, *bootSource, bootSourceStr, |
| 1187 | bootModeStr)) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1188 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1189 | BMCWEB_LOG_DEBUG |
| 1190 | << "Invalid property value for BootSourceOverrideTarget: " |
| 1191 | << *bootSource; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1192 | messages::propertyValueNotInList(aResp->res, *bootSource, |
| 1193 | "BootSourceTargetOverride"); |
| 1194 | return; |
| 1195 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1196 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1197 | |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1198 | // Act on validated parameters |
| 1199 | BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; |
| 1200 | BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1201 | const char* bootObj = |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1202 | oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" |
| 1203 | : "/xyz/openbmc_project/control/host0/boot"; |
| 1204 | |
| 1205 | crow::connections::systemBus->async_method_call( |
| 1206 | [aResp](const boost::system::error_code ec) { |
| 1207 | if (ec) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1208 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1209 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1210 | messages::internalError(aResp->res); |
| 1211 | return; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1212 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1213 | BMCWEB_LOG_DEBUG << "Boot source update done."; |
| 1214 | }, |
| 1215 | "xyz.openbmc_project.Settings", bootObj, |
| 1216 | "org.freedesktop.DBus.Properties", "Set", |
| 1217 | "xyz.openbmc_project.Control.Boot.Source", "BootSource", |
| 1218 | std::variant<std::string>(bootSourceStr)); |
| 1219 | |
| 1220 | crow::connections::systemBus->async_method_call( |
| 1221 | [aResp](const boost::system::error_code ec) { |
| 1222 | if (ec) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1223 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1224 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1225 | messages::internalError(aResp->res); |
| 1226 | return; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1227 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1228 | BMCWEB_LOG_DEBUG << "Boot mode update done."; |
| 1229 | }, |
| 1230 | "xyz.openbmc_project.Settings", bootObj, |
| 1231 | "org.freedesktop.DBus.Properties", "Set", |
| 1232 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode", |
| 1233 | std::variant<std::string>(bootModeStr)); |
| 1234 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1235 | crow::connections::systemBus->async_method_call( |
| 1236 | [aResp{std::move(aResp)}](const boost::system::error_code ec) { |
| 1237 | if (ec) |
| 1238 | { |
| 1239 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1240 | messages::internalError(aResp->res); |
| 1241 | return; |
| 1242 | } |
| 1243 | BMCWEB_LOG_DEBUG << "Boot enable update done."; |
| 1244 | }, |
| 1245 | "xyz.openbmc_project.Settings", |
| 1246 | "/xyz/openbmc_project/control/host0/boot/one_time", |
| 1247 | "org.freedesktop.DBus.Properties", "Set", |
| 1248 | "xyz.openbmc_project.Object.Enable", "Enabled", |
| 1249 | std::variant<bool>(oneTimeSetting)); |
| 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * @brief Retrieves "One time" enabled setting over DBUS and calls function to |
| 1254 | * set boot source/boot mode properties. |
| 1255 | * |
| 1256 | * @param[in] aResp Shared pointer for generating response message. |
| 1257 | * @param[in] bootSource The boot source from incoming RF request. |
| 1258 | * @param[in] bootEnable The boot override enable from incoming RF request. |
| 1259 | * |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1260 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1261 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1262 | inline void setBootSourceProperties(std::shared_ptr<AsyncResp> aResp, |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1263 | std::optional<std::string> bootSource, |
| 1264 | std::optional<std::string> bootEnable) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1265 | { |
| 1266 | BMCWEB_LOG_DEBUG << "Set boot information."; |
| 1267 | |
| 1268 | crow::connections::systemBus->async_method_call( |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1269 | [aResp, bootSource{std::move(bootSource)}, |
Patrick Williams | 19bd78d | 2020-05-13 17:38:24 -0500 | [diff] [blame] | 1270 | bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1271 | const std::variant<bool>& oneTime) { |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1272 | if (ec) |
| 1273 | { |
| 1274 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1275 | messages::internalError(aResp->res); |
| 1276 | return; |
| 1277 | } |
| 1278 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1279 | const bool* oneTimePtr = std::get_if<bool>(&oneTime); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1280 | |
| 1281 | if (!oneTimePtr) |
| 1282 | { |
| 1283 | messages::internalError(aResp->res); |
| 1284 | return; |
| 1285 | } |
| 1286 | |
| 1287 | BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; |
| 1288 | |
| 1289 | setBootModeOrSource(aResp, *oneTimePtr, std::move(bootSource), |
| 1290 | std::move(bootEnable)); |
| 1291 | }, |
| 1292 | "xyz.openbmc_project.Settings", |
| 1293 | "/xyz/openbmc_project/control/host0/boot/one_time", |
| 1294 | "org.freedesktop.DBus.Properties", "Get", |
| 1295 | "xyz.openbmc_project.Object.Enable", "Enabled"); |
| 1296 | } |
| 1297 | |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1298 | /** |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1299 | * @brief Sets automaticRetry (Auto Reboot) |
| 1300 | * |
| 1301 | * @param[in] aResp Shared pointer for generating response message. |
| 1302 | * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. |
| 1303 | * |
| 1304 | * @return None. |
| 1305 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1306 | inline void setAutomaticRetry(std::shared_ptr<AsyncResp> aResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1307 | const std::string&& automaticRetryConfig) |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1308 | { |
| 1309 | BMCWEB_LOG_DEBUG << "Set Automatic Retry."; |
| 1310 | |
| 1311 | // OpenBMC only supports "Disabled" and "RetryAttempts". |
| 1312 | bool autoRebootEnabled; |
| 1313 | |
| 1314 | if (automaticRetryConfig == "Disabled") |
| 1315 | { |
| 1316 | autoRebootEnabled = false; |
| 1317 | } |
| 1318 | else if (automaticRetryConfig == "RetryAttempts") |
| 1319 | { |
| 1320 | autoRebootEnabled = true; |
| 1321 | } |
| 1322 | else |
| 1323 | { |
| 1324 | BMCWEB_LOG_DEBUG << "Invalid property value for " |
| 1325 | "AutomaticRetryConfig: " |
| 1326 | << automaticRetryConfig; |
| 1327 | messages::propertyValueNotInList(aResp->res, automaticRetryConfig, |
| 1328 | "AutomaticRetryConfig"); |
| 1329 | return; |
| 1330 | } |
| 1331 | |
| 1332 | crow::connections::systemBus->async_method_call( |
| 1333 | [aResp](const boost::system::error_code ec) { |
| 1334 | if (ec) |
| 1335 | { |
| 1336 | messages::internalError(aResp->res); |
| 1337 | return; |
| 1338 | } |
| 1339 | }, |
| 1340 | "xyz.openbmc_project.Settings", |
| 1341 | "/xyz/openbmc_project/control/host0/auto_reboot", |
| 1342 | "org.freedesktop.DBus.Properties", "Set", |
| 1343 | "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", |
| 1344 | std::variant<bool>(autoRebootEnabled)); |
| 1345 | } |
| 1346 | |
| 1347 | /** |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1348 | * @brief Sets power restore policy properties. |
| 1349 | * |
| 1350 | * @param[in] aResp Shared pointer for generating response message. |
| 1351 | * @param[in] policy power restore policy properties from request. |
| 1352 | * |
| 1353 | * @return None. |
| 1354 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1355 | inline void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp, |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1356 | std::optional<std::string> policy) |
| 1357 | { |
| 1358 | BMCWEB_LOG_DEBUG << "Set power restore policy."; |
| 1359 | |
| 1360 | const boost::container::flat_map<std::string, std::string> policyMaps = { |
| 1361 | {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1362 | "AlwaysOn"}, |
| 1363 | {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1364 | "AlwaysOff"}, |
| 1365 | {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." |
| 1366 | "LastState"}}; |
| 1367 | |
| 1368 | std::string powerRestorPolicy; |
| 1369 | |
| 1370 | auto policyMapsIt = policyMaps.find(*policy); |
| 1371 | if (policyMapsIt == policyMaps.end()) |
| 1372 | { |
| 1373 | messages::internalError(aResp->res); |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | powerRestorPolicy = policyMapsIt->second; |
| 1378 | |
| 1379 | crow::connections::systemBus->async_method_call( |
| 1380 | [aResp](const boost::system::error_code ec) { |
| 1381 | if (ec) |
| 1382 | { |
| 1383 | messages::internalError(aResp->res); |
| 1384 | return; |
| 1385 | } |
| 1386 | }, |
| 1387 | "xyz.openbmc_project.Settings", |
| 1388 | "/xyz/openbmc_project/control/host0/power_restore_policy", |
| 1389 | "org.freedesktop.DBus.Properties", "Set", |
| 1390 | "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", |
| 1391 | std::variant<std::string>(powerRestorPolicy)); |
| 1392 | } |
| 1393 | |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1394 | #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE |
| 1395 | /** |
| 1396 | * @brief Retrieves provisioning status |
| 1397 | * |
| 1398 | * @param[in] aResp Shared pointer for completing asynchronous calls. |
| 1399 | * |
| 1400 | * @return None. |
| 1401 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1402 | inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1403 | { |
| 1404 | BMCWEB_LOG_DEBUG << "Get OEM information."; |
| 1405 | crow::connections::systemBus->async_method_call( |
| 1406 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1407 | const std::vector<std::pair<std::string, VariantType>>& |
| 1408 | propertiesList) { |
AppaRao Puli | b99fb1a | 2020-07-08 16:42:48 +0530 | [diff] [blame] | 1409 | nlohmann::json& oemPFR = |
| 1410 | aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; |
James Feist | 50626f4 | 2020-09-23 14:40:47 -0700 | [diff] [blame] | 1411 | aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = |
| 1412 | "#OemComputerSystem.OpenBmc"; |
| 1413 | oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; |
| 1414 | |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1415 | if (ec) |
| 1416 | { |
| 1417 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
AppaRao Puli | b99fb1a | 2020-07-08 16:42:48 +0530 | [diff] [blame] | 1418 | // not an error, don't have to have the interface |
| 1419 | oemPFR["ProvisioningStatus"] = "NotProvisioned"; |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1420 | return; |
| 1421 | } |
| 1422 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1423 | const bool* provState = nullptr; |
| 1424 | const bool* lockState = nullptr; |
| 1425 | for (const std::pair<std::string, VariantType>& property : |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1426 | propertiesList) |
| 1427 | { |
| 1428 | if (property.first == "UfmProvisioned") |
| 1429 | { |
| 1430 | provState = std::get_if<bool>(&property.second); |
| 1431 | } |
| 1432 | else if (property.first == "UfmLocked") |
| 1433 | { |
| 1434 | lockState = std::get_if<bool>(&property.second); |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | if ((provState == nullptr) || (lockState == nullptr)) |
| 1439 | { |
| 1440 | BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; |
| 1441 | messages::internalError(aResp->res); |
| 1442 | return; |
| 1443 | } |
| 1444 | |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1445 | if (*provState == true) |
| 1446 | { |
| 1447 | if (*lockState == true) |
| 1448 | { |
| 1449 | oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; |
| 1450 | } |
| 1451 | else |
| 1452 | { |
| 1453 | oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; |
| 1454 | } |
| 1455 | } |
| 1456 | else |
| 1457 | { |
| 1458 | oemPFR["ProvisioningStatus"] = "NotProvisioned"; |
| 1459 | } |
| 1460 | }, |
| 1461 | "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", |
| 1462 | "org.freedesktop.DBus.Properties", "GetAll", |
| 1463 | "xyz.openbmc_project.PFR.Attributes"); |
| 1464 | } |
| 1465 | #endif |
| 1466 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1467 | /** |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1468 | * @brief Translates watchdog timeout action DBUS property value to redfish. |
| 1469 | * |
| 1470 | * @param[in] dbusAction The watchdog timeout action in D-BUS. |
| 1471 | * |
| 1472 | * @return Returns as a string, the timeout action in Redfish terms. If |
| 1473 | * translation cannot be done, returns an empty string. |
| 1474 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1475 | inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1476 | { |
| 1477 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") |
| 1478 | { |
| 1479 | return "None"; |
| 1480 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1481 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1482 | { |
| 1483 | return "ResetSystem"; |
| 1484 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1485 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1486 | { |
| 1487 | return "PowerDown"; |
| 1488 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1489 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1490 | { |
| 1491 | return "PowerCycle"; |
| 1492 | } |
| 1493 | |
| 1494 | return ""; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1498 | *@brief Translates timeout action from Redfish to DBUS property value. |
| 1499 | * |
| 1500 | *@param[in] rfAction The timeout action in Redfish. |
| 1501 | * |
| 1502 | *@return Returns as a string, the time_out action as expected by DBUS. |
| 1503 | *If translation cannot be done, returns an empty string. |
| 1504 | */ |
| 1505 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1506 | inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1507 | { |
| 1508 | if (rfAction == "None") |
| 1509 | { |
| 1510 | return "xyz.openbmc_project.State.Watchdog.Action.None"; |
| 1511 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1512 | if (rfAction == "PowerCycle") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1513 | { |
| 1514 | return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; |
| 1515 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1516 | if (rfAction == "PowerDown") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1517 | { |
| 1518 | return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; |
| 1519 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1520 | if (rfAction == "ResetSystem") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1521 | { |
| 1522 | return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; |
| 1523 | } |
| 1524 | |
| 1525 | return ""; |
| 1526 | } |
| 1527 | |
| 1528 | /** |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1529 | * @brief Retrieves host watchdog timer properties over DBUS |
| 1530 | * |
| 1531 | * @param[in] aResp Shared pointer for completing asynchronous calls. |
| 1532 | * |
| 1533 | * @return None. |
| 1534 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1535 | inline void getHostWatchdogTimer(std::shared_ptr<AsyncResp> aResp) |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1536 | { |
| 1537 | BMCWEB_LOG_DEBUG << "Get host watchodg"; |
| 1538 | crow::connections::systemBus->async_method_call( |
| 1539 | [aResp](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1540 | PropertiesType& properties) { |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1541 | if (ec) |
| 1542 | { |
| 1543 | // watchdog service is stopped |
| 1544 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1545 | return; |
| 1546 | } |
| 1547 | |
| 1548 | BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; |
| 1549 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1550 | nlohmann::json& hostWatchdogTimer = |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1551 | aResp->res.jsonValue["HostWatchdogTimer"]; |
| 1552 | |
| 1553 | // watchdog service is running/enabled |
| 1554 | hostWatchdogTimer["Status"]["State"] = "Enabled"; |
| 1555 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1556 | for (const auto& property : properties) |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1557 | { |
| 1558 | BMCWEB_LOG_DEBUG << "prop=" << property.first; |
| 1559 | if (property.first == "Enabled") |
| 1560 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1561 | const bool* state = std::get_if<bool>(&property.second); |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1562 | |
| 1563 | if (!state) |
| 1564 | { |
| 1565 | messages::internalError(aResp->res); |
| 1566 | continue; |
| 1567 | } |
| 1568 | |
| 1569 | hostWatchdogTimer["FunctionEnabled"] = *state; |
| 1570 | } |
| 1571 | else if (property.first == "ExpireAction") |
| 1572 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1573 | const std::string* s = |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1574 | std::get_if<std::string>(&property.second); |
| 1575 | if (!s) |
| 1576 | { |
| 1577 | messages::internalError(aResp->res); |
| 1578 | continue; |
| 1579 | } |
| 1580 | |
| 1581 | std::string action = dbusToRfWatchdogAction(*s); |
| 1582 | if (action.empty()) |
| 1583 | { |
| 1584 | messages::internalError(aResp->res); |
| 1585 | continue; |
| 1586 | } |
| 1587 | hostWatchdogTimer["TimeoutAction"] = action; |
| 1588 | } |
| 1589 | } |
| 1590 | }, |
| 1591 | "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", |
| 1592 | "org.freedesktop.DBus.Properties", "GetAll", |
| 1593 | "xyz.openbmc_project.State.Watchdog"); |
| 1594 | } |
| 1595 | |
| 1596 | /** |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1597 | * @brief Sets Host WatchDog Timer properties. |
| 1598 | * |
| 1599 | * @param[in] aResp Shared pointer for generating response message. |
| 1600 | * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming |
| 1601 | * RF request. |
| 1602 | * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. |
| 1603 | * |
| 1604 | * @return None. |
| 1605 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1606 | inline void setWDTProperties(std::shared_ptr<AsyncResp> aResp, |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1607 | const std::optional<bool> wdtEnable, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1608 | const std::optional<std::string>& wdtTimeOutAction) |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1609 | { |
| 1610 | BMCWEB_LOG_DEBUG << "Set host watchdog"; |
| 1611 | |
| 1612 | if (wdtTimeOutAction) |
| 1613 | { |
| 1614 | std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); |
| 1615 | // check if TimeOut Action is Valid |
| 1616 | if (wdtTimeOutActStr.empty()) |
| 1617 | { |
| 1618 | BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " |
| 1619 | << *wdtTimeOutAction; |
| 1620 | messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, |
| 1621 | "TimeoutAction"); |
| 1622 | return; |
| 1623 | } |
| 1624 | |
| 1625 | crow::connections::systemBus->async_method_call( |
| 1626 | [aResp](const boost::system::error_code ec) { |
| 1627 | if (ec) |
| 1628 | { |
| 1629 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1630 | messages::internalError(aResp->res); |
| 1631 | return; |
| 1632 | } |
| 1633 | }, |
| 1634 | "xyz.openbmc_project.Watchdog", |
| 1635 | "/xyz/openbmc_project/watchdog/host0", |
| 1636 | "org.freedesktop.DBus.Properties", "Set", |
| 1637 | "xyz.openbmc_project.State.Watchdog", "ExpireAction", |
| 1638 | std::variant<std::string>(wdtTimeOutActStr)); |
| 1639 | } |
| 1640 | |
| 1641 | if (wdtEnable) |
| 1642 | { |
| 1643 | crow::connections::systemBus->async_method_call( |
| 1644 | [aResp](const boost::system::error_code ec) { |
| 1645 | if (ec) |
| 1646 | { |
| 1647 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 1648 | messages::internalError(aResp->res); |
| 1649 | return; |
| 1650 | } |
| 1651 | }, |
| 1652 | "xyz.openbmc_project.Watchdog", |
| 1653 | "/xyz/openbmc_project/watchdog/host0", |
| 1654 | "org.freedesktop.DBus.Properties", "Set", |
| 1655 | "xyz.openbmc_project.State.Watchdog", "Enabled", |
| 1656 | std::variant<bool>(*wdtEnable)); |
| 1657 | } |
| 1658 | } |
| 1659 | |
| 1660 | /** |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1661 | * SystemsCollection derived class for delivering ComputerSystems Collection |
| 1662 | * Schema |
| 1663 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1664 | class SystemsCollection : public Node |
| 1665 | { |
| 1666 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1667 | SystemsCollection(App& app) : Node(app, "/redfish/v1/Systems/") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1668 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1669 | entityPrivileges = { |
| 1670 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1671 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1672 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1673 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1674 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1675 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1676 | } |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1677 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1678 | private: |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1679 | void doGet(crow::Response& res, const crow::Request&, |
| 1680 | const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1681 | { |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1682 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1683 | res.jsonValue["@odata.type"] = |
| 1684 | "#ComputerSystemCollection.ComputerSystemCollection"; |
| 1685 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1686 | res.jsonValue["Name"] = "Computer System Collection"; |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1687 | |
| 1688 | crow::connections::systemBus->async_method_call( |
| 1689 | [asyncResp](const boost::system::error_code ec, |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1690 | const std::variant<std::string>& /*hostName*/) { |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1691 | nlohmann::json& ifaceArray = |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1692 | asyncResp->res.jsonValue["Members"]; |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1693 | ifaceArray = nlohmann::json::array(); |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1694 | auto& count = asyncResp->res.jsonValue["Members@odata.count"]; |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1695 | count = 0; |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1696 | ifaceArray.push_back( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1697 | {{"@odata.id", "/redfish/v1/Systems/system"}}); |
| 1698 | if (!ec) |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1699 | { |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1700 | BMCWEB_LOG_DEBUG << "Hypervisor is available"; |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1701 | ifaceArray.push_back( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1702 | {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); |
Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1703 | count = ifaceArray.size(); |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1704 | return; |
| 1705 | } |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1706 | }, |
Sunitha Harish | 8e651fb | 2020-06-17 06:06:25 -0500 | [diff] [blame] | 1707 | "xyz.openbmc_project.Settings", |
| 1708 | "/xyz/openbmc_project/network/hypervisor", |
Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1709 | "org.freedesktop.DBus.Properties", "Get", |
| 1710 | "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1711 | } |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1712 | }; |
| 1713 | |
| 1714 | /** |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1715 | * SystemActionsReset class supports handle POST method for Reset action. |
| 1716 | * The class retrieves and sends data directly to D-Bus. |
| 1717 | */ |
| 1718 | class SystemActionsReset : public Node |
| 1719 | { |
| 1720 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1721 | SystemActionsReset(App& app) : |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1722 | Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1723 | { |
| 1724 | entityPrivileges = { |
| 1725 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 1726 | } |
| 1727 | |
| 1728 | private: |
| 1729 | /** |
| 1730 | * Function handles POST method request. |
| 1731 | * Analyzes POST body message before sends Reset request data to D-Bus. |
| 1732 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1733 | void doPost(crow::Response& res, const crow::Request& req, |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1734 | const std::vector<std::string>&) override |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1735 | { |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1736 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1737 | |
| 1738 | std::string resetType; |
| 1739 | if (!json_util::readJson(req, res, "ResetType", resetType)) |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1740 | { |
| 1741 | return; |
| 1742 | } |
| 1743 | |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1744 | // Get the command and host vs. chassis |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1745 | std::string command; |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1746 | bool hostCommand; |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 1747 | if ((resetType == "On") || (resetType == "ForceOn")) |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1748 | { |
| 1749 | command = "xyz.openbmc_project.State.Host.Transition.On"; |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1750 | hostCommand = true; |
| 1751 | } |
| 1752 | else if (resetType == "ForceOff") |
| 1753 | { |
| 1754 | command = "xyz.openbmc_project.State.Chassis.Transition.Off"; |
| 1755 | hostCommand = false; |
| 1756 | } |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1757 | else if (resetType == "ForceRestart") |
| 1758 | { |
Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1759 | command = |
| 1760 | "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; |
| 1761 | hostCommand = true; |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1762 | } |
| 1763 | else if (resetType == "GracefulShutdown") |
| 1764 | { |
| 1765 | command = "xyz.openbmc_project.State.Host.Transition.Off"; |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1766 | hostCommand = true; |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1767 | } |
| 1768 | else if (resetType == "GracefulRestart") |
| 1769 | { |
Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1770 | command = |
| 1771 | "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1772 | hostCommand = true; |
| 1773 | } |
| 1774 | else if (resetType == "PowerCycle") |
| 1775 | { |
Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1776 | command = "xyz.openbmc_project.State.Host.Transition.Reboot"; |
| 1777 | hostCommand = true; |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1778 | } |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1779 | else if (resetType == "Nmi") |
| 1780 | { |
| 1781 | doNMI(asyncResp); |
| 1782 | return; |
| 1783 | } |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1784 | else |
| 1785 | { |
Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1786 | messages::actionParameterUnknown(res, "Reset", resetType); |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1787 | return; |
| 1788 | } |
| 1789 | |
Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1790 | if (hostCommand) |
| 1791 | { |
| 1792 | crow::connections::systemBus->async_method_call( |
| 1793 | [asyncResp, resetType](const boost::system::error_code ec) { |
| 1794 | if (ec) |
| 1795 | { |
| 1796 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; |
| 1797 | if (ec.value() == boost::asio::error::invalid_argument) |
| 1798 | { |
| 1799 | messages::actionParameterNotSupported( |
| 1800 | asyncResp->res, resetType, "Reset"); |
| 1801 | } |
| 1802 | else |
| 1803 | { |
| 1804 | messages::internalError(asyncResp->res); |
| 1805 | } |
| 1806 | return; |
| 1807 | } |
| 1808 | messages::success(asyncResp->res); |
| 1809 | }, |
| 1810 | "xyz.openbmc_project.State.Host", |
| 1811 | "/xyz/openbmc_project/state/host0", |
| 1812 | "org.freedesktop.DBus.Properties", "Set", |
| 1813 | "xyz.openbmc_project.State.Host", "RequestedHostTransition", |
| 1814 | std::variant<std::string>{command}); |
| 1815 | } |
| 1816 | else |
| 1817 | { |
| 1818 | crow::connections::systemBus->async_method_call( |
| 1819 | [asyncResp, resetType](const boost::system::error_code ec) { |
| 1820 | if (ec) |
| 1821 | { |
| 1822 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; |
| 1823 | if (ec.value() == boost::asio::error::invalid_argument) |
| 1824 | { |
| 1825 | messages::actionParameterNotSupported( |
| 1826 | asyncResp->res, resetType, "Reset"); |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | messages::internalError(asyncResp->res); |
| 1831 | } |
| 1832 | return; |
| 1833 | } |
| 1834 | messages::success(asyncResp->res); |
| 1835 | }, |
| 1836 | "xyz.openbmc_project.State.Chassis", |
| 1837 | "/xyz/openbmc_project/state/chassis0", |
| 1838 | "org.freedesktop.DBus.Properties", "Set", |
| 1839 | "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", |
| 1840 | std::variant<std::string>{command}); |
| 1841 | } |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1842 | } |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1843 | /** |
| 1844 | * Function transceives data with dbus directly. |
| 1845 | */ |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1846 | void doNMI(const std::shared_ptr<AsyncResp>& asyncResp) |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1847 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1848 | constexpr char const* serviceName = |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1849 | "xyz.openbmc_project.Control.Host.NMI"; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1850 | constexpr char const* objectPath = |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1851 | "/xyz/openbmc_project/control/host0/nmi"; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1852 | constexpr char const* interfaceName = |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1853 | "xyz.openbmc_project.Control.Host.NMI"; |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1854 | constexpr char const* method = "NMI"; |
Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1855 | |
| 1856 | crow::connections::systemBus->async_method_call( |
| 1857 | [asyncResp](const boost::system::error_code ec) { |
| 1858 | if (ec) |
| 1859 | { |
| 1860 | BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; |
| 1861 | messages::internalError(asyncResp->res); |
| 1862 | return; |
| 1863 | } |
| 1864 | messages::success(asyncResp->res); |
| 1865 | }, |
| 1866 | serviceName, objectPath, interfaceName, method); |
| 1867 | } |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1868 | }; |
| 1869 | |
| 1870 | /** |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 1871 | * Systems derived class for delivering Computer Systems Schema. |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1872 | */ |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1873 | class Systems : public Node |
| 1874 | { |
| 1875 | public: |
| 1876 | /* |
| 1877 | * Default Constructor |
| 1878 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1879 | Systems(App& app) : Node(app, "/redfish/v1/Systems/system/") |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1880 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1881 | entityPrivileges = { |
| 1882 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 1883 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 1884 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 1885 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 1886 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 1887 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1890 | private: |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1891 | /** |
| 1892 | * Functions triggers appropriate requests on DBus |
| 1893 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1894 | void doGet(crow::Response& res, const crow::Request&, |
| 1895 | const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1896 | { |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1897 | res.jsonValue["@odata.type"] = "#ComputerSystem.v1_12_0.ComputerSystem"; |
Gunnar Mills | 450a25c | 2020-04-14 21:34:07 -0500 | [diff] [blame] | 1898 | res.jsonValue["Name"] = "system"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1899 | res.jsonValue["Id"] = "system"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1900 | res.jsonValue["SystemType"] = "Physical"; |
| 1901 | res.jsonValue["Description"] = "Computer System"; |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1902 | res.jsonValue["ProcessorSummary"]["Count"] = 0; |
| 1903 | res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 1904 | res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); |
Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1905 | res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1906 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; |
Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 1907 | |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1908 | res.jsonValue["Processors"] = { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1909 | {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; |
Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 1910 | res.jsonValue["Memory"] = { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1911 | {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; |
Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 1912 | res.jsonValue["Storage"] = { |
| 1913 | {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1914 | |
Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1915 | res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { |
| 1916 | {"target", |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1917 | "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 1918 | {"@Redfish.ActionInfo", |
| 1919 | "/redfish/v1/Systems/system/ResetActionInfo"}}; |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1920 | |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1921 | res.jsonValue["LogServices"] = { |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1922 | {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 1923 | |
Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 1924 | res.jsonValue["Bios"] = { |
| 1925 | {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; |
| 1926 | |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1927 | res.jsonValue["Links"]["ManagedBy"] = { |
| 1928 | {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; |
| 1929 | |
| 1930 | res.jsonValue["Status"] = { |
| 1931 | {"Health", "OK"}, |
| 1932 | {"State", "Enabled"}, |
| 1933 | }; |
Ed Tanous | a0803ef | 2018-08-29 13:29:23 -0700 | [diff] [blame] | 1934 | auto asyncResp = std::make_shared<AsyncResp>(res); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1935 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1936 | constexpr const std::array<const char*, 4> inventoryForSystems = { |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 1937 | "xyz.openbmc_project.Inventory.Item.Dimm", |
James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 1938 | "xyz.openbmc_project.Inventory.Item.Cpu", |
James Feist | e284a7c | 2019-11-20 16:20:23 -0800 | [diff] [blame] | 1939 | "xyz.openbmc_project.Inventory.Item.Drive", |
| 1940 | "xyz.openbmc_project.Inventory.Item.StorageController"}; |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 1941 | |
| 1942 | auto health = std::make_shared<HealthPopulate>(asyncResp); |
| 1943 | crow::connections::systemBus->async_method_call( |
| 1944 | [health](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1945 | std::vector<std::string>& resp) { |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 1946 | if (ec) |
| 1947 | { |
| 1948 | // no inventory |
| 1949 | return; |
| 1950 | } |
| 1951 | |
| 1952 | health->inventory = std::move(resp); |
| 1953 | }, |
| 1954 | "xyz.openbmc_project.ObjectMapper", |
| 1955 | "/xyz/openbmc_project/object_mapper", |
| 1956 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", |
| 1957 | int32_t(0), inventoryForSystems); |
| 1958 | |
| 1959 | health->populate(); |
| 1960 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1961 | getMainChassisId(asyncResp, [](const std::string& chassisId, |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1962 | std::shared_ptr<AsyncResp> aRsp) { |
| 1963 | aRsp->res.jsonValue["Links"]["Chassis"] = { |
| 1964 | {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; |
| 1965 | }); |
AppaRao Puli | a300222 | 2019-11-12 21:32:59 +0530 | [diff] [blame] | 1966 | |
| 1967 | getIndicatorLedState(asyncResp); |
James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 1968 | getComputerSystem(asyncResp, health); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 1969 | getHostState(asyncResp); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1970 | getBootProperties(asyncResp); |
Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 1971 | getPCIeDeviceList(asyncResp, "PCIeDevices"); |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1972 | getHostWatchdogTimer(asyncResp); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1973 | getPowerRestorePolicy(asyncResp); |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1974 | getAutomaticRetry(asyncResp); |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1975 | getLastResetTime(asyncResp); |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1976 | #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE |
| 1977 | getProvisioningStatus(asyncResp); |
| 1978 | #endif |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1981 | void doPatch(crow::Response& res, const crow::Request& req, |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1982 | const std::vector<std::string>&) override |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1983 | { |
Santosh Puranik | cde19e5 | 2019-02-20 00:10:56 +0530 | [diff] [blame] | 1984 | std::optional<std::string> indicatorLed; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1985 | std::optional<nlohmann::json> bootProps; |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1986 | std::optional<nlohmann::json> wdtTimerProps; |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1987 | std::optional<std::string> powerRestorePolicy; |
Santosh Puranik | 41352c2 | 2019-07-03 05:35:49 -0500 | [diff] [blame] | 1988 | auto asyncResp = std::make_shared<AsyncResp>(res); |
| 1989 | |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1990 | if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot", |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1991 | bootProps, "WatchdogTimer", wdtTimerProps, |
| 1992 | "PowerRestorePolicy", powerRestorePolicy)) |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 1993 | { |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1994 | return; |
| 1995 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1996 | |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1997 | res.result(boost::beast::http::status::no_content); |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1998 | |
| 1999 | if (wdtTimerProps) |
| 2000 | { |
| 2001 | std::optional<bool> wdtEnable; |
| 2002 | std::optional<std::string> wdtTimeOutAction; |
| 2003 | |
| 2004 | if (!json_util::readJson(*wdtTimerProps, asyncResp->res, |
| 2005 | "FunctionEnabled", wdtEnable, |
| 2006 | "TimeoutAction", wdtTimeOutAction)) |
| 2007 | { |
| 2008 | return; |
| 2009 | } |
| 2010 | setWDTProperties(asyncResp, std::move(wdtEnable), |
| 2011 | std::move(wdtTimeOutAction)); |
| 2012 | } |
| 2013 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2014 | if (bootProps) |
| 2015 | { |
| 2016 | std::optional<std::string> bootSource; |
| 2017 | std::optional<std::string> bootEnable; |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2018 | std::optional<std::string> automaticRetryConfig; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2019 | |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2020 | if (!json_util::readJson( |
| 2021 | *bootProps, asyncResp->res, "BootSourceOverrideTarget", |
| 2022 | bootSource, "BootSourceOverrideEnabled", bootEnable, |
| 2023 | "AutomaticRetryConfig", automaticRetryConfig)) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2024 | { |
| 2025 | return; |
| 2026 | } |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2027 | if (bootSource || bootEnable) |
| 2028 | { |
| 2029 | setBootSourceProperties(asyncResp, std::move(bootSource), |
| 2030 | std::move(bootEnable)); |
| 2031 | } |
| 2032 | if (automaticRetryConfig) |
| 2033 | { |
| 2034 | setAutomaticRetry(asyncResp, std::move(*automaticRetryConfig)); |
| 2035 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2036 | } |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 2037 | |
Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 2038 | if (indicatorLed) |
| 2039 | { |
AppaRao Puli | a300222 | 2019-11-12 21:32:59 +0530 | [diff] [blame] | 2040 | setIndicatorLedState(asyncResp, std::move(*indicatorLed)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2041 | } |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2042 | |
| 2043 | if (powerRestorePolicy) |
| 2044 | { |
| 2045 | setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); |
| 2046 | } |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2047 | } |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2048 | }; |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2049 | |
| 2050 | /** |
| 2051 | * SystemResetActionInfo derived class for delivering Computer Systems |
| 2052 | * ResetType AllowableValues using ResetInfo schema. |
| 2053 | */ |
| 2054 | class SystemResetActionInfo : public Node |
| 2055 | { |
| 2056 | public: |
| 2057 | /* |
| 2058 | * Default Constructor |
| 2059 | */ |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 2060 | SystemResetActionInfo(App& app) : |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2061 | Node(app, "/redfish/v1/Systems/system/ResetActionInfo/") |
| 2062 | { |
| 2063 | entityPrivileges = { |
| 2064 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 2065 | {boost::beast::http::verb::head, {{"Login"}}}, |
| 2066 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, |
| 2067 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, |
| 2068 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, |
| 2069 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; |
| 2070 | } |
| 2071 | |
| 2072 | private: |
| 2073 | /** |
| 2074 | * Functions triggers appropriate requests on DBus |
| 2075 | */ |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 2076 | void doGet(crow::Response& res, const crow::Request&, |
| 2077 | const std::vector<std::string>&) override |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2078 | { |
| 2079 | res.jsonValue = { |
| 2080 | {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, |
| 2081 | {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, |
| 2082 | {"Name", "Reset Action Info"}, |
| 2083 | {"Id", "ResetActionInfo"}, |
| 2084 | {"Parameters", |
| 2085 | {{{"Name", "ResetType"}, |
| 2086 | {"Required", true}, |
| 2087 | {"DataType", "String"}, |
| 2088 | {"AllowableValues", |
| 2089 | {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", |
| 2090 | "GracefulShutdown", "PowerCycle", "Nmi"}}}}}}; |
| 2091 | res.end(); |
| 2092 | } |
| 2093 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2094 | } // namespace redfish |