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