blob: 91da523fdb415695a251e4e4f5e6ce2fc8d50dea [file] [log] [blame]
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02001/*
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 Feistb49ac872019-05-21 15:12:01 -070018#include "health.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080019#include "led.hpp"
Jason M. Billsf5c9f8b2018-12-18 16:51:18 -080020#include "pcie.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080021#include "redfish_util.hpp"
22
Ed Tanous9712f8a2018-09-21 13:38:49 -070023#include <boost/container/flat_map.hpp>
24#include <node.hpp>
Andrew Geisslercb7e1e72019-02-19 13:05:38 -060025#include <utils/fw_utils.hpp>
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +020026#include <utils/json_utils.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050027
Ed Tanousabf2add2019-01-22 16:40:12 -080028#include <variant>
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +020029
Ed Tanous1abe55e2018-09-05 08:30:59 -070030namespace redfish
31{
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +020032
Alpana Kumari9d3ae102019-04-12 06:49:32 -050033/**
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 Tanousb5a76932020-09-29 16:16:58 -070041inline void updateDimmProperties(const std::shared_ptr<AsyncResp>& aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +000042 const std::variant<bool>& dimmState)
Alpana Kumari9d3ae102019-04-12 06:49:32 -050043{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050044 const bool* isDimmFunctional = std::get_if<bool>(&dimmState);
Alpana Kumari9d3ae102019-04-12 06:49:32 -050045 if (isDimmFunctional == nullptr)
46 {
47 messages::internalError(aResp->res);
48 return;
49 }
Gunnar Mills698654b2019-10-16 13:17:37 -050050 BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional;
Alpana Kumari9d3ae102019-04-12 06:49:32 -050051
Gunnar Mills4e0453b2020-07-08 14:00:30 -050052 // Set it as Enabled if at least one DIMM is functional
Alpana Kumari9d3ae102019-04-12 06:49:32 -050053 // Update STATE only if previous State was DISABLED and current Dimm is
54 // ENABLED.
Gunnar Mills1214b7e2020-06-04 10:11:30 -050055 nlohmann::json& prevMemSummary =
Alpana Kumari9d3ae102019-04-12 06:49:32 -050056 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 Kumari57e8c9b2019-04-15 01:09:36 -050067/*
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 Tanousb5a76932020-09-29 16:16:58 -070075inline void modifyCpuPresenceState(const std::shared_ptr<AsyncResp>& aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +000076 const std::variant<bool>& cpuPresenceState)
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050077{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050078 const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState);
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050079
80 if (isCpuPresent == nullptr)
81 {
82 messages::internalError(aResp->res);
83 return;
84 }
Gunnar Mills698654b2019-10-16 13:17:37 -050085 BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent;
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050086
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050087 if (*isCpuPresent == true)
88 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -050089 nlohmann::json& procCount =
James Feistb4b95952019-12-05 15:01:55 -080090 aResp->res.jsonValue["ProcessorSummary"]["Count"];
91 auto procCountPtr =
Gunnar Mills1214b7e2020-06-04 10:11:30 -050092 procCount.get_ptr<nlohmann::json::number_integer_t*>();
James Feistb4b95952019-12-05 15:01:55 -080093 if (procCountPtr != nullptr)
94 {
95 // shouldn't be possible to be nullptr
96 *procCountPtr += 1;
97 }
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050098 }
Alpana Kumari57e8c9b2019-04-15 01:09:36 -050099}
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 Tanous23a21a12020-07-25 04:45:05 +0000110inline void
Ed Tanousb5a76932020-09-29 16:16:58 -0700111 modifyCpuFunctionalState(const std::shared_ptr<AsyncResp>& aResp,
Ed Tanous23a21a12020-07-25 04:45:05 +0000112 const std::variant<bool>& cpuFunctionalState)
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500113{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500114 const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState);
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500115
116 if (isCpuFunctional == nullptr)
117 {
118 messages::internalError(aResp->res);
119 return;
120 }
Gunnar Mills698654b2019-10-16 13:17:37 -0500121 BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional;
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500122
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500123 nlohmann::json& prevProcState =
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500124 aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
125
Gunnar Mills4e0453b2020-07-08 14:00:30 -0500126 // Set it as Enabled if at least one CPU is functional
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500127 // 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 Tanous6c34de42018-08-29 13:37:36 -0700140 * @brief Retrieves computer system properties over dbus
141 *
142 * @param[in] aResp Shared pointer for completing asynchronous calls
Gunnar Mills8f9ee3c2020-10-30 16:15:13 -0500143 * @param[in] systemHealth Shared HealthPopulate pointer
Ed Tanous6c34de42018-08-29 13:37:36 -0700144 *
145 * @return None.
146 */
Ed Tanousb5a76932020-09-29 16:16:58 -0700147inline void
148 getComputerSystem(const std::shared_ptr<AsyncResp>& aResp,
149 const std::shared_ptr<HealthPopulate>& systemHealth)
Ed Tanous6c34de42018-08-29 13:37:36 -0700150{
Ed Tanous6c34de42018-08-29 13:37:36 -0700151 BMCWEB_LOG_DEBUG << "Get available system components.";
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500152
Ed Tanous6c34de42018-08-29 13:37:36 -0700153 crow::connections::systemBus->async_method_call(
James Feist5bc2dc82019-10-22 14:33:16 -0700154 [aResp, systemHealth](
Ed Tanous6c34de42018-08-29 13:37:36 -0700155 const boost::system::error_code ec,
156 const std::vector<std::pair<
157 std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500158 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
159 subtree) {
Ed Tanous6c34de42018-08-29 13:37:36 -0700160 if (ec)
161 {
162 BMCWEB_LOG_DEBUG << "DBUS response error";
Jason M. Billsf12894f2018-10-09 12:45:45 -0700163 messages::internalError(aResp->res);
Ed Tanous6c34de42018-08-29 13:37:36 -0700164 return;
165 }
Ed Tanous6c34de42018-08-29 13:37:36 -0700166 // Iterate over all retrieved ObjectPaths.
167 for (const std::pair<std::string,
168 std::vector<std::pair<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500169 std::string, std::vector<std::string>>>>&
170 object : subtree)
Ed Tanous6c34de42018-08-29 13:37:36 -0700171 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500172 const std::string& path = object.first;
Ed Tanous6c34de42018-08-29 13:37:36 -0700173 BMCWEB_LOG_DEBUG << "Got path: " << path;
174 const std::vector<
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500175 std::pair<std::string, std::vector<std::string>>>&
176 connectionNames = object.second;
Ed Tanous6c34de42018-08-29 13:37:36 -0700177 if (connectionNames.size() < 1)
178 {
179 continue;
180 }
Ed Tanous029573d2019-02-01 10:57:49 -0800181
James Feist5bc2dc82019-10-22 14:33:16 -0700182 auto memoryHealth = std::make_shared<HealthPopulate>(
183 aResp, aResp->res.jsonValue["MemorySummary"]["Status"]);
184
185 auto cpuHealth = std::make_shared<HealthPopulate>(
186 aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]);
187
188 systemHealth->children.emplace_back(memoryHealth);
189 systemHealth->children.emplace_back(cpuHealth);
190
Ed Tanous029573d2019-02-01 10:57:49 -0800191 // This is not system, so check if it's cpu, dimm, UUID or
192 // BiosVer
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500193 for (const auto& connection : connectionNames)
Ed Tanous6c34de42018-08-29 13:37:36 -0700194 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500195 for (const auto& interfaceName : connection.second)
Ed Tanous6c34de42018-08-29 13:37:36 -0700196 {
Ed Tanous029573d2019-02-01 10:57:49 -0800197 if (interfaceName ==
198 "xyz.openbmc_project.Inventory.Item.Dimm")
Ed Tanous6c34de42018-08-29 13:37:36 -0700199 {
Ed Tanous029573d2019-02-01 10:57:49 -0800200 BMCWEB_LOG_DEBUG
201 << "Found Dimm, now get its properties.";
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500202
Ed Tanous029573d2019-02-01 10:57:49 -0800203 crow::connections::systemBus->async_method_call(
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500204 [aResp, service{connection.first},
Ed Tanousf23b7292020-10-15 09:41:17 -0700205 path](const boost::system::error_code ec2,
206 const std::vector<
207 std::pair<std::string, VariantType>>&
208 properties) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000209 if (ec2)
Ed Tanous029573d2019-02-01 10:57:49 -0800210 {
211 BMCWEB_LOG_ERROR
Ed Tanouscb13a392020-07-25 19:02:03 +0000212 << "DBUS response error " << ec2;
Ed Tanous029573d2019-02-01 10:57:49 -0800213 messages::internalError(aResp->res);
214 return;
215 }
216 BMCWEB_LOG_DEBUG << "Got "
217 << properties.size()
Gunnar Mills698654b2019-10-16 13:17:37 -0500218 << " Dimm properties.";
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500219
220 if (properties.size() > 0)
Ed Tanous029573d2019-02-01 10:57:49 -0800221 {
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500222 for (const std::pair<std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500223 VariantType>&
224 property : properties)
Ed Tanous6c34de42018-08-29 13:37:36 -0700225 {
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800226 if (property.first !=
227 "MemorySizeInKB")
Ed Tanous6c34de42018-08-29 13:37:36 -0700228 {
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800229 continue;
Ed Tanous6c34de42018-08-29 13:37:36 -0700230 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500231 const uint32_t* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500232 std::get_if<uint32_t>(
233 &property.second);
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800234 if (value == nullptr)
235 {
236 BMCWEB_LOG_DEBUG
237 << "Find incorrect type of "
238 "MemorySize";
239 continue;
240 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500241 nlohmann::json& totalMemory =
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800242 aResp->res
243 .jsonValue["MemorySummar"
244 "y"]
245 ["TotalSystemMe"
246 "moryGiB"];
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500247 uint64_t* preValue =
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800248 totalMemory
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500249 .get_ptr<uint64_t*>();
Cheng C Yang5fd7ba62019-11-28 15:58:08 +0800250 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 Tanous6c34de42018-08-29 13:37:36 -0700264 }
Ed Tanous029573d2019-02-01 10:57:49 -0800265 }
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500266 else
267 {
268 auto getDimmProperties =
269 [aResp](
270 const boost::system::error_code
Ed Tanouscb13a392020-07-25 19:02:03 +0000271 ec3,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500272 const std::variant<bool>&
273 dimmState) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000274 if (ec3)
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500275 {
276 BMCWEB_LOG_ERROR
277 << "DBUS response "
278 "error "
Ed Tanouscb13a392020-07-25 19:02:03 +0000279 << ec3;
Alpana Kumari9d3ae102019-04-12 06:49:32 -0500280 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 Tanous029573d2019-02-01 10:57:49 -0800296 },
297 connection.first, path,
298 "org.freedesktop.DBus.Properties", "GetAll",
299 "xyz.openbmc_project.Inventory.Item.Dimm");
James Feist5bc2dc82019-10-22 14:33:16 -0700300
301 memoryHealth->inventory.emplace_back(path);
Ed Tanous029573d2019-02-01 10:57:49 -0800302 }
303 else if (interfaceName ==
304 "xyz.openbmc_project.Inventory.Item.Cpu")
305 {
306 BMCWEB_LOG_DEBUG
307 << "Found Cpu, now get its properties.";
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500308
Ed Tanous029573d2019-02-01 10:57:49 -0800309 crow::connections::systemBus->async_method_call(
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500310 [aResp, service{connection.first},
Ed Tanousf23b7292020-10-15 09:41:17 -0700311 path](const boost::system::error_code ec2,
312 const std::vector<
313 std::pair<std::string, VariantType>>&
314 properties) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000315 if (ec2)
Ed Tanous029573d2019-02-01 10:57:49 -0800316 {
317 BMCWEB_LOG_ERROR
Ed Tanouscb13a392020-07-25 19:02:03 +0000318 << "DBUS response error " << ec2;
Ed Tanous029573d2019-02-01 10:57:49 -0800319 messages::internalError(aResp->res);
320 return;
321 }
322 BMCWEB_LOG_DEBUG << "Got "
323 << properties.size()
Gunnar Mills698654b2019-10-16 13:17:37 -0500324 << " Cpu properties.";
Ed Tanous04a258f2018-10-15 08:00:41 -0700325
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500326 if (properties.size() > 0)
327 {
Zhikui Ren9cf21522020-09-10 11:13:14 -0700328 const uint64_t* processorId = nullptr;
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700329 const std::string* procFamily = nullptr;
330 nlohmann::json& procSummary =
331 aResp->res.jsonValue["ProcessorSumm"
332 "ary"];
333 nlohmann::json& procCount =
334 procSummary["Count"];
335
336 auto procCountPtr = procCount.get_ptr<
337 nlohmann::json::
338 number_integer_t*>();
339 if (procCountPtr == nullptr)
340 {
341 messages::internalError(aResp->res);
342 return;
343 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500344 for (const auto& property : properties)
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500345 {
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700346
Zhikui Ren9cf21522020-09-10 11:13:14 -0700347 if (property.first == "Id")
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700348 {
349 processorId =
Zhikui Ren9cf21522020-09-10 11:13:14 -0700350 std::get_if<uint64_t>(
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700351 &property.second);
352 if (nullptr != procFamily)
Ed Tanous3174e4d2020-10-07 11:41:22 -0700353 {
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700354 break;
Ed Tanous3174e4d2020-10-07 11:41:22 -0700355 }
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700356 continue;
357 }
358
Zhikui Ren9cf21522020-09-10 11:13:14 -0700359 if (property.first == "Family")
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500360 {
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700361 procFamily =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500362 std::get_if<std::string>(
363 &property.second);
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700364 if (nullptr != processorId)
Ed Tanous3174e4d2020-10-07 11:41:22 -0700365 {
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700366 break;
Ed Tanous3174e4d2020-10-07 11:41:22 -0700367 }
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700368 continue;
369 }
370 }
James Feistb4b95952019-12-05 15:01:55 -0800371
Zhikui Ren029cc1f2020-08-25 15:21:41 -0700372 if (procFamily != nullptr &&
373 processorId != nullptr)
374 {
375 if (procCountPtr != nullptr &&
376 *processorId != 0)
377 {
378 *procCountPtr += 1;
379 procSummary["Status"]["State"] =
380 "Enabled";
381
382 procSummary["Model"] =
383 *procFamily;
Ed Tanous6c34de42018-08-29 13:37:36 -0700384 }
385 }
Ed Tanous029573d2019-02-01 10:57:49 -0800386 }
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500387 else
388 {
389 auto getCpuPresenceState =
390 [aResp](
391 const boost::system::error_code
Ed Tanouscb13a392020-07-25 19:02:03 +0000392 ec3,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500393 const std::variant<bool>&
394 cpuPresenceCheck) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000395 if (ec3)
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500396 {
397 BMCWEB_LOG_ERROR
398 << "DBUS response "
399 "error "
Ed Tanouscb13a392020-07-25 19:02:03 +0000400 << ec3;
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500401 return;
402 }
403 modifyCpuPresenceState(
404 aResp, cpuPresenceCheck);
405 };
406
407 auto getCpuFunctionalState =
408 [aResp](
409 const boost::system::error_code
Ed Tanouscb13a392020-07-25 19:02:03 +0000410 ec3,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500411 const std::variant<bool>&
412 cpuFunctionalCheck) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000413 if (ec3)
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500414 {
415 BMCWEB_LOG_ERROR
416 << "DBUS response "
417 "error "
Ed Tanouscb13a392020-07-25 19:02:03 +0000418 << ec3;
Alpana Kumari57e8c9b2019-04-15 01:09:36 -0500419 return;
420 }
421 modifyCpuFunctionalState(
422 aResp, cpuFunctionalCheck);
423 };
424 // Get the Presence of CPU
425 crow::connections::systemBus
426 ->async_method_call(
427 std::move(getCpuPresenceState),
428 service, path,
429 "org.freedesktop.DBus."
430 "Properties",
431 "Get",
432 "xyz.openbmc_project.Inventory."
433 "Item",
434 "Present");
435
436 // Get the Functional State
437 crow::connections::systemBus
438 ->async_method_call(
439 std::move(
440 getCpuFunctionalState),
441 service, path,
442 "org.freedesktop.DBus."
443 "Properties",
444 "Get",
445 "xyz.openbmc_project.State."
446 "Decorator."
447 "OperationalStatus",
448 "Functional");
449
450 // Get the MODEL from
451 // xyz.openbmc_project.Inventory.Decorator.Asset
452 // support it later as Model is Empty
453 // currently.
454 }
Ed Tanous029573d2019-02-01 10:57:49 -0800455 },
456 connection.first, path,
457 "org.freedesktop.DBus.Properties", "GetAll",
458 "xyz.openbmc_project.Inventory.Item.Cpu");
James Feist5bc2dc82019-10-22 14:33:16 -0700459
460 cpuHealth->inventory.emplace_back(path);
Ed Tanous029573d2019-02-01 10:57:49 -0800461 }
462 else if (interfaceName ==
463 "xyz.openbmc_project.Common.UUID")
464 {
465 BMCWEB_LOG_DEBUG
466 << "Found UUID, now get its properties.";
467 crow::connections::systemBus->async_method_call(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500468 [aResp](
Ed Tanouscb13a392020-07-25 19:02:03 +0000469 const boost::system::error_code ec3,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500470 const std::vector<
471 std::pair<std::string, VariantType>>&
472 properties) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000473 if (ec3)
Ed Tanous029573d2019-02-01 10:57:49 -0800474 {
475 BMCWEB_LOG_DEBUG
Ed Tanouscb13a392020-07-25 19:02:03 +0000476 << "DBUS response error " << ec3;
Ed Tanous029573d2019-02-01 10:57:49 -0800477 messages::internalError(aResp->res);
478 return;
479 }
480 BMCWEB_LOG_DEBUG << "Got "
481 << properties.size()
Gunnar Mills698654b2019-10-16 13:17:37 -0500482 << " UUID properties.";
Ed Tanous029573d2019-02-01 10:57:49 -0800483 for (const std::pair<std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500484 VariantType>&
485 property : properties)
Ed Tanous029573d2019-02-01 10:57:49 -0800486 {
Ed Tanous029573d2019-02-01 10:57:49 -0800487 if (property.first == "UUID")
488 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500489 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500490 std::get_if<std::string>(
491 &property.second);
Ed Tanous04a258f2018-10-15 08:00:41 -0700492
Ed Tanous029573d2019-02-01 10:57:49 -0800493 if (value != nullptr)
494 {
495 std::string valueStr = *value;
496 if (valueStr.size() == 32)
Ed Tanous6c34de42018-08-29 13:37:36 -0700497 {
Ed Tanous029573d2019-02-01 10:57:49 -0800498 valueStr.insert(8, 1, '-');
499 valueStr.insert(13, 1, '-');
500 valueStr.insert(18, 1, '-');
501 valueStr.insert(23, 1, '-');
Ed Tanous6c34de42018-08-29 13:37:36 -0700502 }
Ed Tanous029573d2019-02-01 10:57:49 -0800503 BMCWEB_LOG_DEBUG << "UUID = "
504 << valueStr;
505 aResp->res.jsonValue["UUID"] =
506 valueStr;
Ed Tanous6c34de42018-08-29 13:37:36 -0700507 }
508 }
Ed Tanous029573d2019-02-01 10:57:49 -0800509 }
510 },
511 connection.first, path,
512 "org.freedesktop.DBus.Properties", "GetAll",
513 "xyz.openbmc_project.Common.UUID");
514 }
515 else if (interfaceName ==
516 "xyz.openbmc_project.Inventory.Item.System")
517 {
518 crow::connections::systemBus->async_method_call(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500519 [aResp](
Ed Tanouscb13a392020-07-25 19:02:03 +0000520 const boost::system::error_code ec2,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500521 const std::vector<
522 std::pair<std::string, VariantType>>&
523 propertiesList) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000524 if (ec2)
Ed Tanous029573d2019-02-01 10:57:49 -0800525 {
James Feiste4a4b9a2019-06-20 14:08:07 -0700526 // doesn't have to include this
527 // interface
Ed Tanous029573d2019-02-01 10:57:49 -0800528 return;
529 }
Gunnar Mills698654b2019-10-16 13:17:37 -0500530 BMCWEB_LOG_DEBUG
531 << "Got " << propertiesList.size()
532 << " properties for system";
Ed Tanous029573d2019-02-01 10:57:49 -0800533 for (const std::pair<std::string,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500534 VariantType>&
535 property : propertiesList)
Ed Tanous029573d2019-02-01 10:57:49 -0800536 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500537 const std::string& propertyName =
beccabroekfc5afcf2019-03-05 14:35:15 -0600538 property.first;
539 if ((propertyName == "PartNumber") ||
540 (propertyName == "SerialNumber") ||
541 (propertyName == "Manufacturer") ||
SunnySrivastava19845235d962020-06-30 03:09:00 -0500542 (propertyName == "Model") ||
543 (propertyName == "SubModel"))
Ed Tanous029573d2019-02-01 10:57:49 -0800544 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500545 const std::string* value =
beccabroekfc5afcf2019-03-05 14:35:15 -0600546 std::get_if<std::string>(
547 &property.second);
548 if (value != nullptr)
549 {
550 aResp->res
551 .jsonValue[propertyName] =
552 *value;
553 }
Ed Tanous029573d2019-02-01 10:57:49 -0800554 }
555 }
Gunnar Millsc1e236a2020-04-14 21:36:33 -0500556
Andrew Geisslercb7e1e72019-02-19 13:05:38 -0600557 // Grab the bios version
Gunnar Millsf97ddba2020-08-20 15:57:40 -0500558 fw_util::populateFirmwareInformation(
Andrew Geisslercb7e1e72019-02-19 13:05:38 -0600559 aResp, fw_util::biosPurpose,
Gunnar Mills72d566d2020-07-21 12:44:00 -0500560 "BiosVersion", false);
Ed Tanous029573d2019-02-01 10:57:49 -0800561 },
562 connection.first, path,
563 "org.freedesktop.DBus.Properties", "GetAll",
564 "xyz.openbmc_project.Inventory.Decorator."
565 "Asset");
James Feiste4a4b9a2019-06-20 14:08:07 -0700566
567 crow::connections::systemBus->async_method_call(
568 [aResp](
Ed Tanouscb13a392020-07-25 19:02:03 +0000569 const boost::system::error_code ec2,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500570 const std::variant<std::string>& property) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000571 if (ec2)
James Feiste4a4b9a2019-06-20 14:08:07 -0700572 {
573 // doesn't have to include this
574 // interface
575 return;
576 }
577
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500578 const std::string* value =
James Feiste4a4b9a2019-06-20 14:08:07 -0700579 std::get_if<std::string>(&property);
580 if (value != nullptr)
581 {
582 aResp->res.jsonValue["AssetTag"] =
583 *value;
584 }
585 },
586 connection.first, path,
587 "org.freedesktop.DBus.Properties", "Get",
588 "xyz.openbmc_project.Inventory.Decorator."
589 "AssetTag",
590 "AssetTag");
Ed Tanous6c34de42018-08-29 13:37:36 -0700591 }
592 }
593 }
594 }
Ed Tanous6c34de42018-08-29 13:37:36 -0700595 },
596 "xyz.openbmc_project.ObjectMapper",
597 "/xyz/openbmc_project/object_mapper",
598 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
Ed Tanous66173382018-08-15 18:20:59 -0700599 "/xyz/openbmc_project/inventory", int32_t(0),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500600 std::array<const char*, 5>{
Ed Tanous66173382018-08-15 18:20:59 -0700601 "xyz.openbmc_project.Inventory.Decorator.Asset",
602 "xyz.openbmc_project.Inventory.Item.Cpu",
603 "xyz.openbmc_project.Inventory.Item.Dimm",
604 "xyz.openbmc_project.Inventory.Item.System",
605 "xyz.openbmc_project.Common.UUID",
606 });
Ed Tanous6c34de42018-08-29 13:37:36 -0700607}
608
609/**
Ed Tanous6c34de42018-08-29 13:37:36 -0700610 * @brief Retrieves host state properties over dbus
611 *
612 * @param[in] aResp Shared pointer for completing asynchronous calls.
613 *
614 * @return None.
615 */
Ed Tanousb5a76932020-09-29 16:16:58 -0700616inline void getHostState(const std::shared_ptr<AsyncResp>& aResp)
Ed Tanous6c34de42018-08-29 13:37:36 -0700617{
618 BMCWEB_LOG_DEBUG << "Get host information.";
619 crow::connections::systemBus->async_method_call(
Jennifer Leec5d03ff2019-03-08 15:42:58 -0800620 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500621 const std::variant<std::string>& hostState) {
Ed Tanous6c34de42018-08-29 13:37:36 -0700622 if (ec)
623 {
624 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700625 messages::internalError(aResp->res);
Ed Tanous6c34de42018-08-29 13:37:36 -0700626 return;
627 }
Ed Tanous66173382018-08-15 18:20:59 -0700628
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500629 const std::string* s = std::get_if<std::string>(&hostState);
Ed Tanous66173382018-08-15 18:20:59 -0700630 BMCWEB_LOG_DEBUG << "Host state: " << *s;
631 if (s != nullptr)
Ed Tanous6c34de42018-08-29 13:37:36 -0700632 {
Ed Tanous66173382018-08-15 18:20:59 -0700633 // Verify Host State
Andrew Geissler94732662019-01-08 19:32:16 -0800634 if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
Ed Tanous6c34de42018-08-29 13:37:36 -0700635 {
Ed Tanous66173382018-08-15 18:20:59 -0700636 aResp->res.jsonValue["PowerState"] = "On";
637 aResp->res.jsonValue["Status"]["State"] = "Enabled";
638 }
Andrew Geissler83935af2020-02-13 10:24:53 -0600639 else if (*s == "xyz.openbmc_project.State.Host.HostState."
Gunnar Mills8c888602020-05-01 14:25:09 -0500640 "Quiesced")
641 {
642 aResp->res.jsonValue["PowerState"] = "On";
643 aResp->res.jsonValue["Status"]["State"] = "Quiesced";
644 }
645 else if (*s == "xyz.openbmc_project.State.Host.HostState."
Andrew Geissler83935af2020-02-13 10:24:53 -0600646 "DiagnosticMode")
647 {
648 aResp->res.jsonValue["PowerState"] = "On";
649 aResp->res.jsonValue["Status"]["State"] = "InTest";
650 }
Andrew Geissler1a2a1432021-01-06 13:48:57 -0600651 else if (*s == "xyz.openbmc_project.State.Host.HostState."
652 "TransitioningToRunning")
653 {
654 aResp->res.jsonValue["PowerState"] = "PoweringOn";
655 aResp->res.jsonValue["Status"]["State"] = "Disabled";
656 }
657 else if (*s == "xyz.openbmc_project.State.Host.HostState."
658 "TransitioningToOff")
659 {
660 aResp->res.jsonValue["PowerState"] = "PoweringOff";
661 aResp->res.jsonValue["Status"]["State"] = "Disabled";
662 }
Ed Tanous66173382018-08-15 18:20:59 -0700663 else
664 {
665 aResp->res.jsonValue["PowerState"] = "Off";
666 aResp->res.jsonValue["Status"]["State"] = "Disabled";
Ed Tanous6c34de42018-08-29 13:37:36 -0700667 }
668 }
669 },
670 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
Ed Tanous66173382018-08-15 18:20:59 -0700671 "org.freedesktop.DBus.Properties", "Get",
672 "xyz.openbmc_project.State.Host", "CurrentHostState");
Ed Tanous6c34de42018-08-29 13:37:36 -0700673}
674
675/**
Gunnar Mills786d0f62020-07-08 13:43:15 -0500676 * @brief Translates boot source DBUS property value to redfish.
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530677 *
678 * @param[in] dbusSource The boot source in DBUS speak.
679 *
680 * @return Returns as a string, the boot source in Redfish terms. If translation
681 * cannot be done, returns an empty string.
682 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000683inline std::string dbusToRfBootSource(const std::string& dbusSource)
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530684{
685 if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default")
686 {
687 return "None";
688 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700689 if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530690 {
691 return "Hdd";
692 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700693 if (dbusSource ==
694 "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530695 {
696 return "Cd";
697 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700698 if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530699 {
700 return "Pxe";
701 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700702 if (dbusSource ==
703 "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia")
Jennifer Lee9f16b2c2019-04-19 15:33:48 -0700704 {
705 return "Usb";
706 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700707 return "";
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530708}
709
710/**
Gunnar Mills786d0f62020-07-08 13:43:15 -0500711 * @brief Translates boot mode DBUS property value to redfish.
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530712 *
713 * @param[in] dbusMode The boot mode in DBUS speak.
714 *
715 * @return Returns as a string, the boot mode in Redfish terms. If translation
716 * cannot be done, returns an empty string.
717 */
Ed Tanous23a21a12020-07-25 04:45:05 +0000718inline std::string dbusToRfBootMode(const std::string& dbusMode)
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530719{
720 if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
721 {
722 return "None";
723 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700724 if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530725 {
726 return "Diags";
727 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700728 if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530729 {
730 return "BiosSetup";
731 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700732 return "";
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530733}
734
735/**
Gunnar Mills786d0f62020-07-08 13:43:15 -0500736 * @brief Translates boot source from Redfish to the DBus boot paths.
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530737 *
738 * @param[in] rfSource The boot source in Redfish.
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700739 * @param[out] bootSource The DBus source
740 * @param[out] bootMode the DBus boot mode
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530741 *
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700742 * @return Integer error code.
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530743 */
Ed Tanousb5a76932020-09-29 16:16:58 -0700744inline int assignBootParameters(const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500745 const std::string& rfSource,
746 std::string& bootSource, std::string& bootMode)
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530747{
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700748 // The caller has initialized the bootSource and bootMode to:
749 // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
750 // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
751 // Only modify the bootSource/bootMode variable needed to achieve the
752 // desired boot action.
753
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530754 if (rfSource == "None")
755 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700756 return 0;
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530757 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700758 if (rfSource == "Pxe")
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530759 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700760 bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network";
761 }
762 else if (rfSource == "Hdd")
763 {
764 bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk";
765 }
766 else if (rfSource == "Diags")
767 {
768 bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe";
769 }
770 else if (rfSource == "Cd")
771 {
772 bootSource =
773 "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia";
774 }
775 else if (rfSource == "BiosSetup")
776 {
777 bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup";
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530778 }
Jennifer Lee9f16b2c2019-04-19 15:33:48 -0700779 else if (rfSource == "Usb")
780 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700781 bootSource =
782 "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia";
Jennifer Lee9f16b2c2019-04-19 15:33:48 -0700783 }
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530784 else
785 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700786 BMCWEB_LOG_DEBUG << "Invalid property value for "
787 "BootSourceOverrideTarget: "
788 << bootSource;
789 messages::propertyValueNotInList(aResp->res, rfSource,
790 "BootSourceTargetOverride");
791 return -1;
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530792 }
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700793 return 0;
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530794}
Andrew Geissler978b8802020-11-19 13:36:40 -0600795/**
796 * @brief Retrieves boot progress of the system
797 *
798 * @param[in] aResp Shared pointer for generating response message.
799 *
800 * @return None.
801 */
802inline void getBootProgress(const std::shared_ptr<AsyncResp>& aResp)
803{
804 crow::connections::systemBus->async_method_call(
805 [aResp](const boost::system::error_code ec,
806 const std::variant<std::string>& bootProgress) {
807 if (ec)
808 {
809 // BootProgress is an optional object so just do nothing if
810 // not found
811 return;
812 }
813
814 const std::string* bootProgressStr =
815 std::get_if<std::string>(&bootProgress);
816
817 if (!bootProgressStr)
818 {
819 // Interface implemented but property not found, return error
820 // for that
821 messages::internalError(aResp->res);
822 return;
823 }
824
825 BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr;
826
827 // Now convert the D-Bus BootProgress to the appropriate Redfish
828 // enum
829 std::string rfBpLastState = "None";
830 if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress."
831 "ProgressStages.Unspecified")
832 {
833 rfBpLastState = "None";
834 }
835 else if (*bootProgressStr ==
836 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
837 "PrimaryProcInit")
838 {
839 rfBpLastState = "PrimaryProcessorInitializationStarted";
840 }
841 else if (*bootProgressStr ==
842 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
843 "BusInit")
844 {
845 rfBpLastState = "BusInitializationStarted";
846 }
847 else if (*bootProgressStr ==
848 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
849 "MemoryInit")
850 {
851 rfBpLastState = "MemoryInitializationStarted";
852 }
853 else if (*bootProgressStr ==
854 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
855 "SecondaryProcInit")
856 {
857 rfBpLastState = "SecondaryProcessorInitializationStarted";
858 }
859 else if (*bootProgressStr ==
860 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
861 "PCIInit")
862 {
863 rfBpLastState = "PCIResourceConfigStarted";
864 }
865 else if (*bootProgressStr ==
866 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
867 "SystemInitComplete")
868 {
869 rfBpLastState = "SystemHardwareInitializationComplete";
870 }
871 else if (*bootProgressStr ==
872 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
873 "OSStart")
874 {
875 rfBpLastState = "OSBootStarted";
876 }
877 else if (*bootProgressStr ==
878 "xyz.openbmc_project.State.Boot.Progress.ProgressStages."
879 "OSRunning")
880 {
881 rfBpLastState = "OSRunning";
882 }
883 else
884 {
885 BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress "
886 << *bootProgressStr;
887 // Just return the default
888 }
889
890 aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState;
891 },
892 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
893 "org.freedesktop.DBus.Properties", "Get",
894 "xyz.openbmc_project.State.Boot.Progress", "BootProgress");
895}
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530896
897/**
898 * @brief Retrieves boot mode over DBUS and fills out the response
899 *
900 * @param[in] aResp Shared pointer for generating response message.
901 * @param[in] bootDbusObj The dbus object to query for boot properties.
902 *
903 * @return None.
904 */
Ed Tanousb5a76932020-09-29 16:16:58 -0700905inline void getBootMode(const std::shared_ptr<AsyncResp>& aResp,
906 const std::string& bootDbusObj)
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530907{
908 crow::connections::systemBus->async_method_call(
909 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500910 const std::variant<std::string>& bootMode) {
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530911 if (ec)
912 {
913 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
914 messages::internalError(aResp->res);
915 return;
916 }
917
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500918 const std::string* bootModeStr =
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530919 std::get_if<std::string>(&bootMode);
920
921 if (!bootModeStr)
922 {
923 messages::internalError(aResp->res);
924 return;
925 }
926
927 BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
928
929 // TODO (Santosh): Do we need to support override mode?
930 aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy";
931 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish."
932 "AllowableValues"] = {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -0700933 "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530934
935 if (*bootModeStr !=
936 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
937 {
938 auto rfMode = dbusToRfBootMode(*bootModeStr);
939 if (!rfMode.empty())
940 {
941 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
942 rfMode;
943 }
944 }
945
946 // If the BootSourceOverrideTarget is still "None" at the end,
947 // reset the BootSourceOverrideEnabled to indicate that
948 // overrides are disabled
949 if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] ==
950 "None")
951 {
952 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
953 "Disabled";
954 }
955 },
956 "xyz.openbmc_project.Settings", bootDbusObj,
957 "org.freedesktop.DBus.Properties", "Get",
958 "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
959}
960
961/**
962 * @brief Retrieves boot source over DBUS
963 *
964 * @param[in] aResp Shared pointer for generating response message.
965 * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time.
966 *
967 * @return None.
968 */
Ed Tanousf23b7292020-10-15 09:41:17 -0700969inline void getBootSource(const std::shared_ptr<AsyncResp>& aResp,
970 bool oneTimeEnabled)
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530971{
972 std::string bootDbusObj =
973 oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time"
974 : "/xyz/openbmc_project/control/host0/boot";
975
976 BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled;
977 aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
978 (oneTimeEnabled) ? "Once" : "Continuous";
979
980 crow::connections::systemBus->async_method_call(
981 [aResp, bootDbusObj](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500982 const std::variant<std::string>& bootSource) {
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530983 if (ec)
984 {
985 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
986 messages::internalError(aResp->res);
987 return;
988 }
989
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500990 const std::string* bootSourceStr =
Santosh Puranik491d8ee2019-02-06 19:46:56 +0530991 std::get_if<std::string>(&bootSource);
992
993 if (!bootSourceStr)
994 {
995 messages::internalError(aResp->res);
996 return;
997 }
998 BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
999
1000 auto rfSource = dbusToRfBootSource(*bootSourceStr);
1001 if (!rfSource.empty())
1002 {
1003 aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
1004 rfSource;
1005 }
1006 },
1007 "xyz.openbmc_project.Settings", bootDbusObj,
1008 "org.freedesktop.DBus.Properties", "Get",
1009 "xyz.openbmc_project.Control.Boot.Source", "BootSource");
Ed Tanousf23b7292020-10-15 09:41:17 -07001010 getBootMode(aResp, bootDbusObj);
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301011}
1012
1013/**
1014 * @brief Retrieves "One time" enabled setting over DBUS and calls function to
1015 * get boot source and boot mode.
1016 *
1017 * @param[in] aResp Shared pointer for generating response message.
1018 *
1019 * @return None.
1020 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001021inline void getBootProperties(const std::shared_ptr<AsyncResp>& aResp)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301022{
1023 BMCWEB_LOG_DEBUG << "Get boot information.";
1024
1025 crow::connections::systemBus->async_method_call(
Jennifer Leec5d03ff2019-03-08 15:42:58 -08001026 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001027 const std::variant<bool>& oneTime) {
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301028 if (ec)
1029 {
1030 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
James Feist2a833c72019-07-19 10:17:13 -07001031 // not an error, don't have to have the interface
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301032 return;
1033 }
1034
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001035 const bool* oneTimePtr = std::get_if<bool>(&oneTime);
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301036
1037 if (!oneTimePtr)
1038 {
1039 messages::internalError(aResp->res);
1040 return;
1041 }
1042 getBootSource(aResp, *oneTimePtr);
1043 },
1044 "xyz.openbmc_project.Settings",
1045 "/xyz/openbmc_project/control/host0/boot/one_time",
1046 "org.freedesktop.DBus.Properties", "Get",
1047 "xyz.openbmc_project.Object.Enable", "Enabled");
1048}
1049
1050/**
Gunnar Millsc0557e12020-06-30 11:26:20 -05001051 * @brief Retrieves the Last Reset Time
1052 *
1053 * "Reset" is an overloaded term in Redfish, "Reset" includes power on
1054 * and power off. Even though this is the "system" Redfish object look at the
1055 * chassis D-Bus interface for the LastStateChangeTime since this has the
1056 * last power operation time.
1057 *
1058 * @param[in] aResp Shared pointer for generating response message.
1059 *
1060 * @return None.
1061 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001062inline void getLastResetTime(const std::shared_ptr<AsyncResp>& aResp)
Gunnar Millsc0557e12020-06-30 11:26:20 -05001063{
1064 BMCWEB_LOG_DEBUG << "Getting System Last Reset Time";
1065
1066 crow::connections::systemBus->async_method_call(
1067 [aResp](const boost::system::error_code ec,
1068 std::variant<uint64_t>& lastResetTime) {
1069 if (ec)
1070 {
1071 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1072 return;
1073 }
1074
1075 const uint64_t* lastResetTimePtr =
1076 std::get_if<uint64_t>(&lastResetTime);
1077
1078 if (!lastResetTimePtr)
1079 {
1080 messages::internalError(aResp->res);
1081 return;
1082 }
1083 // LastStateChangeTime is epoch time, in milliseconds
1084 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
1085 time_t lastResetTimeStamp =
1086 static_cast<time_t>(*lastResetTimePtr / 1000);
1087
1088 // Convert to ISO 8601 standard
1089 aResp->res.jsonValue["LastResetTime"] =
1090 crow::utility::getDateTime(lastResetTimeStamp);
1091 },
1092 "xyz.openbmc_project.State.Chassis",
1093 "/xyz/openbmc_project/state/chassis0",
1094 "org.freedesktop.DBus.Properties", "Get",
1095 "xyz.openbmc_project.State.Chassis", "LastStateChangeTime");
1096}
1097
1098/**
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001099 * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot.
1100 *
1101 * @param[in] aResp Shared pointer for generating response message.
1102 *
1103 * @return None.
1104 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001105inline void getAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp)
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001106{
1107 BMCWEB_LOG_DEBUG << "Get Automatic Retry policy";
1108
1109 crow::connections::systemBus->async_method_call(
1110 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001111 std::variant<bool>& autoRebootEnabled) {
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001112 if (ec)
1113 {
1114 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1115 return;
1116 }
1117
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001118 const bool* autoRebootEnabledPtr =
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001119 std::get_if<bool>(&autoRebootEnabled);
1120
1121 if (!autoRebootEnabledPtr)
1122 {
1123 messages::internalError(aResp->res);
1124 return;
1125 }
1126
1127 BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr;
1128 if (*autoRebootEnabledPtr == true)
1129 {
1130 aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
1131 "RetryAttempts";
1132 // If AutomaticRetry (AutoReboot) is enabled see how many
1133 // attempts are left
1134 crow::connections::systemBus->async_method_call(
Ed Tanouscb13a392020-07-25 19:02:03 +00001135 [aResp](const boost::system::error_code ec2,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001136 std::variant<uint32_t>& autoRebootAttemptsLeft) {
Ed Tanouscb13a392020-07-25 19:02:03 +00001137 if (ec2)
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001138 {
Ed Tanouscb13a392020-07-25 19:02:03 +00001139 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2;
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001140 return;
1141 }
1142
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001143 const uint32_t* autoRebootAttemptsLeftPtr =
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001144 std::get_if<uint32_t>(&autoRebootAttemptsLeft);
1145
1146 if (!autoRebootAttemptsLeftPtr)
1147 {
1148 messages::internalError(aResp->res);
1149 return;
1150 }
1151
1152 BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: "
1153 << *autoRebootAttemptsLeftPtr;
1154
1155 aResp->res
1156 .jsonValue["Boot"]
1157 ["RemainingAutomaticRetryAttempts"] =
1158 *autoRebootAttemptsLeftPtr;
1159 },
1160 "xyz.openbmc_project.State.Host",
1161 "/xyz/openbmc_project/state/host0",
1162 "org.freedesktop.DBus.Properties", "Get",
1163 "xyz.openbmc_project.Control.Boot.RebootAttempts",
1164 "AttemptsLeft");
1165 }
1166 else
1167 {
1168 aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
1169 "Disabled";
1170 }
1171
1172 // Not on D-Bus. Hardcoded here:
1173 // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71
1174 aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3;
Gunnar Mills69f35302020-05-17 16:06:31 -05001175
1176 // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways,
1177 // and RetryAttempts. OpenBMC only supports Disabled and
1178 // RetryAttempts.
1179 aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish."
1180 "AllowableValues"] = {"Disabled",
1181 "RetryAttempts"};
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05001182 },
1183 "xyz.openbmc_project.Settings",
1184 "/xyz/openbmc_project/control/host0/auto_reboot",
1185 "org.freedesktop.DBus.Properties", "Get",
1186 "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot");
1187}
1188
1189/**
George Liuc6a620f2020-04-10 17:18:11 +08001190 * @brief Retrieves power restore policy over DBUS.
1191 *
1192 * @param[in] aResp Shared pointer for generating response message.
1193 *
1194 * @return None.
1195 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001196inline void getPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp)
George Liuc6a620f2020-04-10 17:18:11 +08001197{
1198 BMCWEB_LOG_DEBUG << "Get power restore policy";
1199
1200 crow::connections::systemBus->async_method_call(
1201 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001202 std::variant<std::string>& policy) {
George Liuc6a620f2020-04-10 17:18:11 +08001203 if (ec)
1204 {
1205 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1206 return;
1207 }
1208
1209 const boost::container::flat_map<std::string, std::string>
1210 policyMaps = {
1211 {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1212 "AlwaysOn",
1213 "AlwaysOn"},
1214 {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1215 "AlwaysOff",
1216 "AlwaysOff"},
1217 {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
Gunnar Mills37ec9072021-01-05 19:43:44 -06001218 "Restore",
George Liuc6a620f2020-04-10 17:18:11 +08001219 "LastState"}};
1220
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001221 const std::string* policyPtr = std::get_if<std::string>(&policy);
George Liuc6a620f2020-04-10 17:18:11 +08001222
1223 if (!policyPtr)
1224 {
1225 messages::internalError(aResp->res);
1226 return;
1227 }
1228
1229 auto policyMapsIt = policyMaps.find(*policyPtr);
1230 if (policyMapsIt == policyMaps.end())
1231 {
1232 messages::internalError(aResp->res);
1233 return;
1234 }
1235
1236 aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second;
1237 },
1238 "xyz.openbmc_project.Settings",
1239 "/xyz/openbmc_project/control/host0/power_restore_policy",
1240 "org.freedesktop.DBus.Properties", "Get",
1241 "xyz.openbmc_project.Control.Power.RestorePolicy",
1242 "PowerRestorePolicy");
1243}
1244
1245/**
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301246 * @brief Sets boot properties into DBUS object(s).
1247 *
1248 * @param[in] aResp Shared pointer for generating response message.
1249 * @param[in] oneTimeEnabled Is "one-time" setting already enabled.
1250 * @param[in] bootSource The boot source to set.
1251 * @param[in] bootEnable The source override "enable" to set.
1252 *
Johnathan Mantey265c1602019-08-08 11:02:51 -07001253 * @return Integer error code.
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301254 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001255inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp,
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301256 bool oneTimeEnabled,
Ed Tanousf23b7292020-10-15 09:41:17 -07001257 const std::optional<std::string>& bootSource,
1258 const std::optional<std::string>& bootEnable)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301259{
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001260 std::string bootSourceStr =
1261 "xyz.openbmc_project.Control.Boot.Source.Sources.Default";
1262 std::string bootModeStr =
1263 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301264 bool oneTimeSetting = oneTimeEnabled;
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001265 bool useBootSource = true;
1266
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301267 // Validate incoming parameters
1268 if (bootEnable)
1269 {
1270 if (*bootEnable == "Once")
1271 {
1272 oneTimeSetting = true;
1273 }
1274 else if (*bootEnable == "Continuous")
1275 {
1276 oneTimeSetting = false;
1277 }
1278 else if (*bootEnable == "Disabled")
1279 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001280 BMCWEB_LOG_DEBUG << "Boot source override will be disabled";
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301281 oneTimeSetting = false;
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001282 useBootSource = false;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301283 }
1284 else
1285 {
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301286 BMCWEB_LOG_DEBUG << "Unsupported value for "
1287 "BootSourceOverrideEnabled: "
1288 << *bootEnable;
1289 messages::propertyValueNotInList(aResp->res, *bootEnable,
1290 "BootSourceOverrideEnabled");
1291 return;
1292 }
1293 }
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301294
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001295 if (bootSource && useBootSource)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301296 {
1297 // Source target specified
1298 BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
1299 // Figure out which DBUS interface and property to use
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001300 if (assignBootParameters(aResp, *bootSource, bootSourceStr,
1301 bootModeStr))
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301302 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001303 BMCWEB_LOG_DEBUG
1304 << "Invalid property value for BootSourceOverrideTarget: "
1305 << *bootSource;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301306 messages::propertyValueNotInList(aResp->res, *bootSource,
1307 "BootSourceTargetOverride");
1308 return;
1309 }
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001310 }
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301311
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001312 // Act on validated parameters
1313 BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr;
1314 BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001315 const char* bootObj =
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001316 oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time"
1317 : "/xyz/openbmc_project/control/host0/boot";
1318
1319 crow::connections::systemBus->async_method_call(
1320 [aResp](const boost::system::error_code ec) {
1321 if (ec)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301322 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001323 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1324 messages::internalError(aResp->res);
1325 return;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301326 }
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001327 BMCWEB_LOG_DEBUG << "Boot source update done.";
1328 },
1329 "xyz.openbmc_project.Settings", bootObj,
1330 "org.freedesktop.DBus.Properties", "Set",
1331 "xyz.openbmc_project.Control.Boot.Source", "BootSource",
1332 std::variant<std::string>(bootSourceStr));
1333
1334 crow::connections::systemBus->async_method_call(
1335 [aResp](const boost::system::error_code ec) {
1336 if (ec)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301337 {
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001338 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1339 messages::internalError(aResp->res);
1340 return;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301341 }
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07001342 BMCWEB_LOG_DEBUG << "Boot mode update done.";
1343 },
1344 "xyz.openbmc_project.Settings", bootObj,
1345 "org.freedesktop.DBus.Properties", "Set",
1346 "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
1347 std::variant<std::string>(bootModeStr));
1348
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301349 crow::connections::systemBus->async_method_call(
1350 [aResp{std::move(aResp)}](const boost::system::error_code ec) {
1351 if (ec)
1352 {
1353 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1354 messages::internalError(aResp->res);
1355 return;
1356 }
1357 BMCWEB_LOG_DEBUG << "Boot enable update done.";
1358 },
1359 "xyz.openbmc_project.Settings",
1360 "/xyz/openbmc_project/control/host0/boot/one_time",
1361 "org.freedesktop.DBus.Properties", "Set",
1362 "xyz.openbmc_project.Object.Enable", "Enabled",
1363 std::variant<bool>(oneTimeSetting));
1364}
1365
1366/**
1367 * @brief Retrieves "One time" enabled setting over DBUS and calls function to
1368 * set boot source/boot mode properties.
1369 *
1370 * @param[in] aResp Shared pointer for generating response message.
1371 * @param[in] bootSource The boot source from incoming RF request.
1372 * @param[in] bootEnable The boot override enable from incoming RF request.
1373 *
Johnathan Mantey265c1602019-08-08 11:02:51 -07001374 * @return Integer error code.
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301375 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001376inline void setBootSourceProperties(const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills69f35302020-05-17 16:06:31 -05001377 std::optional<std::string> bootSource,
1378 std::optional<std::string> bootEnable)
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301379{
1380 BMCWEB_LOG_DEBUG << "Set boot information.";
1381
1382 crow::connections::systemBus->async_method_call(
Johnathan Mantey265c1602019-08-08 11:02:51 -07001383 [aResp, bootSource{std::move(bootSource)},
Patrick Williams19bd78d2020-05-13 17:38:24 -05001384 bootEnable{std::move(bootEnable)}](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001385 const std::variant<bool>& oneTime) {
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301386 if (ec)
1387 {
1388 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1389 messages::internalError(aResp->res);
1390 return;
1391 }
1392
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001393 const bool* oneTimePtr = std::get_if<bool>(&oneTime);
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301394
1395 if (!oneTimePtr)
1396 {
1397 messages::internalError(aResp->res);
1398 return;
1399 }
1400
1401 BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr;
1402
Ed Tanousf23b7292020-10-15 09:41:17 -07001403 setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable);
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301404 },
1405 "xyz.openbmc_project.Settings",
1406 "/xyz/openbmc_project/control/host0/boot/one_time",
1407 "org.freedesktop.DBus.Properties", "Get",
1408 "xyz.openbmc_project.Object.Enable", "Enabled");
1409}
1410
George Liuc6a620f2020-04-10 17:18:11 +08001411/**
Gunnar Mills98e386e2020-10-30 14:58:09 -05001412 * @brief Sets AssetTag
1413 *
1414 * @param[in] aResp Shared pointer for generating response message.
1415 * @param[in] assetTag "AssetTag" from request.
1416 *
1417 * @return None.
1418 */
1419inline void setAssetTag(const std::shared_ptr<AsyncResp>& aResp,
1420 const std::string& assetTag)
1421{
1422 crow::connections::systemBus->async_method_call(
1423 [aResp, assetTag](
1424 const boost::system::error_code ec,
1425 const std::vector<std::pair<
1426 std::string,
1427 std::vector<std::pair<std::string, std::vector<std::string>>>>>&
1428 subtree) {
1429 if (ec)
1430 {
1431 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
1432 messages::internalError(aResp->res);
1433 return;
1434 }
1435 if (subtree.size() == 0)
1436 {
1437 BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!";
1438 messages::internalError(aResp->res);
1439 return;
1440 }
1441 // Assume only 1 system D-Bus object
1442 // Throw an error if there is more than 1
1443 if (subtree.size() > 1)
1444 {
1445 BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!";
1446 messages::internalError(aResp->res);
1447 return;
1448 }
1449 if (subtree[0].first.empty() || subtree[0].second.size() != 1)
1450 {
1451 BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!";
1452 messages::internalError(aResp->res);
1453 return;
1454 }
1455
1456 const std::string& path = subtree[0].first;
1457 const std::string& service = subtree[0].second.begin()->first;
1458
1459 if (service.empty())
1460 {
1461 BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!";
1462 messages::internalError(aResp->res);
1463 return;
1464 }
1465
1466 crow::connections::systemBus->async_method_call(
1467 [aResp](const boost::system::error_code ec2) {
1468 if (ec2)
1469 {
1470 BMCWEB_LOG_DEBUG
1471 << "D-Bus response error on AssetTag Set " << ec2;
1472 messages::internalError(aResp->res);
1473 return;
1474 }
1475 },
1476 service, path, "org.freedesktop.DBus.Properties", "Set",
1477 "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag",
1478 std::variant<std::string>(assetTag));
1479 },
1480 "xyz.openbmc_project.ObjectMapper",
1481 "/xyz/openbmc_project/object_mapper",
1482 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
1483 "/xyz/openbmc_project/inventory", int32_t(0),
1484 std::array<const char*, 1>{
1485 "xyz.openbmc_project.Inventory.Item.System"});
1486}
1487
1488/**
Gunnar Mills69f35302020-05-17 16:06:31 -05001489 * @brief Sets automaticRetry (Auto Reboot)
1490 *
1491 * @param[in] aResp Shared pointer for generating response message.
1492 * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request.
1493 *
1494 * @return None.
1495 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001496inline void setAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp,
Ed Tanousf23b7292020-10-15 09:41:17 -07001497 const std::string& automaticRetryConfig)
Gunnar Mills69f35302020-05-17 16:06:31 -05001498{
1499 BMCWEB_LOG_DEBUG << "Set Automatic Retry.";
1500
1501 // OpenBMC only supports "Disabled" and "RetryAttempts".
1502 bool autoRebootEnabled;
1503
1504 if (automaticRetryConfig == "Disabled")
1505 {
1506 autoRebootEnabled = false;
1507 }
1508 else if (automaticRetryConfig == "RetryAttempts")
1509 {
1510 autoRebootEnabled = true;
1511 }
1512 else
1513 {
1514 BMCWEB_LOG_DEBUG << "Invalid property value for "
1515 "AutomaticRetryConfig: "
1516 << automaticRetryConfig;
1517 messages::propertyValueNotInList(aResp->res, automaticRetryConfig,
1518 "AutomaticRetryConfig");
1519 return;
1520 }
1521
1522 crow::connections::systemBus->async_method_call(
1523 [aResp](const boost::system::error_code ec) {
1524 if (ec)
1525 {
1526 messages::internalError(aResp->res);
1527 return;
1528 }
1529 },
1530 "xyz.openbmc_project.Settings",
1531 "/xyz/openbmc_project/control/host0/auto_reboot",
1532 "org.freedesktop.DBus.Properties", "Set",
1533 "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
1534 std::variant<bool>(autoRebootEnabled));
1535}
1536
1537/**
George Liuc6a620f2020-04-10 17:18:11 +08001538 * @brief Sets power restore policy properties.
1539 *
1540 * @param[in] aResp Shared pointer for generating response message.
1541 * @param[in] policy power restore policy properties from request.
1542 *
1543 * @return None.
1544 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001545inline void setPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills4e69c902021-01-05 19:50:11 -06001546 const std::string& policy)
George Liuc6a620f2020-04-10 17:18:11 +08001547{
1548 BMCWEB_LOG_DEBUG << "Set power restore policy.";
1549
1550 const boost::container::flat_map<std::string, std::string> policyMaps = {
1551 {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1552 "AlwaysOn"},
1553 {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
1554 "AlwaysOff"},
1555 {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
Gunnar Mills37ec9072021-01-05 19:43:44 -06001556 "Restore"}};
George Liuc6a620f2020-04-10 17:18:11 +08001557
1558 std::string powerRestorPolicy;
1559
Gunnar Mills4e69c902021-01-05 19:50:11 -06001560 auto policyMapsIt = policyMaps.find(policy);
George Liuc6a620f2020-04-10 17:18:11 +08001561 if (policyMapsIt == policyMaps.end())
1562 {
Gunnar Mills4e69c902021-01-05 19:50:11 -06001563 messages::propertyValueNotInList(aResp->res, policy,
1564 "PowerRestorePolicy");
George Liuc6a620f2020-04-10 17:18:11 +08001565 return;
1566 }
1567
1568 powerRestorPolicy = policyMapsIt->second;
1569
1570 crow::connections::systemBus->async_method_call(
1571 [aResp](const boost::system::error_code ec) {
1572 if (ec)
1573 {
1574 messages::internalError(aResp->res);
1575 return;
1576 }
1577 },
1578 "xyz.openbmc_project.Settings",
1579 "/xyz/openbmc_project/control/host0/power_restore_policy",
1580 "org.freedesktop.DBus.Properties", "Set",
1581 "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
1582 std::variant<std::string>(powerRestorPolicy));
1583}
1584
AppaRao Pulia6349912019-10-18 17:16:08 +05301585#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
1586/**
1587 * @brief Retrieves provisioning status
1588 *
1589 * @param[in] aResp Shared pointer for completing asynchronous calls.
1590 *
1591 * @return None.
1592 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001593inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp)
AppaRao Pulia6349912019-10-18 17:16:08 +05301594{
1595 BMCWEB_LOG_DEBUG << "Get OEM information.";
1596 crow::connections::systemBus->async_method_call(
1597 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001598 const std::vector<std::pair<std::string, VariantType>>&
1599 propertiesList) {
AppaRao Pulib99fb1a2020-07-08 16:42:48 +05301600 nlohmann::json& oemPFR =
1601 aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"];
James Feist50626f42020-09-23 14:40:47 -07001602 aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
1603 "#OemComputerSystem.OpenBmc";
1604 oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning";
1605
AppaRao Pulia6349912019-10-18 17:16:08 +05301606 if (ec)
1607 {
1608 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
AppaRao Pulib99fb1a2020-07-08 16:42:48 +05301609 // not an error, don't have to have the interface
1610 oemPFR["ProvisioningStatus"] = "NotProvisioned";
AppaRao Pulia6349912019-10-18 17:16:08 +05301611 return;
1612 }
1613
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001614 const bool* provState = nullptr;
1615 const bool* lockState = nullptr;
1616 for (const std::pair<std::string, VariantType>& property :
AppaRao Pulia6349912019-10-18 17:16:08 +05301617 propertiesList)
1618 {
1619 if (property.first == "UfmProvisioned")
1620 {
1621 provState = std::get_if<bool>(&property.second);
1622 }
1623 else if (property.first == "UfmLocked")
1624 {
1625 lockState = std::get_if<bool>(&property.second);
1626 }
1627 }
1628
1629 if ((provState == nullptr) || (lockState == nullptr))
1630 {
1631 BMCWEB_LOG_DEBUG << "Unable to get PFR attributes.";
1632 messages::internalError(aResp->res);
1633 return;
1634 }
1635
AppaRao Pulia6349912019-10-18 17:16:08 +05301636 if (*provState == true)
1637 {
1638 if (*lockState == true)
1639 {
1640 oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked";
1641 }
1642 else
1643 {
1644 oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked";
1645 }
1646 }
1647 else
1648 {
1649 oemPFR["ProvisioningStatus"] = "NotProvisioned";
1650 }
1651 },
1652 "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr",
1653 "org.freedesktop.DBus.Properties", "GetAll",
1654 "xyz.openbmc_project.PFR.Attributes");
1655}
1656#endif
1657
Santosh Puranik491d8ee2019-02-06 19:46:56 +05301658/**
Yong Li51709ff2019-09-30 14:13:04 +08001659 * @brief Translates watchdog timeout action DBUS property value to redfish.
1660 *
1661 * @param[in] dbusAction The watchdog timeout action in D-BUS.
1662 *
1663 * @return Returns as a string, the timeout action in Redfish terms. If
1664 * translation cannot be done, returns an empty string.
1665 */
Ed Tanous23a21a12020-07-25 04:45:05 +00001666inline std::string dbusToRfWatchdogAction(const std::string& dbusAction)
Yong Li51709ff2019-09-30 14:13:04 +08001667{
1668 if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None")
1669 {
1670 return "None";
1671 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001672 if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset")
Yong Li51709ff2019-09-30 14:13:04 +08001673 {
1674 return "ResetSystem";
1675 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001676 if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff")
Yong Li51709ff2019-09-30 14:13:04 +08001677 {
1678 return "PowerDown";
1679 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001680 if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle")
Yong Li51709ff2019-09-30 14:13:04 +08001681 {
1682 return "PowerCycle";
1683 }
1684
1685 return "";
1686}
1687
1688/**
Yong Lic45f0082019-10-10 14:19:01 +08001689 *@brief Translates timeout action from Redfish to DBUS property value.
1690 *
1691 *@param[in] rfAction The timeout action in Redfish.
1692 *
1693 *@return Returns as a string, the time_out action as expected by DBUS.
1694 *If translation cannot be done, returns an empty string.
1695 */
1696
Ed Tanous23a21a12020-07-25 04:45:05 +00001697inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction)
Yong Lic45f0082019-10-10 14:19:01 +08001698{
1699 if (rfAction == "None")
1700 {
1701 return "xyz.openbmc_project.State.Watchdog.Action.None";
1702 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001703 if (rfAction == "PowerCycle")
Yong Lic45f0082019-10-10 14:19:01 +08001704 {
1705 return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle";
1706 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001707 if (rfAction == "PowerDown")
Yong Lic45f0082019-10-10 14:19:01 +08001708 {
1709 return "xyz.openbmc_project.State.Watchdog.Action.PowerOff";
1710 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001711 if (rfAction == "ResetSystem")
Yong Lic45f0082019-10-10 14:19:01 +08001712 {
1713 return "xyz.openbmc_project.State.Watchdog.Action.HardReset";
1714 }
1715
1716 return "";
1717}
1718
1719/**
Yong Li51709ff2019-09-30 14:13:04 +08001720 * @brief Retrieves host watchdog timer properties over DBUS
1721 *
1722 * @param[in] aResp Shared pointer for completing asynchronous calls.
1723 *
1724 * @return None.
1725 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001726inline void getHostWatchdogTimer(const std::shared_ptr<AsyncResp>& aResp)
Yong Li51709ff2019-09-30 14:13:04 +08001727{
1728 BMCWEB_LOG_DEBUG << "Get host watchodg";
1729 crow::connections::systemBus->async_method_call(
1730 [aResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001731 PropertiesType& properties) {
Yong Li51709ff2019-09-30 14:13:04 +08001732 if (ec)
1733 {
1734 // watchdog service is stopped
1735 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1736 return;
1737 }
1738
1739 BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop.";
1740
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001741 nlohmann::json& hostWatchdogTimer =
Yong Li51709ff2019-09-30 14:13:04 +08001742 aResp->res.jsonValue["HostWatchdogTimer"];
1743
1744 // watchdog service is running/enabled
1745 hostWatchdogTimer["Status"]["State"] = "Enabled";
1746
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001747 for (const auto& property : properties)
Yong Li51709ff2019-09-30 14:13:04 +08001748 {
1749 BMCWEB_LOG_DEBUG << "prop=" << property.first;
1750 if (property.first == "Enabled")
1751 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001752 const bool* state = std::get_if<bool>(&property.second);
Yong Li51709ff2019-09-30 14:13:04 +08001753
1754 if (!state)
1755 {
1756 messages::internalError(aResp->res);
1757 continue;
1758 }
1759
1760 hostWatchdogTimer["FunctionEnabled"] = *state;
1761 }
1762 else if (property.first == "ExpireAction")
1763 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001764 const std::string* s =
Yong Li51709ff2019-09-30 14:13:04 +08001765 std::get_if<std::string>(&property.second);
1766 if (!s)
1767 {
1768 messages::internalError(aResp->res);
1769 continue;
1770 }
1771
1772 std::string action = dbusToRfWatchdogAction(*s);
1773 if (action.empty())
1774 {
1775 messages::internalError(aResp->res);
1776 continue;
1777 }
1778 hostWatchdogTimer["TimeoutAction"] = action;
1779 }
1780 }
1781 },
1782 "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0",
1783 "org.freedesktop.DBus.Properties", "GetAll",
1784 "xyz.openbmc_project.State.Watchdog");
1785}
1786
1787/**
Yong Lic45f0082019-10-10 14:19:01 +08001788 * @brief Sets Host WatchDog Timer properties.
1789 *
1790 * @param[in] aResp Shared pointer for generating response message.
1791 * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming
1792 * RF request.
1793 * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request.
1794 *
1795 * @return None.
1796 */
Ed Tanousb5a76932020-09-29 16:16:58 -07001797inline void setWDTProperties(const std::shared_ptr<AsyncResp>& aResp,
Yong Lic45f0082019-10-10 14:19:01 +08001798 const std::optional<bool> wdtEnable,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001799 const std::optional<std::string>& wdtTimeOutAction)
Yong Lic45f0082019-10-10 14:19:01 +08001800{
1801 BMCWEB_LOG_DEBUG << "Set host watchdog";
1802
1803 if (wdtTimeOutAction)
1804 {
1805 std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction);
1806 // check if TimeOut Action is Valid
1807 if (wdtTimeOutActStr.empty())
1808 {
1809 BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: "
1810 << *wdtTimeOutAction;
1811 messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction,
1812 "TimeoutAction");
1813 return;
1814 }
1815
1816 crow::connections::systemBus->async_method_call(
1817 [aResp](const boost::system::error_code ec) {
1818 if (ec)
1819 {
1820 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1821 messages::internalError(aResp->res);
1822 return;
1823 }
1824 },
1825 "xyz.openbmc_project.Watchdog",
1826 "/xyz/openbmc_project/watchdog/host0",
1827 "org.freedesktop.DBus.Properties", "Set",
1828 "xyz.openbmc_project.State.Watchdog", "ExpireAction",
1829 std::variant<std::string>(wdtTimeOutActStr));
1830 }
1831
1832 if (wdtEnable)
1833 {
1834 crow::connections::systemBus->async_method_call(
1835 [aResp](const boost::system::error_code ec) {
1836 if (ec)
1837 {
1838 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1839 messages::internalError(aResp->res);
1840 return;
1841 }
1842 },
1843 "xyz.openbmc_project.Watchdog",
1844 "/xyz/openbmc_project/watchdog/host0",
1845 "org.freedesktop.DBus.Properties", "Set",
1846 "xyz.openbmc_project.State.Watchdog", "Enabled",
1847 std::variant<bool>(*wdtEnable));
1848 }
1849}
1850
1851/**
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02001852 * SystemsCollection derived class for delivering ComputerSystems Collection
1853 * Schema
1854 */
Ed Tanous1abe55e2018-09-05 08:30:59 -07001855class SystemsCollection : public Node
1856{
1857 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001858 SystemsCollection(App& app) : Node(app, "/redfish/v1/Systems/")
Ed Tanous1abe55e2018-09-05 08:30:59 -07001859 {
Ed Tanous1abe55e2018-09-05 08:30:59 -07001860 entityPrivileges = {
1861 {boost::beast::http::verb::get, {{"Login"}}},
1862 {boost::beast::http::verb::head, {{"Login"}}},
1863 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1864 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1865 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1866 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1867 }
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02001868
Ed Tanous1abe55e2018-09-05 08:30:59 -07001869 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001870 void doGet(crow::Response& res, const crow::Request&,
1871 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -07001872 {
Sunitha Harish462023a2020-02-19 08:34:59 -06001873 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous0f74e642018-11-12 15:17:05 -08001874 res.jsonValue["@odata.type"] =
1875 "#ComputerSystemCollection.ComputerSystemCollection";
1876 res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
Ed Tanous0f74e642018-11-12 15:17:05 -08001877 res.jsonValue["Name"] = "Computer System Collection";
Sunitha Harish462023a2020-02-19 08:34:59 -06001878
1879 crow::connections::systemBus->async_method_call(
1880 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00001881 const std::variant<std::string>& /*hostName*/) {
Ed Tanous2c70f802020-09-28 14:29:23 -07001882 nlohmann::json& ifaceArray =
Sunitha Harish462023a2020-02-19 08:34:59 -06001883 asyncResp->res.jsonValue["Members"];
Ed Tanous2c70f802020-09-28 14:29:23 -07001884 ifaceArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001885 auto& count = asyncResp->res.jsonValue["Members@odata.count"];
Ed Tanous2c70f802020-09-28 14:29:23 -07001886 ifaceArray.push_back(
Ed Tanouscb13a392020-07-25 19:02:03 +00001887 {{"@odata.id", "/redfish/v1/Systems/system"}});
Tim Lee94bda602020-11-19 14:14:27 +08001888 count = ifaceArray.size();
Ed Tanouscb13a392020-07-25 19:02:03 +00001889 if (!ec)
Sunitha Harish462023a2020-02-19 08:34:59 -06001890 {
Ed Tanouscb13a392020-07-25 19:02:03 +00001891 BMCWEB_LOG_DEBUG << "Hypervisor is available";
Ed Tanous2c70f802020-09-28 14:29:23 -07001892 ifaceArray.push_back(
Ed Tanouscb13a392020-07-25 19:02:03 +00001893 {{"@odata.id", "/redfish/v1/Systems/hypervisor"}});
Ed Tanous2c70f802020-09-28 14:29:23 -07001894 count = ifaceArray.size();
Sunitha Harish462023a2020-02-19 08:34:59 -06001895 return;
1896 }
Sunitha Harish462023a2020-02-19 08:34:59 -06001897 },
Sunitha Harish8e651fb2020-06-17 06:06:25 -05001898 "xyz.openbmc_project.Settings",
1899 "/xyz/openbmc_project/network/hypervisor",
Sunitha Harish462023a2020-02-19 08:34:59 -06001900 "org.freedesktop.DBus.Properties", "Get",
1901 "xyz.openbmc_project.Network.SystemConfiguration", "HostName");
Ed Tanous1abe55e2018-09-05 08:30:59 -07001902 }
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02001903};
1904
1905/**
Ed Tanouscc340dd2018-08-29 13:43:38 -07001906 * SystemActionsReset class supports handle POST method for Reset action.
1907 * The class retrieves and sends data directly to D-Bus.
1908 */
1909class SystemActionsReset : public Node
1910{
1911 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001912 SystemActionsReset(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001913 Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/")
Ed Tanouscc340dd2018-08-29 13:43:38 -07001914 {
1915 entityPrivileges = {
1916 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1917 }
1918
1919 private:
1920 /**
1921 * Function handles POST method request.
1922 * Analyzes POST body message before sends Reset request data to D-Bus.
1923 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001924 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001925 const std::vector<std::string>&) override
Ed Tanouscc340dd2018-08-29 13:43:38 -07001926 {
Ed Tanous9712f8a2018-09-21 13:38:49 -07001927 auto asyncResp = std::make_shared<AsyncResp>(res);
1928
1929 std::string resetType;
1930 if (!json_util::readJson(req, res, "ResetType", resetType))
Ed Tanouscc340dd2018-08-29 13:43:38 -07001931 {
1932 return;
1933 }
1934
Jason M. Billsd22c8392019-06-03 13:59:03 -07001935 // Get the command and host vs. chassis
Ed Tanous9712f8a2018-09-21 13:38:49 -07001936 std::string command;
Jason M. Billsd22c8392019-06-03 13:59:03 -07001937 bool hostCommand;
Ed Tanousd4d25792020-09-29 15:15:03 -07001938 if ((resetType == "On") || (resetType == "ForceOn"))
Ed Tanous9712f8a2018-09-21 13:38:49 -07001939 {
1940 command = "xyz.openbmc_project.State.Host.Transition.On";
Jason M. Billsd22c8392019-06-03 13:59:03 -07001941 hostCommand = true;
1942 }
1943 else if (resetType == "ForceOff")
1944 {
1945 command = "xyz.openbmc_project.State.Chassis.Transition.Off";
1946 hostCommand = false;
1947 }
Jason M. Billsd22c8392019-06-03 13:59:03 -07001948 else if (resetType == "ForceRestart")
1949 {
Jason M. Bills86a08512020-02-04 13:15:49 -08001950 command =
1951 "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot";
1952 hostCommand = true;
Ed Tanous9712f8a2018-09-21 13:38:49 -07001953 }
1954 else if (resetType == "GracefulShutdown")
1955 {
1956 command = "xyz.openbmc_project.State.Host.Transition.Off";
Jason M. Billsd22c8392019-06-03 13:59:03 -07001957 hostCommand = true;
Ed Tanous9712f8a2018-09-21 13:38:49 -07001958 }
1959 else if (resetType == "GracefulRestart")
1960 {
Jason M. Bills86a08512020-02-04 13:15:49 -08001961 command =
1962 "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot";
Jason M. Billsd22c8392019-06-03 13:59:03 -07001963 hostCommand = true;
1964 }
1965 else if (resetType == "PowerCycle")
1966 {
Jason M. Bills86a08512020-02-04 13:15:49 -08001967 command = "xyz.openbmc_project.State.Host.Transition.Reboot";
1968 hostCommand = true;
Ed Tanous9712f8a2018-09-21 13:38:49 -07001969 }
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05001970 else if (resetType == "Nmi")
1971 {
1972 doNMI(asyncResp);
1973 return;
1974 }
Ed Tanous9712f8a2018-09-21 13:38:49 -07001975 else
1976 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001977 messages::actionParameterUnknown(res, "Reset", resetType);
Ed Tanous9712f8a2018-09-21 13:38:49 -07001978 return;
1979 }
1980
Jason M. Billsd22c8392019-06-03 13:59:03 -07001981 if (hostCommand)
1982 {
1983 crow::connections::systemBus->async_method_call(
1984 [asyncResp, resetType](const boost::system::error_code ec) {
1985 if (ec)
1986 {
1987 BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
1988 if (ec.value() == boost::asio::error::invalid_argument)
1989 {
1990 messages::actionParameterNotSupported(
1991 asyncResp->res, resetType, "Reset");
1992 }
1993 else
1994 {
1995 messages::internalError(asyncResp->res);
1996 }
1997 return;
1998 }
1999 messages::success(asyncResp->res);
2000 },
2001 "xyz.openbmc_project.State.Host",
2002 "/xyz/openbmc_project/state/host0",
2003 "org.freedesktop.DBus.Properties", "Set",
2004 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
2005 std::variant<std::string>{command});
2006 }
2007 else
2008 {
2009 crow::connections::systemBus->async_method_call(
2010 [asyncResp, resetType](const boost::system::error_code ec) {
2011 if (ec)
2012 {
2013 BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
2014 if (ec.value() == boost::asio::error::invalid_argument)
2015 {
2016 messages::actionParameterNotSupported(
2017 asyncResp->res, resetType, "Reset");
2018 }
2019 else
2020 {
2021 messages::internalError(asyncResp->res);
2022 }
2023 return;
2024 }
2025 messages::success(asyncResp->res);
2026 },
2027 "xyz.openbmc_project.State.Chassis",
2028 "/xyz/openbmc_project/state/chassis0",
2029 "org.freedesktop.DBus.Properties", "Set",
2030 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
2031 std::variant<std::string>{command});
2032 }
Ed Tanouscc340dd2018-08-29 13:43:38 -07002033 }
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002034 /**
2035 * Function transceives data with dbus directly.
2036 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002037 void doNMI(const std::shared_ptr<AsyncResp>& asyncResp)
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002038 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002039 constexpr char const* serviceName =
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002040 "xyz.openbmc_project.Control.Host.NMI";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002041 constexpr char const* objectPath =
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002042 "/xyz/openbmc_project/control/host0/nmi";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002043 constexpr char const* interfaceName =
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002044 "xyz.openbmc_project.Control.Host.NMI";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002045 constexpr char const* method = "NMI";
Lakshminarayana R. Kammathbfd5b822019-06-17 12:11:01 -05002046
2047 crow::connections::systemBus->async_method_call(
2048 [asyncResp](const boost::system::error_code ec) {
2049 if (ec)
2050 {
2051 BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec;
2052 messages::internalError(asyncResp->res);
2053 return;
2054 }
2055 messages::success(asyncResp->res);
2056 },
2057 serviceName, objectPath, interfaceName, method);
2058 }
Ed Tanouscc340dd2018-08-29 13:43:38 -07002059};
2060
2061/**
Ed Tanous66173382018-08-15 18:20:59 -07002062 * Systems derived class for delivering Computer Systems Schema.
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002063 */
Ed Tanous1abe55e2018-09-05 08:30:59 -07002064class Systems : public Node
2065{
2066 public:
2067 /*
2068 * Default Constructor
2069 */
Ed Tanous52cc1122020-07-18 13:51:21 -07002070 Systems(App& app) : Node(app, "/redfish/v1/Systems/system/")
Ed Tanous1abe55e2018-09-05 08:30:59 -07002071 {
Ed Tanous1abe55e2018-09-05 08:30:59 -07002072 entityPrivileges = {
2073 {boost::beast::http::verb::get, {{"Login"}}},
2074 {boost::beast::http::verb::head, {{"Login"}}},
2075 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2076 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2077 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2078 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002079 }
2080
Ed Tanous1abe55e2018-09-05 08:30:59 -07002081 private:
Ed Tanous1abe55e2018-09-05 08:30:59 -07002082 /**
2083 * Functions triggers appropriate requests on DBus
2084 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002085 void doGet(crow::Response& res, const crow::Request&,
2086 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -07002087 {
Gunnar Mills9f8bfa72020-09-28 13:45:19 -05002088 res.jsonValue["@odata.type"] = "#ComputerSystem.v1_13_0.ComputerSystem";
Gunnar Mills450a25c2020-04-14 21:34:07 -05002089 res.jsonValue["Name"] = "system";
Ed Tanous029573d2019-02-01 10:57:49 -08002090 res.jsonValue["Id"] = "system";
Ed Tanous0f74e642018-11-12 15:17:05 -08002091 res.jsonValue["SystemType"] = "Physical";
2092 res.jsonValue["Description"] = "Computer System";
Ed Tanous0f74e642018-11-12 15:17:05 -08002093 res.jsonValue["ProcessorSummary"]["Count"] = 0;
2094 res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled";
Cheng C Yang5fd7ba62019-11-28 15:58:08 +08002095 res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0);
Ed Tanous0f74e642018-11-12 15:17:05 -08002096 res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled";
Ed Tanous029573d2019-02-01 10:57:49 -08002097 res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system";
Ed Tanous04a258f2018-10-15 08:00:41 -07002098
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02002099 res.jsonValue["Processors"] = {
Ed Tanous029573d2019-02-01 10:57:49 -08002100 {"@odata.id", "/redfish/v1/Systems/system/Processors"}};
Rapkiewicz, Pawel443c2932018-10-22 15:08:49 +02002101 res.jsonValue["Memory"] = {
Ed Tanous029573d2019-02-01 10:57:49 -08002102 {"@odata.id", "/redfish/v1/Systems/system/Memory"}};
Nikhil Potadea25aecc2019-08-23 16:35:26 -07002103 res.jsonValue["Storage"] = {
2104 {"@odata.id", "/redfish/v1/Systems/system/Storage"}};
Ed Tanous029573d2019-02-01 10:57:49 -08002105
Ed Tanouscc340dd2018-08-29 13:43:38 -07002106 res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
2107 {"target",
Ed Tanous029573d2019-02-01 10:57:49 -08002108 "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"},
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05302109 {"@Redfish.ActionInfo",
2110 "/redfish/v1/Systems/system/ResetActionInfo"}};
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002111
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002112 res.jsonValue["LogServices"] = {
Ed Tanous029573d2019-02-01 10:57:49 -08002113 {"@odata.id", "/redfish/v1/Systems/system/LogServices"}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002114
Carol Wangd82a3ac2019-11-21 13:56:38 +08002115 res.jsonValue["Bios"] = {
2116 {"@odata.id", "/redfish/v1/Systems/system/Bios"}};
2117
Jennifer Leec5d03ff2019-03-08 15:42:58 -08002118 res.jsonValue["Links"]["ManagedBy"] = {
2119 {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
2120
2121 res.jsonValue["Status"] = {
2122 {"Health", "OK"},
2123 {"State", "Enabled"},
2124 };
Ed Tanousa0803ef2018-08-29 13:29:23 -07002125 auto asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -07002126
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002127 constexpr const std::array<const char*, 4> inventoryForSystems = {
James Feistb49ac872019-05-21 15:12:01 -07002128 "xyz.openbmc_project.Inventory.Item.Dimm",
James Feist2ad9c2f2019-10-29 16:26:48 -07002129 "xyz.openbmc_project.Inventory.Item.Cpu",
James Feiste284a7c2019-11-20 16:20:23 -08002130 "xyz.openbmc_project.Inventory.Item.Drive",
2131 "xyz.openbmc_project.Inventory.Item.StorageController"};
James Feistb49ac872019-05-21 15:12:01 -07002132
2133 auto health = std::make_shared<HealthPopulate>(asyncResp);
2134 crow::connections::systemBus->async_method_call(
2135 [health](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002136 std::vector<std::string>& resp) {
James Feistb49ac872019-05-21 15:12:01 -07002137 if (ec)
2138 {
2139 // no inventory
2140 return;
2141 }
2142
2143 health->inventory = std::move(resp);
2144 },
2145 "xyz.openbmc_project.ObjectMapper",
2146 "/xyz/openbmc_project/object_mapper",
2147 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/",
2148 int32_t(0), inventoryForSystems);
2149
2150 health->populate();
2151
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002152 getMainChassisId(asyncResp, [](const std::string& chassisId,
Ed Tanousb5a76932020-09-29 16:16:58 -07002153 const std::shared_ptr<AsyncResp>& aRsp) {
Jennifer Leec5d03ff2019-03-08 15:42:58 -08002154 aRsp->res.jsonValue["Links"]["Chassis"] = {
2155 {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
2156 });
AppaRao Pulia3002222019-11-12 21:32:59 +05302157
Gunnar Mills9f8bfa72020-09-28 13:45:19 -05002158 getLocationIndicatorActive(asyncResp);
2159 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
AppaRao Pulia3002222019-11-12 21:32:59 +05302160 getIndicatorLedState(asyncResp);
James Feist5bc2dc82019-10-22 14:33:16 -07002161 getComputerSystem(asyncResp, health);
Ed Tanous6c34de42018-08-29 13:37:36 -07002162 getHostState(asyncResp);
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302163 getBootProperties(asyncResp);
Andrew Geissler978b8802020-11-19 13:36:40 -06002164 getBootProgress(asyncResp);
Jason M. Billsadbe1922019-10-14 15:44:35 -07002165 getPCIeDeviceList(asyncResp, "PCIeDevices");
Yong Li51709ff2019-09-30 14:13:04 +08002166 getHostWatchdogTimer(asyncResp);
George Liuc6a620f2020-04-10 17:18:11 +08002167 getPowerRestorePolicy(asyncResp);
Gunnar Mills6bd5a8d2020-05-16 18:49:33 -05002168 getAutomaticRetry(asyncResp);
Gunnar Millsc0557e12020-06-30 11:26:20 -05002169 getLastResetTime(asyncResp);
AppaRao Pulia6349912019-10-18 17:16:08 +05302170#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
2171 getProvisioningStatus(asyncResp);
2172#endif
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002173 }
2174
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002175 void doPatch(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002176 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -07002177 {
Gunnar Mills9f8bfa72020-09-28 13:45:19 -05002178 std::optional<bool> locationIndicatorActive;
Santosh Puranikcde19e52019-02-20 00:10:56 +05302179 std::optional<std::string> indicatorLed;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302180 std::optional<nlohmann::json> bootProps;
Yong Lic45f0082019-10-10 14:19:01 +08002181 std::optional<nlohmann::json> wdtTimerProps;
Gunnar Mills98e386e2020-10-30 14:58:09 -05002182 std::optional<std::string> assetTag;
George Liuc6a620f2020-04-10 17:18:11 +08002183 std::optional<std::string> powerRestorePolicy;
Santosh Puranik41352c22019-07-03 05:35:49 -05002184 auto asyncResp = std::make_shared<AsyncResp>(res);
2185
Gunnar Mills9f8bfa72020-09-28 13:45:19 -05002186 if (!json_util::readJson(
2187 req, res, "IndicatorLED", indicatorLed,
2188 "LocationIndicatorActive", locationIndicatorActive, "Boot",
2189 bootProps, "WatchdogTimer", wdtTimerProps, "PowerRestorePolicy",
2190 powerRestorePolicy, "AssetTag", assetTag))
Ed Tanous66173382018-08-15 18:20:59 -07002191 {
Ed Tanous9712f8a2018-09-21 13:38:49 -07002192 return;
2193 }
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302194
Johnathan Mantey944ffaf2019-08-12 16:16:14 -07002195 res.result(boost::beast::http::status::no_content);
Yong Lic45f0082019-10-10 14:19:01 +08002196
Gunnar Mills98e386e2020-10-30 14:58:09 -05002197 if (assetTag)
2198 {
2199 setAssetTag(asyncResp, *assetTag);
2200 }
2201
Yong Lic45f0082019-10-10 14:19:01 +08002202 if (wdtTimerProps)
2203 {
2204 std::optional<bool> wdtEnable;
2205 std::optional<std::string> wdtTimeOutAction;
2206
2207 if (!json_util::readJson(*wdtTimerProps, asyncResp->res,
2208 "FunctionEnabled", wdtEnable,
2209 "TimeoutAction", wdtTimeOutAction))
2210 {
2211 return;
2212 }
Ed Tanousf23b7292020-10-15 09:41:17 -07002213 setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction);
Yong Lic45f0082019-10-10 14:19:01 +08002214 }
2215
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302216 if (bootProps)
2217 {
2218 std::optional<std::string> bootSource;
2219 std::optional<std::string> bootEnable;
Gunnar Mills69f35302020-05-17 16:06:31 -05002220 std::optional<std::string> automaticRetryConfig;
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302221
Gunnar Mills69f35302020-05-17 16:06:31 -05002222 if (!json_util::readJson(
2223 *bootProps, asyncResp->res, "BootSourceOverrideTarget",
2224 bootSource, "BootSourceOverrideEnabled", bootEnable,
2225 "AutomaticRetryConfig", automaticRetryConfig))
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302226 {
2227 return;
2228 }
Gunnar Mills69f35302020-05-17 16:06:31 -05002229 if (bootSource || bootEnable)
2230 {
2231 setBootSourceProperties(asyncResp, std::move(bootSource),
2232 std::move(bootEnable));
2233 }
2234 if (automaticRetryConfig)
2235 {
Ed Tanousf23b7292020-10-15 09:41:17 -07002236 setAutomaticRetry(asyncResp, *automaticRetryConfig);
Gunnar Mills69f35302020-05-17 16:06:31 -05002237 }
Santosh Puranik491d8ee2019-02-06 19:46:56 +05302238 }
Johnathan Mantey265c1602019-08-08 11:02:51 -07002239
Gunnar Mills9f8bfa72020-09-28 13:45:19 -05002240 if (locationIndicatorActive)
2241 {
2242 setLocationIndicatorActive(asyncResp, *locationIndicatorActive);
2243 }
2244
2245 // TODO (Gunnar): Remove IndicatorLED after enough time has passed
Ed Tanous9712f8a2018-09-21 13:38:49 -07002246 if (indicatorLed)
2247 {
Ed Tanousf23b7292020-10-15 09:41:17 -07002248 setIndicatorLedState(asyncResp, *indicatorLed);
Gunnar Millsd6aa0092020-11-25 14:17:37 -06002249 res.addHeader(boost::beast::http::field::warning,
2250 "299 - \"IndicatorLED is deprecated. Use "
2251 "LocationIndicatorActive instead.\"");
Ed Tanous1abe55e2018-09-05 08:30:59 -07002252 }
George Liuc6a620f2020-04-10 17:18:11 +08002253
2254 if (powerRestorePolicy)
2255 {
Gunnar Mills4e69c902021-01-05 19:50:11 -06002256 setPowerRestorePolicy(asyncResp, *powerRestorePolicy);
George Liuc6a620f2020-04-10 17:18:11 +08002257 }
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002258 }
Lewanczyk, Dawidc5b2abe2018-05-30 16:59:42 +02002259};
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05302260
2261/**
2262 * SystemResetActionInfo derived class for delivering Computer Systems
2263 * ResetType AllowableValues using ResetInfo schema.
2264 */
2265class SystemResetActionInfo : public Node
2266{
2267 public:
2268 /*
2269 * Default Constructor
2270 */
Ed Tanous52cc1122020-07-18 13:51:21 -07002271 SystemResetActionInfo(App& app) :
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05302272 Node(app, "/redfish/v1/Systems/system/ResetActionInfo/")
2273 {
2274 entityPrivileges = {
2275 {boost::beast::http::verb::get, {{"Login"}}},
2276 {boost::beast::http::verb::head, {{"Login"}}},
2277 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2278 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2279 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2280 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2281 }
2282
2283 private:
2284 /**
2285 * Functions triggers appropriate requests on DBus
2286 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002287 void doGet(crow::Response& res, const crow::Request&,
2288 const std::vector<std::string>&) override
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05302289 {
2290 res.jsonValue = {
2291 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
2292 {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"},
2293 {"Name", "Reset Action Info"},
2294 {"Id", "ResetActionInfo"},
2295 {"Parameters",
2296 {{{"Name", "ResetType"},
2297 {"Required", true},
2298 {"DataType", "String"},
2299 {"AllowableValues",
2300 {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart",
2301 "GracefulShutdown", "PowerCycle", "Nmi"}}}}}};
2302 res.end();
2303 }
2304};
Ed Tanous1abe55e2018-09-05 08:30:59 -07002305} // namespace redfish