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