blob: 376f70c52b69d9093eded6fbbbc9ac1dd4600c8d [file] [log] [blame]
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001/*
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
Sui Chena51fc2d2022-07-14 17:21:53 -070018#include "app.hpp"
19#include "dbus_utility.hpp"
James Feistb49ac872019-05-21 15:12:01 -070020#include "health.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070021#include "query.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080022#include "redfish_util.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070023#include "registries/privilege_registry.hpp"
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020024#include "utils/dbus_utils.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080025#include "utils/json_utils.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070026#include "utils/sw_utils.hpp"
27#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070028#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010029
George Liue99073f2022-12-09 11:06:16 +080030#include <boost/system/error_code.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020031#include <sdbusplus/asio/property.hpp>
32#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050033
Ed Tanousa170f272022-06-30 21:53:27 -070034#include <algorithm>
George Liue99073f2022-12-09 11:06:16 +080035#include <array>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050036#include <cstdint>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050037#include <memory>
38#include <sstream>
George Liue99073f2022-12-09 11:06:16 +080039#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080040#include <variant>
James Feist5b4aa862018-08-16 14:07:01 -070041
Ed Tanous1abe55e2018-09-05 08:30:59 -070042namespace redfish
43{
Jennifer Leeed5befb2018-08-10 11:29:45 -070044
45/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050046 * Function reboots the BMC.
47 *
48 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070049 */
zhanghch058d1b46d2021-04-01 11:18:24 +080050inline void
51 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050052{
53 const char* processName = "xyz.openbmc_project.State.BMC";
54 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
55 const char* interfaceName = "xyz.openbmc_project.State.BMC";
56 const std::string& propertyValue =
57 "xyz.openbmc_project.State.BMC.Transition.Reboot";
58 const char* destProperty = "RequestedBMCTransition";
59
60 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080061 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050062
63 crow::connections::systemBus->async_method_call(
64 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070065 // Use "Set" method to set the property value.
66 if (ec)
67 {
68 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
69 messages::internalError(asyncResp->res);
70 return;
71 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -050072
Ed Tanous002d39b2022-05-31 08:59:27 -070073 messages::success(asyncResp->res);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050074 },
75 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
76 interfaceName, destProperty, dbusPropertyValue);
77}
78
zhanghch058d1b46d2021-04-01 11:18:24 +080079inline void
80 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000081{
82 const char* processName = "xyz.openbmc_project.State.BMC";
83 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
84 const char* interfaceName = "xyz.openbmc_project.State.BMC";
85 const std::string& propertyValue =
86 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
87 const char* destProperty = "RequestedBMCTransition";
88
89 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080090 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000091
92 crow::connections::systemBus->async_method_call(
93 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070094 // Use "Set" method to set the property value.
95 if (ec)
96 {
97 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
98 messages::internalError(asyncResp->res);
99 return;
100 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000101
Ed Tanous002d39b2022-05-31 08:59:27 -0700102 messages::success(asyncResp->res);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000103 },
104 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
105 interfaceName, destProperty, dbusPropertyValue);
106}
107
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500108/**
109 * ManagerResetAction class supports the POST method for the Reset (reboot)
110 * action.
111 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700112inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700113{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700114 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700115 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500116 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000117 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700118 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700119
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700120 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700121 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700122 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700123 [&app](const crow::Request& req,
124 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000125 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700126 {
127 return;
128 }
129 BMCWEB_LOG_DEBUG << "Post Manager Reset.";
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500130
Ed Tanous002d39b2022-05-31 08:59:27 -0700131 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700132
Ed Tanous002d39b2022-05-31 08:59:27 -0700133 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
134 resetType))
135 {
136 return;
137 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500138
Ed Tanous002d39b2022-05-31 08:59:27 -0700139 if (resetType == "GracefulRestart")
140 {
141 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
142 doBMCGracefulRestart(asyncResp);
143 return;
144 }
145 if (resetType == "ForceRestart")
146 {
147 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
148 doBMCForceRestart(asyncResp);
149 return;
150 }
151 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
152 << resetType;
153 messages::actionParameterNotSupported(asyncResp->res, resetType,
154 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700155
Ed Tanous002d39b2022-05-31 08:59:27 -0700156 return;
157 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700158}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700159
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500160/**
161 * ManagerResetToDefaultsAction class supports POST method for factory reset
162 * action.
163 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700164inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500165{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500166
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500167 /**
168 * Function handles ResetToDefaults POST method request.
169 *
170 * Analyzes POST body message and factory resets BMC by calling
171 * BMC code updater factory reset followed by a BMC reboot.
172 *
173 * BMC code updater factory reset wipes the whole BMC read-write
174 * filesystem which includes things like the network settings.
175 *
176 * OpenBMC only supports ResetToDefaultsType "ResetAll".
177 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500178
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700179 BMCWEB_ROUTE(app,
180 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700181 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700182 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700183 [&app](const crow::Request& req,
184 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000185 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700186 {
187 return;
188 }
189 BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500190
Ed Tanous002d39b2022-05-31 08:59:27 -0700191 std::string resetType;
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500192
Ed Tanous002d39b2022-05-31 08:59:27 -0700193 if (!json_util::readJsonAction(req, asyncResp->res,
194 "ResetToDefaultsType", resetType))
195 {
196 BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700197
Ed Tanous002d39b2022-05-31 08:59:27 -0700198 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
199 "ResetToDefaultsType");
200 return;
201 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700202
Ed Tanous002d39b2022-05-31 08:59:27 -0700203 if (resetType != "ResetAll")
204 {
205 BMCWEB_LOG_DEBUG
206 << "Invalid property value for ResetToDefaultsType: "
207 << resetType;
208 messages::actionParameterNotSupported(asyncResp->res, resetType,
209 "ResetToDefaultsType");
210 return;
211 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700212
Ed Tanous002d39b2022-05-31 08:59:27 -0700213 crow::connections::systemBus->async_method_call(
214 [asyncResp](const boost::system::error_code ec) {
215 if (ec)
216 {
217 BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec;
218 messages::internalError(asyncResp->res);
219 return;
220 }
221 // Factory Reset doesn't actually happen until a reboot
222 // Can't erase what the BMC is running on
223 doBMCGracefulRestart(asyncResp);
224 },
225 "xyz.openbmc_project.Software.BMC.Updater",
226 "/xyz/openbmc_project/software",
227 "xyz.openbmc_project.Common.FactoryReset", "Reset");
228 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700229}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500230
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530231/**
232 * ManagerResetActionInfo derived class for delivering Manager
233 * ResetType AllowableValues using ResetInfo schema.
234 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700235inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530236{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530237 /**
238 * Functions triggers appropriate requests on DBus
239 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700240
241 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700242 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700243 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700244 [&app](const crow::Request& req,
245 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000246 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700247 {
248 return;
249 }
Ed Tanous14766872022-03-15 10:44:42 -0700250
Ed Tanous002d39b2022-05-31 08:59:27 -0700251 asyncResp->res.jsonValue["@odata.type"] =
252 "#ActionInfo.v1_1_2.ActionInfo";
253 asyncResp->res.jsonValue["@odata.id"] =
254 "/redfish/v1/Managers/bmc/ResetActionInfo";
255 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
256 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
257 nlohmann::json::object_t parameter;
258 parameter["Name"] = "ResetType";
259 parameter["Required"] = true;
260 parameter["DataType"] = "String";
Ed Tanous14766872022-03-15 10:44:42 -0700261
Ed Tanous002d39b2022-05-31 08:59:27 -0700262 nlohmann::json::array_t allowableValues;
263 allowableValues.push_back("GracefulRestart");
264 allowableValues.push_back("ForceRestart");
265 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700266
Ed Tanous002d39b2022-05-31 08:59:27 -0700267 nlohmann::json::array_t parameters;
268 parameters.push_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700269
Ed Tanous002d39b2022-05-31 08:59:27 -0700270 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
271 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700272}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530273
James Feist5b4aa862018-08-16 14:07:01 -0700274static constexpr const char* objectManagerIface =
275 "org.freedesktop.DBus.ObjectManager";
276static constexpr const char* pidConfigurationIface =
277 "xyz.openbmc_project.Configuration.Pid";
278static constexpr const char* pidZoneConfigurationIface =
279 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feistb7a08d02018-12-11 14:55:37 -0800280static constexpr const char* stepwiseConfigurationIface =
281 "xyz.openbmc_project.Configuration.Stepwise";
James Feist73df0db2019-03-25 15:29:35 -0700282static constexpr const char* thermalModeIface =
283 "xyz.openbmc_project.Control.ThermalMode";
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100284
zhanghch058d1b46d2021-04-01 11:18:24 +0800285inline void
286 asyncPopulatePid(const std::string& connection, const std::string& path,
287 const std::string& currentProfile,
288 const std::vector<std::string>& supportedProfiles,
289 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist5b4aa862018-08-16 14:07:01 -0700290{
291
292 crow::connections::systemBus->async_method_call(
James Feist73df0db2019-03-25 15:29:35 -0700293 [asyncResp, currentProfile, supportedProfiles](
294 const boost::system::error_code ec,
295 const dbus::utility::ManagedObjectType& managedObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700296 if (ec)
297 {
298 BMCWEB_LOG_ERROR << ec;
299 asyncResp->res.jsonValue.clear();
300 messages::internalError(asyncResp->res);
301 return;
302 }
303 nlohmann::json& configRoot =
304 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"];
305 nlohmann::json& fans = configRoot["FanControllers"];
306 fans["@odata.type"] = "#OemManager.FanControllers";
307 fans["@odata.id"] =
308 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers";
309
310 nlohmann::json& pids = configRoot["PidControllers"];
311 pids["@odata.type"] = "#OemManager.PidControllers";
312 pids["@odata.id"] =
313 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers";
314
315 nlohmann::json& stepwise = configRoot["StepwiseControllers"];
316 stepwise["@odata.type"] = "#OemManager.StepwiseControllers";
317 stepwise["@odata.id"] =
318 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers";
319
320 nlohmann::json& zones = configRoot["FanZones"];
321 zones["@odata.id"] =
322 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones";
323 zones["@odata.type"] = "#OemManager.FanZones";
324 configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan";
325 configRoot["@odata.type"] = "#OemManager.Fan";
326 configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles;
327
328 if (!currentProfile.empty())
329 {
330 configRoot["Profile"] = currentProfile;
331 }
332 BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !";
333
334 for (const auto& pathPair : managedObj)
335 {
336 for (const auto& intfPair : pathPair.second)
James Feist5b4aa862018-08-16 14:07:01 -0700337 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700338 if (intfPair.first != pidConfigurationIface &&
339 intfPair.first != pidZoneConfigurationIface &&
340 intfPair.first != stepwiseConfigurationIface)
James Feist5b4aa862018-08-16 14:07:01 -0700341 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700342 continue;
343 }
James Feist73df0db2019-03-25 15:29:35 -0700344
Ed Tanous002d39b2022-05-31 08:59:27 -0700345 std::string name;
James Feist73df0db2019-03-25 15:29:35 -0700346
Ed Tanous002d39b2022-05-31 08:59:27 -0700347 for (const std::pair<std::string,
348 dbus::utility::DbusVariantType>& propPair :
349 intfPair.second)
350 {
351 if (propPair.first == "Name")
James Feist73df0db2019-03-25 15:29:35 -0700352 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700353 const std::string* namePtr =
354 std::get_if<std::string>(&propPair.second);
355 if (namePtr == nullptr)
James Feist73df0db2019-03-25 15:29:35 -0700356 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700357 BMCWEB_LOG_ERROR << "Pid Name Field illegal";
James Feistc33a90e2019-03-01 10:17:44 -0800358 messages::internalError(asyncResp->res);
359 return;
360 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700361 name = *namePtr;
362 dbus::utility::escapePathForDbus(name);
James Feistb7a08d02018-12-11 14:55:37 -0800363 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700364 else if (propPair.first == "Profiles")
James Feistb7a08d02018-12-11 14:55:37 -0800365 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700366 const std::vector<std::string>* profiles =
367 std::get_if<std::vector<std::string>>(
368 &propPair.second);
369 if (profiles == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800370 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700371 BMCWEB_LOG_ERROR << "Pid Profiles Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800372 messages::internalError(asyncResp->res);
373 return;
374 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700375 if (std::find(profiles->begin(), profiles->end(),
376 currentProfile) == profiles->end())
James Feistb7a08d02018-12-11 14:55:37 -0800377 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700378 BMCWEB_LOG_INFO
379 << name << " not supported in current profile";
380 continue;
James Feistb7a08d02018-12-11 14:55:37 -0800381 }
382 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700383 }
384 nlohmann::json* config = nullptr;
385 const std::string* classPtr = nullptr;
386
387 for (const std::pair<std::string,
388 dbus::utility::DbusVariantType>& propPair :
389 intfPair.second)
390 {
391 if (propPair.first == "Class")
James Feistb7a08d02018-12-11 14:55:37 -0800392 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700393 classPtr = std::get_if<std::string>(&propPair.second);
394 }
395 }
396
397 if (intfPair.first == pidZoneConfigurationIface)
398 {
399 std::string chassis;
400 if (!dbus::utility::getNthStringFromPath(pathPair.first.str,
401 5, chassis))
402 {
403 chassis = "#IllegalValue";
404 }
405 nlohmann::json& zone = zones[name];
Ed Tanous613dabe2022-07-09 11:17:36 -0700406 zone["Chassis"]["@odata.id"] =
407 "/redfish/v1/Chassis/" + chassis;
Ed Tanous002d39b2022-05-31 08:59:27 -0700408 zone["@odata.id"] =
409 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
410 name;
411 zone["@odata.type"] = "#OemManager.FanZone";
412 config = &zone;
413 }
414
415 else if (intfPair.first == stepwiseConfigurationIface)
416 {
417 if (classPtr == nullptr)
418 {
419 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800420 messages::internalError(asyncResp->res);
421 return;
422 }
423
Ed Tanous002d39b2022-05-31 08:59:27 -0700424 nlohmann::json& controller = stepwise[name];
425 config = &controller;
James Feistb7a08d02018-12-11 14:55:37 -0800426
Ed Tanous002d39b2022-05-31 08:59:27 -0700427 controller["@odata.id"] =
428 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/" +
429 name;
430 controller["@odata.type"] =
431 "#OemManager.StepwiseController";
432
433 controller["Direction"] = *classPtr;
434 }
435
436 // pid and fans are off the same configuration
437 else if (intfPair.first == pidConfigurationIface)
438 {
439
440 if (classPtr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700441 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700442 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
443 messages::internalError(asyncResp->res);
444 return;
445 }
446 bool isFan = *classPtr == "fan";
447 nlohmann::json& element = isFan ? fans[name] : pids[name];
448 config = &element;
449 if (isFan)
450 {
451 element["@odata.id"] =
452 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/" +
453 name;
454 element["@odata.type"] = "#OemManager.FanController";
455 }
456 else
457 {
458 element["@odata.id"] =
459 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers/" +
460 name;
461 element["@odata.type"] = "#OemManager.PidController";
462 }
463 }
464 else
465 {
466 BMCWEB_LOG_ERROR << "Unexpected configuration";
467 messages::internalError(asyncResp->res);
468 return;
469 }
James Feist5b4aa862018-08-16 14:07:01 -0700470
Ed Tanous002d39b2022-05-31 08:59:27 -0700471 // used for making maps out of 2 vectors
472 const std::vector<double>* keys = nullptr;
473 const std::vector<double>* values = nullptr;
474
475 for (const auto& propertyPair : intfPair.second)
476 {
477 if (propertyPair.first == "Type" ||
478 propertyPair.first == "Class" ||
479 propertyPair.first == "Name")
480 {
481 continue;
482 }
483
484 // zones
485 if (intfPair.first == pidZoneConfigurationIface)
486 {
487 const double* ptr =
488 std::get_if<double>(&propertyPair.second);
489 if (ptr == nullptr)
490 {
491 BMCWEB_LOG_ERROR << "Field Illegal "
492 << propertyPair.first;
493 messages::internalError(asyncResp->res);
494 return;
495 }
496 (*config)[propertyPair.first] = *ptr;
497 }
498
499 if (intfPair.first == stepwiseConfigurationIface)
500 {
501 if (propertyPair.first == "Reading" ||
502 propertyPair.first == "Output")
503 {
504 const std::vector<double>* ptr =
505 std::get_if<std::vector<double>>(
506 &propertyPair.second);
507
508 if (ptr == nullptr)
509 {
510 BMCWEB_LOG_ERROR << "Field Illegal "
511 << propertyPair.first;
512 messages::internalError(asyncResp->res);
513 return;
514 }
515
516 if (propertyPair.first == "Reading")
517 {
518 keys = ptr;
519 }
520 else
521 {
522 values = ptr;
523 }
524 if (keys != nullptr && values != nullptr)
525 {
526 if (keys->size() != values->size())
527 {
528 BMCWEB_LOG_ERROR
529 << "Reading and Output size don't match ";
530 messages::internalError(asyncResp->res);
531 return;
532 }
533 nlohmann::json& steps = (*config)["Steps"];
534 steps = nlohmann::json::array();
535 for (size_t ii = 0; ii < keys->size(); ii++)
536 {
537 nlohmann::json::object_t step;
538 step["Target"] = (*keys)[ii];
539 step["Output"] = (*values)[ii];
540 steps.push_back(std::move(step));
541 }
542 }
543 }
544 if (propertyPair.first == "NegativeHysteresis" ||
545 propertyPair.first == "PositiveHysteresis")
James Feist5b4aa862018-08-16 14:07:01 -0700546 {
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800547 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800548 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700549 if (ptr == nullptr)
550 {
551 BMCWEB_LOG_ERROR << "Field Illegal "
552 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700553 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700554 return;
555 }
James Feistb7a08d02018-12-11 14:55:37 -0800556 (*config)[propertyPair.first] = *ptr;
557 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700558 }
James Feistb7a08d02018-12-11 14:55:37 -0800559
Ed Tanous002d39b2022-05-31 08:59:27 -0700560 // pid and fans are off the same configuration
561 if (intfPair.first == pidConfigurationIface ||
562 intfPair.first == stepwiseConfigurationIface)
563 {
564
565 if (propertyPair.first == "Zones")
James Feistb7a08d02018-12-11 14:55:37 -0800566 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700567 const std::vector<std::string>* inputs =
568 std::get_if<std::vector<std::string>>(
569 &propertyPair.second);
570
571 if (inputs == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800572 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700573 BMCWEB_LOG_ERROR << "Zones Pid Field Illegal";
574 messages::internalError(asyncResp->res);
575 return;
James Feistb7a08d02018-12-11 14:55:37 -0800576 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700577 auto& data = (*config)[propertyPair.first];
578 data = nlohmann::json::array();
579 for (std::string itemCopy : *inputs)
James Feistb7a08d02018-12-11 14:55:37 -0800580 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700581 dbus::utility::escapePathForDbus(itemCopy);
582 nlohmann::json::object_t input;
583 input["@odata.id"] =
584 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
585 itemCopy;
586 data.push_back(std::move(input));
James Feistb7a08d02018-12-11 14:55:37 -0800587 }
James Feist5b4aa862018-08-16 14:07:01 -0700588 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700589 // todo(james): may never happen, but this
590 // assumes configuration data referenced in the
591 // PID config is provided by the same daemon, we
592 // could add another loop to cover all cases,
593 // but I'm okay kicking this can down the road a
594 // bit
James Feist5b4aa862018-08-16 14:07:01 -0700595
Ed Tanous002d39b2022-05-31 08:59:27 -0700596 else if (propertyPair.first == "Inputs" ||
597 propertyPair.first == "Outputs")
James Feist5b4aa862018-08-16 14:07:01 -0700598 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700599 auto& data = (*config)[propertyPair.first];
600 const std::vector<std::string>* inputs =
601 std::get_if<std::vector<std::string>>(
602 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700603
Ed Tanous002d39b2022-05-31 08:59:27 -0700604 if (inputs == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700605 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700606 BMCWEB_LOG_ERROR << "Field Illegal "
607 << propertyPair.first;
608 messages::internalError(asyncResp->res);
609 return;
James Feist5b4aa862018-08-16 14:07:01 -0700610 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700611 data = *inputs;
612 }
613 else if (propertyPair.first == "SetPointOffset")
614 {
615 const std::string* ptr =
616 std::get_if<std::string>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700617
Ed Tanous002d39b2022-05-31 08:59:27 -0700618 if (ptr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700619 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700620 BMCWEB_LOG_ERROR << "Field Illegal "
621 << propertyPair.first;
622 messages::internalError(asyncResp->res);
623 return;
James Feistb943aae2019-07-11 16:33:56 -0700624 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700625 // translate from dbus to redfish
626 if (*ptr == "WarningHigh")
James Feistb943aae2019-07-11 16:33:56 -0700627 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700628 (*config)["SetPointOffset"] =
629 "UpperThresholdNonCritical";
James Feistb943aae2019-07-11 16:33:56 -0700630 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700631 else if (*ptr == "WarningLow")
James Feist5b4aa862018-08-16 14:07:01 -0700632 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700633 (*config)["SetPointOffset"] =
634 "LowerThresholdNonCritical";
James Feist5b4aa862018-08-16 14:07:01 -0700635 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700636 else if (*ptr == "CriticalHigh")
637 {
638 (*config)["SetPointOffset"] =
639 "UpperThresholdCritical";
640 }
641 else if (*ptr == "CriticalLow")
642 {
643 (*config)["SetPointOffset"] =
644 "LowerThresholdCritical";
645 }
646 else
647 {
648 BMCWEB_LOG_ERROR << "Value Illegal " << *ptr;
649 messages::internalError(asyncResp->res);
650 return;
651 }
652 }
653 // doubles
654 else if (propertyPair.first == "FFGainCoefficient" ||
655 propertyPair.first == "FFOffCoefficient" ||
656 propertyPair.first == "ICoefficient" ||
657 propertyPair.first == "ILimitMax" ||
658 propertyPair.first == "ILimitMin" ||
659 propertyPair.first == "PositiveHysteresis" ||
660 propertyPair.first == "NegativeHysteresis" ||
661 propertyPair.first == "OutLimitMax" ||
662 propertyPair.first == "OutLimitMin" ||
663 propertyPair.first == "PCoefficient" ||
664 propertyPair.first == "SetPoint" ||
665 propertyPair.first == "SlewNeg" ||
666 propertyPair.first == "SlewPos")
667 {
668 const double* ptr =
669 std::get_if<double>(&propertyPair.second);
670 if (ptr == nullptr)
671 {
672 BMCWEB_LOG_ERROR << "Field Illegal "
673 << propertyPair.first;
674 messages::internalError(asyncResp->res);
675 return;
676 }
677 (*config)[propertyPair.first] = *ptr;
James Feist5b4aa862018-08-16 14:07:01 -0700678 }
679 }
680 }
681 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700682 }
James Feist5b4aa862018-08-16 14:07:01 -0700683 },
684 connection, path, objectManagerIface, "GetManagedObjects");
685}
Jennifer Leeca537922018-08-10 10:07:30 -0700686
James Feist83ff9ab2018-08-31 10:18:24 -0700687enum class CreatePIDRet
688{
689 fail,
690 del,
691 patch
692};
693
zhanghch058d1b46d2021-04-01 11:18:24 +0800694inline bool
695 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response,
696 std::vector<nlohmann::json>& config,
697 std::vector<std::string>& zones)
James Feist5f2caae2018-12-12 14:08:25 -0800698{
James Feistb6baeaa2019-02-21 10:41:40 -0800699 if (config.empty())
700 {
701 BMCWEB_LOG_ERROR << "Empty Zones";
Ed Tanous1668ce62022-02-07 23:44:31 -0800702 messages::propertyValueFormatError(response->res, "[]", "Zones");
James Feistb6baeaa2019-02-21 10:41:40 -0800703 return false;
704 }
James Feist5f2caae2018-12-12 14:08:25 -0800705 for (auto& odata : config)
706 {
707 std::string path;
708 if (!redfish::json_util::readJson(odata, response->res, "@odata.id",
709 path))
710 {
711 return false;
712 }
713 std::string input;
James Feist61adbda2019-03-25 13:03:51 -0700714
715 // 8 below comes from
716 // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left
717 // 0 1 2 3 4 5 6 7 8
718 if (!dbus::utility::getNthStringFromPath(path, 8, input))
James Feist5f2caae2018-12-12 14:08:25 -0800719 {
720 BMCWEB_LOG_ERROR << "Got invalid path " << path;
721 BMCWEB_LOG_ERROR << "Illegal Type Zones";
722 messages::propertyValueFormatError(response->res, odata.dump(),
723 "Zones");
724 return false;
725 }
Ed Tanousa170f272022-06-30 21:53:27 -0700726 std::replace(input.begin(), input.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -0800727 zones.emplace_back(std::move(input));
728 }
729 return true;
730}
731
Ed Tanous711ac7a2021-12-20 09:34:41 -0800732inline const dbus::utility::ManagedObjectType::value_type*
James Feist73df0db2019-03-25 15:29:35 -0700733 findChassis(const dbus::utility::ManagedObjectType& managedObj,
734 const std::string& value, std::string& chassis)
James Feistb6baeaa2019-02-21 10:41:40 -0800735{
736 BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n";
737
Ed Tanousa170f272022-06-30 21:53:27 -0700738 std::string escaped = value;
739 std::replace(escaped.begin(), escaped.end(), '_', ' ');
James Feistb6baeaa2019-02-21 10:41:40 -0800740 escaped = "/" + escaped;
Ed Tanous002d39b2022-05-31 08:59:27 -0700741 auto it = std::find_if(managedObj.begin(), managedObj.end(),
742 [&escaped](const auto& obj) {
743 if (boost::algorithm::ends_with(obj.first.str, escaped))
744 {
745 BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n";
746 return true;
747 }
748 return false;
749 });
James Feistb6baeaa2019-02-21 10:41:40 -0800750
751 if (it == managedObj.end())
752 {
James Feist73df0db2019-03-25 15:29:35 -0700753 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800754 }
755 // 5 comes from <chassis-name> being the 5th element
756 // /xyz/openbmc_project/inventory/system/chassis/<chassis-name>
James Feist73df0db2019-03-25 15:29:35 -0700757 if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis))
758 {
759 return &(*it);
760 }
761
762 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800763}
764
Ed Tanous23a21a12020-07-25 04:45:05 +0000765inline CreatePIDRet createPidInterface(
zhanghch058d1b46d2021-04-01 11:18:24 +0800766 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type,
Ed Tanousb5a76932020-09-29 16:16:58 -0700767 const nlohmann::json::iterator& it, const std::string& path,
James Feist83ff9ab2018-08-31 10:18:24 -0700768 const dbus::utility::ManagedObjectType& managedObj, bool createNewObject,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800769 dbus::utility::DBusPropertiesMap& output, std::string& chassis,
770 const std::string& profile)
James Feist83ff9ab2018-08-31 10:18:24 -0700771{
772
James Feist5f2caae2018-12-12 14:08:25 -0800773 // common deleter
James Feistb6baeaa2019-02-21 10:41:40 -0800774 if (it.value() == nullptr)
James Feist5f2caae2018-12-12 14:08:25 -0800775 {
776 std::string iface;
777 if (type == "PidControllers" || type == "FanControllers")
778 {
779 iface = pidConfigurationIface;
780 }
781 else if (type == "FanZones")
782 {
783 iface = pidZoneConfigurationIface;
784 }
785 else if (type == "StepwiseControllers")
786 {
787 iface = stepwiseConfigurationIface;
788 }
789 else
790 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600791 BMCWEB_LOG_ERROR << "Illegal Type " << type;
James Feist5f2caae2018-12-12 14:08:25 -0800792 messages::propertyUnknown(response->res, type);
793 return CreatePIDRet::fail;
794 }
James Feist6ee7f772020-02-06 16:25:27 -0800795
796 BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n";
James Feist5f2caae2018-12-12 14:08:25 -0800797 // delete interface
798 crow::connections::systemBus->async_method_call(
799 [response, path](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700800 if (ec)
801 {
802 BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec;
803 messages::internalError(response->res);
804 return;
805 }
806 messages::success(response->res);
James Feist5f2caae2018-12-12 14:08:25 -0800807 },
808 "xyz.openbmc_project.EntityManager", path, iface, "Delete");
809 return CreatePIDRet::del;
810 }
811
Ed Tanous711ac7a2021-12-20 09:34:41 -0800812 const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800813 if (!createNewObject)
814 {
815 // if we aren't creating a new object, we should be able to find it on
816 // d-bus
James Feist73df0db2019-03-25 15:29:35 -0700817 managedItem = findChassis(managedObj, it.key(), chassis);
818 if (managedItem == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800819 {
820 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700821 messages::invalidObject(response->res,
822 crow::utility::urlFromPieces(
823 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800824 return CreatePIDRet::fail;
825 }
826 }
827
Ed Tanous26f69762022-01-25 09:49:11 -0800828 if (!profile.empty() &&
James Feist73df0db2019-03-25 15:29:35 -0700829 (type == "PidControllers" || type == "FanControllers" ||
830 type == "StepwiseControllers"))
831 {
832 if (managedItem == nullptr)
833 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800834 output.emplace_back("Profiles", std::vector<std::string>{profile});
James Feist73df0db2019-03-25 15:29:35 -0700835 }
836 else
837 {
838 std::string interface;
839 if (type == "StepwiseControllers")
840 {
841 interface = stepwiseConfigurationIface;
842 }
843 else
844 {
845 interface = pidConfigurationIface;
846 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800847 bool ifaceFound = false;
848 for (const auto& iface : managedItem->second)
849 {
850 if (iface.first == interface)
851 {
852 ifaceFound = true;
853 for (const auto& prop : iface.second)
854 {
855 if (prop.first == "Profiles")
856 {
857 const std::vector<std::string>* curProfiles =
858 std::get_if<std::vector<std::string>>(
859 &(prop.second));
860 if (curProfiles == nullptr)
861 {
862 BMCWEB_LOG_ERROR
863 << "Illegal profiles in managed object";
864 messages::internalError(response->res);
865 return CreatePIDRet::fail;
866 }
867 if (std::find(curProfiles->begin(),
868 curProfiles->end(),
869 profile) == curProfiles->end())
870 {
871 std::vector<std::string> newProfiles =
872 *curProfiles;
873 newProfiles.push_back(profile);
Ed Tanousb9d36b42022-02-26 21:42:46 -0800874 output.emplace_back("Profiles", newProfiles);
Ed Tanous711ac7a2021-12-20 09:34:41 -0800875 }
876 }
877 }
878 }
879 }
880
881 if (!ifaceFound)
James Feist73df0db2019-03-25 15:29:35 -0700882 {
883 BMCWEB_LOG_ERROR
884 << "Failed to find interface in managed object";
885 messages::internalError(response->res);
886 return CreatePIDRet::fail;
887 }
James Feist73df0db2019-03-25 15:29:35 -0700888 }
889 }
890
James Feist83ff9ab2018-08-31 10:18:24 -0700891 if (type == "PidControllers" || type == "FanControllers")
892 {
893 if (createNewObject)
894 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800895 output.emplace_back("Class",
896 type == "PidControllers" ? "temp" : "fan");
897 output.emplace_back("Type", "Pid");
James Feist83ff9ab2018-08-31 10:18:24 -0700898 }
James Feist5f2caae2018-12-12 14:08:25 -0800899
900 std::optional<std::vector<nlohmann::json>> zones;
901 std::optional<std::vector<std::string>> inputs;
902 std::optional<std::vector<std::string>> outputs;
903 std::map<std::string, std::optional<double>> doubles;
James Feistb943aae2019-07-11 16:33:56 -0700904 std::optional<std::string> setpointOffset;
James Feist5f2caae2018-12-12 14:08:25 -0800905 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -0800906 it.value(), response->res, "Inputs", inputs, "Outputs", outputs,
James Feist5f2caae2018-12-12 14:08:25 -0800907 "Zones", zones, "FFGainCoefficient",
908 doubles["FFGainCoefficient"], "FFOffCoefficient",
909 doubles["FFOffCoefficient"], "ICoefficient",
910 doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"],
911 "ILimitMin", doubles["ILimitMin"], "OutLimitMax",
912 doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"],
913 "PCoefficient", doubles["PCoefficient"], "SetPoint",
James Feistb943aae2019-07-11 16:33:56 -0700914 doubles["SetPoint"], "SetPointOffset", setpointOffset,
915 "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"],
916 "PositiveHysteresis", doubles["PositiveHysteresis"],
917 "NegativeHysteresis", doubles["NegativeHysteresis"]))
James Feist83ff9ab2018-08-31 10:18:24 -0700918 {
Ed Tanous71f52d92021-02-19 08:51:17 -0800919 BMCWEB_LOG_ERROR
920 << "Illegal Property "
921 << it.value().dump(2, ' ', true,
922 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -0800923 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700924 }
James Feist5f2caae2018-12-12 14:08:25 -0800925 if (zones)
James Feist83ff9ab2018-08-31 10:18:24 -0700926 {
James Feist5f2caae2018-12-12 14:08:25 -0800927 std::vector<std::string> zonesStr;
928 if (!getZonesFromJsonReq(response, *zones, zonesStr))
James Feist83ff9ab2018-08-31 10:18:24 -0700929 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600930 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -0800931 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700932 }
James Feistb6baeaa2019-02-21 10:41:40 -0800933 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -0800934 findChassis(managedObj, zonesStr[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800935 {
936 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700937 messages::invalidObject(
938 response->res, crow::utility::urlFromPieces(
939 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800940 return CreatePIDRet::fail;
941 }
Ed Tanousb9d36b42022-02-26 21:42:46 -0800942 output.emplace_back("Zones", std::move(zonesStr));
James Feist5f2caae2018-12-12 14:08:25 -0800943 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800944
945 if (inputs)
James Feist5f2caae2018-12-12 14:08:25 -0800946 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800947 for (std::string& value : *inputs)
James Feist83ff9ab2018-08-31 10:18:24 -0700948 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800949 std::replace(value.begin(), value.end(), '_', ' ');
James Feist83ff9ab2018-08-31 10:18:24 -0700950 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800951 output.emplace_back("Inputs", *inputs);
952 }
953
954 if (outputs)
955 {
956 for (std::string& value : *outputs)
957 {
958 std::replace(value.begin(), value.end(), '_', ' ');
959 }
960 output.emplace_back("Outputs", *outputs);
James Feist5f2caae2018-12-12 14:08:25 -0800961 }
James Feist83ff9ab2018-08-31 10:18:24 -0700962
James Feistb943aae2019-07-11 16:33:56 -0700963 if (setpointOffset)
964 {
965 // translate between redfish and dbus names
966 if (*setpointOffset == "UpperThresholdNonCritical")
967 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800968 output.emplace_back("SetPointOffset", "WarningLow");
James Feistb943aae2019-07-11 16:33:56 -0700969 }
970 else if (*setpointOffset == "LowerThresholdNonCritical")
971 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800972 output.emplace_back("SetPointOffset", "WarningHigh");
James Feistb943aae2019-07-11 16:33:56 -0700973 }
974 else if (*setpointOffset == "LowerThresholdCritical")
975 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800976 output.emplace_back("SetPointOffset", "CriticalLow");
James Feistb943aae2019-07-11 16:33:56 -0700977 }
978 else if (*setpointOffset == "UpperThresholdCritical")
979 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800980 output.emplace_back("SetPointOffset", "CriticalHigh");
James Feistb943aae2019-07-11 16:33:56 -0700981 }
982 else
983 {
984 BMCWEB_LOG_ERROR << "Invalid setpointoffset "
985 << *setpointOffset;
Ed Tanousace85d62021-10-26 12:45:59 -0700986 messages::propertyValueNotInList(response->res, it.key(),
987 "SetPointOffset");
James Feistb943aae2019-07-11 16:33:56 -0700988 return CreatePIDRet::fail;
989 }
990 }
991
James Feist5f2caae2018-12-12 14:08:25 -0800992 // doubles
993 for (const auto& pairs : doubles)
994 {
995 if (!pairs.second)
James Feist83ff9ab2018-08-31 10:18:24 -0700996 {
James Feist5f2caae2018-12-12 14:08:25 -0800997 continue;
James Feist83ff9ab2018-08-31 10:18:24 -0700998 }
James Feist5f2caae2018-12-12 14:08:25 -0800999 BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second;
Ed Tanousb9d36b42022-02-26 21:42:46 -08001000 output.emplace_back(pairs.first, *pairs.second);
James Feist83ff9ab2018-08-31 10:18:24 -07001001 }
1002 }
James Feist5f2caae2018-12-12 14:08:25 -08001003
James Feist83ff9ab2018-08-31 10:18:24 -07001004 else if (type == "FanZones")
1005 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001006 output.emplace_back("Type", "Pid.Zone");
James Feist83ff9ab2018-08-31 10:18:24 -07001007
James Feist5f2caae2018-12-12 14:08:25 -08001008 std::optional<nlohmann::json> chassisContainer;
1009 std::optional<double> failSafePercent;
James Feistd3ec07f2019-02-25 14:51:15 -08001010 std::optional<double> minThermalOutput;
James Feistb6baeaa2019-02-21 10:41:40 -08001011 if (!redfish::json_util::readJson(it.value(), response->res, "Chassis",
James Feist5f2caae2018-12-12 14:08:25 -08001012 chassisContainer, "FailSafePercent",
James Feistd3ec07f2019-02-25 14:51:15 -08001013 failSafePercent, "MinThermalOutput",
1014 minThermalOutput))
James Feist83ff9ab2018-08-31 10:18:24 -07001015 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001016 BMCWEB_LOG_ERROR
1017 << "Illegal Property "
1018 << it.value().dump(2, ' ', true,
1019 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001020 return CreatePIDRet::fail;
1021 }
James Feist83ff9ab2018-08-31 10:18:24 -07001022
James Feist5f2caae2018-12-12 14:08:25 -08001023 if (chassisContainer)
1024 {
1025
1026 std::string chassisId;
1027 if (!redfish::json_util::readJson(*chassisContainer, response->res,
1028 "@odata.id", chassisId))
James Feist83ff9ab2018-08-31 10:18:24 -07001029 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001030 BMCWEB_LOG_ERROR
1031 << "Illegal Property "
1032 << chassisContainer->dump(
1033 2, ' ', true,
1034 nlohmann::json::error_handler_t::replace);
James Feist83ff9ab2018-08-31 10:18:24 -07001035 return CreatePIDRet::fail;
1036 }
James Feist5f2caae2018-12-12 14:08:25 -08001037
AppaRao Puli717794d2019-10-18 22:54:53 +05301038 // /redfish/v1/chassis/chassis_name/
James Feist5f2caae2018-12-12 14:08:25 -08001039 if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis))
1040 {
1041 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
Ed Tanousace85d62021-10-26 12:45:59 -07001042 messages::invalidObject(
1043 response->res, crow::utility::urlFromPieces(
1044 "redfish", "v1", "Chassis", chassisId));
James Feist5f2caae2018-12-12 14:08:25 -08001045 return CreatePIDRet::fail;
1046 }
1047 }
James Feistd3ec07f2019-02-25 14:51:15 -08001048 if (minThermalOutput)
James Feist5f2caae2018-12-12 14:08:25 -08001049 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001050 output.emplace_back("MinThermalOutput", *minThermalOutput);
James Feist5f2caae2018-12-12 14:08:25 -08001051 }
1052 if (failSafePercent)
1053 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001054 output.emplace_back("FailSafePercent", *failSafePercent);
James Feist5f2caae2018-12-12 14:08:25 -08001055 }
1056 }
1057 else if (type == "StepwiseControllers")
1058 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001059 output.emplace_back("Type", "Stepwise");
James Feist5f2caae2018-12-12 14:08:25 -08001060
1061 std::optional<std::vector<nlohmann::json>> zones;
1062 std::optional<std::vector<nlohmann::json>> steps;
1063 std::optional<std::vector<std::string>> inputs;
1064 std::optional<double> positiveHysteresis;
1065 std::optional<double> negativeHysteresis;
James Feistc33a90e2019-03-01 10:17:44 -08001066 std::optional<std::string> direction; // upper clipping curve vs lower
James Feist5f2caae2018-12-12 14:08:25 -08001067 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -08001068 it.value(), response->res, "Zones", zones, "Steps", steps,
1069 "Inputs", inputs, "PositiveHysteresis", positiveHysteresis,
James Feistc33a90e2019-03-01 10:17:44 -08001070 "NegativeHysteresis", negativeHysteresis, "Direction",
1071 direction))
James Feist5f2caae2018-12-12 14:08:25 -08001072 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001073 BMCWEB_LOG_ERROR
1074 << "Illegal Property "
1075 << it.value().dump(2, ' ', true,
1076 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001077 return CreatePIDRet::fail;
1078 }
1079
1080 if (zones)
1081 {
James Feistb6baeaa2019-02-21 10:41:40 -08001082 std::vector<std::string> zonesStrs;
1083 if (!getZonesFromJsonReq(response, *zones, zonesStrs))
James Feist5f2caae2018-12-12 14:08:25 -08001084 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001085 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -08001086 return CreatePIDRet::fail;
1087 }
James Feistb6baeaa2019-02-21 10:41:40 -08001088 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -08001089 findChassis(managedObj, zonesStrs[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -08001090 {
1091 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -07001092 messages::invalidObject(
1093 response->res, crow::utility::urlFromPieces(
1094 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -08001095 return CreatePIDRet::fail;
1096 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001097 output.emplace_back("Zones", std::move(zonesStrs));
James Feist5f2caae2018-12-12 14:08:25 -08001098 }
1099 if (steps)
1100 {
1101 std::vector<double> readings;
1102 std::vector<double> outputs;
1103 for (auto& step : *steps)
1104 {
Ed Tanous543f4402022-01-06 13:12:53 -08001105 double target = 0.0;
1106 double out = 0.0;
James Feist5f2caae2018-12-12 14:08:25 -08001107
1108 if (!redfish::json_util::readJson(step, response->res, "Target",
Ed Tanous23a21a12020-07-25 04:45:05 +00001109 target, "Output", out))
James Feist5f2caae2018-12-12 14:08:25 -08001110 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001111 BMCWEB_LOG_ERROR
1112 << "Illegal Property "
1113 << it.value().dump(
1114 2, ' ', true,
1115 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001116 return CreatePIDRet::fail;
1117 }
1118 readings.emplace_back(target);
Ed Tanous23a21a12020-07-25 04:45:05 +00001119 outputs.emplace_back(out);
James Feist5f2caae2018-12-12 14:08:25 -08001120 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001121 output.emplace_back("Reading", std::move(readings));
1122 output.emplace_back("Output", std::move(outputs));
James Feist5f2caae2018-12-12 14:08:25 -08001123 }
1124 if (inputs)
1125 {
1126 for (std::string& value : *inputs)
1127 {
Ed Tanousa170f272022-06-30 21:53:27 -07001128
1129 std::replace(value.begin(), value.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -08001130 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001131 output.emplace_back("Inputs", std::move(*inputs));
James Feist5f2caae2018-12-12 14:08:25 -08001132 }
1133 if (negativeHysteresis)
1134 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001135 output.emplace_back("NegativeHysteresis", *negativeHysteresis);
James Feist5f2caae2018-12-12 14:08:25 -08001136 }
1137 if (positiveHysteresis)
1138 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001139 output.emplace_back("PositiveHysteresis", *positiveHysteresis);
James Feist83ff9ab2018-08-31 10:18:24 -07001140 }
James Feistc33a90e2019-03-01 10:17:44 -08001141 if (direction)
1142 {
1143 constexpr const std::array<const char*, 2> allowedDirections = {
1144 "Ceiling", "Floor"};
1145 if (std::find(allowedDirections.begin(), allowedDirections.end(),
1146 *direction) == allowedDirections.end())
1147 {
1148 messages::propertyValueTypeError(response->res, "Direction",
1149 *direction);
1150 return CreatePIDRet::fail;
1151 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001152 output.emplace_back("Class", *direction);
James Feistc33a90e2019-03-01 10:17:44 -08001153 }
James Feist83ff9ab2018-08-31 10:18:24 -07001154 }
1155 else
1156 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001157 BMCWEB_LOG_ERROR << "Illegal Type " << type;
Jason M. Bills35a62c72018-10-09 12:45:45 -07001158 messages::propertyUnknown(response->res, type);
James Feist83ff9ab2018-08-31 10:18:24 -07001159 return CreatePIDRet::fail;
1160 }
1161 return CreatePIDRet::patch;
1162}
James Feist73df0db2019-03-25 15:29:35 -07001163struct GetPIDValues : std::enable_shared_from_this<GetPIDValues>
1164{
Ed Tanous6936afe2022-09-08 15:10:39 -07001165 struct CompletionValues
1166 {
1167 std::vector<std::string> supportedProfiles;
1168 std::string currentProfile;
1169 dbus::utility::MapperGetSubTreeResponse subtree;
1170 };
James Feist73df0db2019-03-25 15:29:35 -07001171
Ed Tanous4e23a442022-06-06 09:57:26 -07001172 explicit GetPIDValues(
1173 const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
Ed Tanous23a21a12020-07-25 04:45:05 +00001174 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001175
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001176 {}
James Feist73df0db2019-03-25 15:29:35 -07001177
1178 void run()
1179 {
1180 std::shared_ptr<GetPIDValues> self = shared_from_this();
1181
1182 // get all configurations
George Liue99073f2022-12-09 11:06:16 +08001183 constexpr std::array<std::string_view, 4> interfaces = {
1184 pidConfigurationIface, pidZoneConfigurationIface,
1185 objectManagerIface, stepwiseConfigurationIface};
1186 dbus::utility::getSubTree(
1187 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001188 [self](
George Liue99073f2022-12-09 11:06:16 +08001189 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001190 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001191 if (ec)
1192 {
1193 BMCWEB_LOG_ERROR << ec;
1194 messages::internalError(self->asyncResp->res);
1195 return;
1196 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001197 self->complete.subtree = subtreeLocal;
George Liue99073f2022-12-09 11:06:16 +08001198 });
James Feist73df0db2019-03-25 15:29:35 -07001199
1200 // at the same time get the selected profile
George Liue99073f2022-12-09 11:06:16 +08001201 constexpr std::array<std::string_view, 1> thermalModeIfaces = {
1202 thermalModeIface};
1203 dbus::utility::getSubTree(
1204 "/", 0, thermalModeIfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001205 [self](
George Liue99073f2022-12-09 11:06:16 +08001206 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001207 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001208 if (ec || subtreeLocal.empty())
1209 {
1210 return;
1211 }
1212 if (subtreeLocal[0].second.size() != 1)
1213 {
1214 // invalid mapper response, should never happen
1215 BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error";
1216 messages::internalError(self->asyncResp->res);
1217 return;
1218 }
1219
1220 const std::string& path = subtreeLocal[0].first;
1221 const std::string& owner = subtreeLocal[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001222
1223 sdbusplus::asio::getAllProperties(
1224 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001225 [path, owner,
1226 self](const boost::system::error_code ec2,
1227 const dbus::utility::DBusPropertiesMap& resp) {
1228 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001229 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001230 BMCWEB_LOG_ERROR
1231 << "GetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001232 messages::internalError(self->asyncResp->res);
1233 return;
1234 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001235
Ed Tanous002d39b2022-05-31 08:59:27 -07001236 const std::string* current = nullptr;
1237 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001238
1239 const bool success = sdbusplus::unpackPropertiesNoThrow(
1240 dbus_utils::UnpackErrorPrinter(), resp, "Current", current,
1241 "Supported", supported);
1242
1243 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001244 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001245 messages::internalError(self->asyncResp->res);
1246 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001247 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001248
Ed Tanous002d39b2022-05-31 08:59:27 -07001249 if (current == nullptr || supported == nullptr)
1250 {
1251 BMCWEB_LOG_ERROR
1252 << "GetPIDValues: thermal mode iface invalid " << path;
1253 messages::internalError(self->asyncResp->res);
1254 return;
1255 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001256 self->complete.currentProfile = *current;
1257 self->complete.supportedProfiles = *supported;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001258 });
George Liue99073f2022-12-09 11:06:16 +08001259 });
James Feist73df0db2019-03-25 15:29:35 -07001260 }
1261
Ed Tanous6936afe2022-09-08 15:10:39 -07001262 static void
1263 processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1264 const CompletionValues& completion)
James Feist73df0db2019-03-25 15:29:35 -07001265 {
1266 if (asyncResp->res.result() != boost::beast::http::status::ok)
1267 {
1268 return;
1269 }
1270 // create map of <connection, path to objMgr>>
Ed Tanous6936afe2022-09-08 15:10:39 -07001271 boost::container::flat_map<
1272 std::string, std::string, std::less<>,
1273 std::vector<std::pair<std::string, std::string>>>
1274 objectMgrPaths;
1275 boost::container::flat_set<std::string, std::less<>,
1276 std::vector<std::string>>
1277 calledConnections;
1278 for (const auto& pathGroup : completion.subtree)
James Feist73df0db2019-03-25 15:29:35 -07001279 {
1280 for (const auto& connectionGroup : pathGroup.second)
1281 {
1282 auto findConnection =
1283 calledConnections.find(connectionGroup.first);
1284 if (findConnection != calledConnections.end())
1285 {
1286 break;
1287 }
1288 for (const std::string& interface : connectionGroup.second)
1289 {
1290 if (interface == objectManagerIface)
1291 {
1292 objectMgrPaths[connectionGroup.first] = pathGroup.first;
1293 }
1294 // this list is alphabetical, so we
1295 // should have found the objMgr by now
1296 if (interface == pidConfigurationIface ||
1297 interface == pidZoneConfigurationIface ||
1298 interface == stepwiseConfigurationIface)
1299 {
1300 auto findObjMgr =
1301 objectMgrPaths.find(connectionGroup.first);
1302 if (findObjMgr == objectMgrPaths.end())
1303 {
1304 BMCWEB_LOG_DEBUG << connectionGroup.first
1305 << "Has no Object Manager";
1306 continue;
1307 }
1308
1309 calledConnections.insert(connectionGroup.first);
1310
1311 asyncPopulatePid(findObjMgr->first, findObjMgr->second,
Ed Tanous6936afe2022-09-08 15:10:39 -07001312 completion.currentProfile,
1313 completion.supportedProfiles,
James Feist73df0db2019-03-25 15:29:35 -07001314 asyncResp);
1315 break;
1316 }
1317 }
1318 }
1319 }
1320 }
1321
Ed Tanous6936afe2022-09-08 15:10:39 -07001322 ~GetPIDValues()
1323 {
1324 boost::asio::post(crow::connections::systemBus->get_io_context(),
1325 std::bind_front(&processingComplete, asyncResp,
1326 std::move(complete)));
1327 }
1328
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001329 GetPIDValues(const GetPIDValues&) = delete;
1330 GetPIDValues(GetPIDValues&&) = delete;
1331 GetPIDValues& operator=(const GetPIDValues&) = delete;
1332 GetPIDValues& operator=(GetPIDValues&&) = delete;
1333
zhanghch058d1b46d2021-04-01 11:18:24 +08001334 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
Ed Tanous6936afe2022-09-08 15:10:39 -07001335 CompletionValues complete;
James Feist73df0db2019-03-25 15:29:35 -07001336};
1337
1338struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
1339{
1340
zhanghch058d1b46d2021-04-01 11:18:24 +08001341 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
James Feist73df0db2019-03-25 15:29:35 -07001342 nlohmann::json& data) :
Ed Tanous271584a2019-07-09 16:24:22 -07001343 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001344 {
1345
1346 std::optional<nlohmann::json> pidControllers;
1347 std::optional<nlohmann::json> fanControllers;
1348 std::optional<nlohmann::json> fanZones;
1349 std::optional<nlohmann::json> stepwiseControllers;
1350
1351 if (!redfish::json_util::readJson(
1352 data, asyncResp->res, "PidControllers", pidControllers,
1353 "FanControllers", fanControllers, "FanZones", fanZones,
1354 "StepwiseControllers", stepwiseControllers, "Profile", profile))
1355 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001356 BMCWEB_LOG_ERROR
1357 << "Illegal Property "
1358 << data.dump(2, ' ', true,
1359 nlohmann::json::error_handler_t::replace);
James Feist73df0db2019-03-25 15:29:35 -07001360 return;
1361 }
1362 configuration.emplace_back("PidControllers", std::move(pidControllers));
1363 configuration.emplace_back("FanControllers", std::move(fanControllers));
1364 configuration.emplace_back("FanZones", std::move(fanZones));
1365 configuration.emplace_back("StepwiseControllers",
1366 std::move(stepwiseControllers));
1367 }
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001368
1369 SetPIDValues(const SetPIDValues&) = delete;
1370 SetPIDValues(SetPIDValues&&) = delete;
1371 SetPIDValues& operator=(const SetPIDValues&) = delete;
1372 SetPIDValues& operator=(SetPIDValues&&) = delete;
1373
James Feist73df0db2019-03-25 15:29:35 -07001374 void run()
1375 {
1376 if (asyncResp->res.result() != boost::beast::http::status::ok)
1377 {
1378 return;
1379 }
1380
1381 std::shared_ptr<SetPIDValues> self = shared_from_this();
1382
1383 // todo(james): might make sense to do a mapper call here if this
1384 // interface gets more traction
1385 crow::connections::systemBus->async_method_call(
1386 [self](const boost::system::error_code ec,
Ed Tanous914e2d52022-01-07 11:38:34 -08001387 const dbus::utility::ManagedObjectType& mObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001388 if (ec)
1389 {
1390 BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
1391 messages::internalError(self->asyncResp->res);
1392 return;
1393 }
1394 const std::array<const char*, 3> configurations = {
1395 pidConfigurationIface, pidZoneConfigurationIface,
1396 stepwiseConfigurationIface};
James Feiste69d9de2020-02-07 12:23:27 -08001397
Ed Tanous002d39b2022-05-31 08:59:27 -07001398 for (const auto& [path, object] : mObj)
1399 {
1400 for (const auto& [interface, _] : object)
James Feiste69d9de2020-02-07 12:23:27 -08001401 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001402 if (std::find(configurations.begin(), configurations.end(),
1403 interface) != configurations.end())
James Feiste69d9de2020-02-07 12:23:27 -08001404 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001405 self->objectCount++;
1406 break;
James Feiste69d9de2020-02-07 12:23:27 -08001407 }
James Feiste69d9de2020-02-07 12:23:27 -08001408 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001409 }
1410 self->managedObj = mObj;
James Feist73df0db2019-03-25 15:29:35 -07001411 },
Nan Zhouc106b672022-09-20 22:35:31 +00001412 "xyz.openbmc_project.EntityManager",
1413 "/xyz/openbmc_project/inventory", objectManagerIface,
James Feist73df0db2019-03-25 15:29:35 -07001414 "GetManagedObjects");
1415
1416 // at the same time get the profile information
George Liue99073f2022-12-09 11:06:16 +08001417 constexpr std::array<std::string_view, 1> thermalModeIfaces = {
1418 thermalModeIface};
1419 dbus::utility::getSubTree(
1420 "/", 0, thermalModeIfaces,
1421 [self](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001422 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001423 if (ec || subtree.empty())
1424 {
1425 return;
1426 }
1427 if (subtree[0].second.empty())
1428 {
1429 // invalid mapper response, should never happen
1430 BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error";
1431 messages::internalError(self->asyncResp->res);
1432 return;
1433 }
1434
1435 const std::string& path = subtree[0].first;
1436 const std::string& owner = subtree[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001437 sdbusplus::asio::getAllProperties(
1438 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001439 [self, path, owner](const boost::system::error_code ec2,
1440 const dbus::utility::DBusPropertiesMap& r) {
1441 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001442 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001443 BMCWEB_LOG_ERROR
1444 << "SetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001445 messages::internalError(self->asyncResp->res);
1446 return;
1447 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001448 const std::string* current = nullptr;
1449 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001450
1451 const bool success = sdbusplus::unpackPropertiesNoThrow(
1452 dbus_utils::UnpackErrorPrinter(), r, "Current", current,
1453 "Supported", supported);
1454
1455 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001456 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001457 messages::internalError(self->asyncResp->res);
1458 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001459 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001460
Ed Tanous002d39b2022-05-31 08:59:27 -07001461 if (current == nullptr || supported == nullptr)
1462 {
1463 BMCWEB_LOG_ERROR
1464 << "SetPIDValues: thermal mode iface invalid " << path;
1465 messages::internalError(self->asyncResp->res);
1466 return;
1467 }
1468 self->currentProfile = *current;
1469 self->supportedProfiles = *supported;
1470 self->profileConnection = owner;
1471 self->profilePath = path;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001472 });
George Liue99073f2022-12-09 11:06:16 +08001473 });
James Feist73df0db2019-03-25 15:29:35 -07001474 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001475 void pidSetDone()
James Feist73df0db2019-03-25 15:29:35 -07001476 {
1477 if (asyncResp->res.result() != boost::beast::http::status::ok)
1478 {
1479 return;
1480 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001481 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001482 if (profile)
1483 {
1484 if (std::find(supportedProfiles.begin(), supportedProfiles.end(),
1485 *profile) == supportedProfiles.end())
1486 {
1487 messages::actionParameterUnknown(response->res, "Profile",
1488 *profile);
1489 return;
1490 }
1491 currentProfile = *profile;
1492 crow::connections::systemBus->async_method_call(
1493 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001494 if (ec)
1495 {
1496 BMCWEB_LOG_ERROR << "Error patching profile" << ec;
1497 messages::internalError(response->res);
1498 }
James Feist73df0db2019-03-25 15:29:35 -07001499 },
1500 profileConnection, profilePath,
1501 "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
Ed Tanous168e20c2021-12-13 14:39:53 -08001502 "Current", dbus::utility::DbusVariantType(*profile));
James Feist73df0db2019-03-25 15:29:35 -07001503 }
1504
1505 for (auto& containerPair : configuration)
1506 {
1507 auto& container = containerPair.second;
1508 if (!container)
1509 {
1510 continue;
1511 }
James Feist6ee7f772020-02-06 16:25:27 -08001512 BMCWEB_LOG_DEBUG << *container;
1513
Ed Tanous02cad962022-06-30 16:50:15 -07001514 const std::string& type = containerPair.first;
James Feist73df0db2019-03-25 15:29:35 -07001515
1516 for (nlohmann::json::iterator it = container->begin();
Manojkiran Eda17a897d2020-09-12 15:31:58 +05301517 it != container->end(); ++it)
James Feist73df0db2019-03-25 15:29:35 -07001518 {
1519 const auto& name = it.key();
James Feist6ee7f772020-02-06 16:25:27 -08001520 BMCWEB_LOG_DEBUG << "looking for " << name;
1521
James Feist73df0db2019-03-25 15:29:35 -07001522 auto pathItr =
1523 std::find_if(managedObj.begin(), managedObj.end(),
1524 [&name](const auto& obj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001525 return boost::algorithm::ends_with(obj.first.str,
1526 "/" + name);
1527 });
Ed Tanousb9d36b42022-02-26 21:42:46 -08001528 dbus::utility::DBusPropertiesMap output;
James Feist73df0db2019-03-25 15:29:35 -07001529
1530 output.reserve(16); // The pid interface length
1531
1532 // determines if we're patching entity-manager or
1533 // creating a new object
1534 bool createNewObject = (pathItr == managedObj.end());
James Feist6ee7f772020-02-06 16:25:27 -08001535 BMCWEB_LOG_DEBUG << "Found = " << !createNewObject;
1536
James Feist73df0db2019-03-25 15:29:35 -07001537 std::string iface;
Ed Tanousea2b6702022-03-07 16:48:38 -08001538 if (!createNewObject)
James Feist73df0db2019-03-25 15:29:35 -07001539 {
Potin Lai8be2b5b2022-11-22 13:27:16 +08001540 bool findInterface = false;
Ed Tanousea2b6702022-03-07 16:48:38 -08001541 for (const auto& interface : pathItr->second)
James Feist73df0db2019-03-25 15:29:35 -07001542 {
Ed Tanousea2b6702022-03-07 16:48:38 -08001543 if (interface.first == pidConfigurationIface)
1544 {
1545 if (type == "PidControllers" ||
1546 type == "FanControllers")
1547 {
1548 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001549 findInterface = true;
1550 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001551 }
1552 }
1553 else if (interface.first == pidZoneConfigurationIface)
1554 {
1555 if (type == "FanZones")
1556 {
1557 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001558 findInterface = true;
1559 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001560 }
1561 }
1562 else if (interface.first == stepwiseConfigurationIface)
1563 {
1564 if (type == "StepwiseControllers")
1565 {
1566 iface = stepwiseConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001567 findInterface = true;
1568 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001569 }
1570 }
James Feist73df0db2019-03-25 15:29:35 -07001571 }
Potin Lai8be2b5b2022-11-22 13:27:16 +08001572
1573 // create new object if interface not found
1574 if (!findInterface)
1575 {
1576 createNewObject = true;
1577 }
James Feist73df0db2019-03-25 15:29:35 -07001578 }
James Feist6ee7f772020-02-06 16:25:27 -08001579
1580 if (createNewObject && it.value() == nullptr)
1581 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -05001582 // can't delete a non-existent object
Ed Tanous1668ce62022-02-07 23:44:31 -08001583 messages::propertyValueNotInList(response->res,
1584 it.value().dump(), name);
James Feist6ee7f772020-02-06 16:25:27 -08001585 continue;
1586 }
1587
1588 std::string path;
1589 if (pathItr != managedObj.end())
1590 {
1591 path = pathItr->first.str;
1592 }
1593
James Feist73df0db2019-03-25 15:29:35 -07001594 BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n";
James Feiste69d9de2020-02-07 12:23:27 -08001595
1596 // arbitrary limit to avoid attacks
1597 constexpr const size_t controllerLimit = 500;
James Feist14b0b8d2020-02-12 11:52:07 -08001598 if (createNewObject && objectCount >= controllerLimit)
James Feiste69d9de2020-02-07 12:23:27 -08001599 {
1600 messages::resourceExhaustion(response->res, type);
1601 continue;
1602 }
Ed Tanousa170f272022-06-30 21:53:27 -07001603 std::string escaped = name;
1604 std::replace(escaped.begin(), escaped.end(), '_', ' ');
1605 output.emplace_back("Name", escaped);
James Feist73df0db2019-03-25 15:29:35 -07001606
1607 std::string chassis;
1608 CreatePIDRet ret = createPidInterface(
James Feist6ee7f772020-02-06 16:25:27 -08001609 response, type, it, path, managedObj, createNewObject,
1610 output, chassis, currentProfile);
James Feist73df0db2019-03-25 15:29:35 -07001611 if (ret == CreatePIDRet::fail)
1612 {
1613 return;
1614 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001615 if (ret == CreatePIDRet::del)
James Feist73df0db2019-03-25 15:29:35 -07001616 {
1617 continue;
1618 }
1619
1620 if (!createNewObject)
1621 {
1622 for (const auto& property : output)
1623 {
1624 crow::connections::systemBus->async_method_call(
1625 [response,
1626 propertyName{std::string(property.first)}](
1627 const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001628 if (ec)
1629 {
1630 BMCWEB_LOG_ERROR << "Error patching "
1631 << propertyName << ": " << ec;
1632 messages::internalError(response->res);
1633 return;
1634 }
1635 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001636 },
James Feist6ee7f772020-02-06 16:25:27 -08001637 "xyz.openbmc_project.EntityManager", path,
James Feist73df0db2019-03-25 15:29:35 -07001638 "org.freedesktop.DBus.Properties", "Set", iface,
1639 property.first, property.second);
1640 }
1641 }
1642 else
1643 {
1644 if (chassis.empty())
1645 {
1646 BMCWEB_LOG_ERROR << "Failed to get chassis from config";
Ed Tanousace85d62021-10-26 12:45:59 -07001647 messages::internalError(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001648 return;
1649 }
1650
1651 bool foundChassis = false;
1652 for (const auto& obj : managedObj)
1653 {
1654 if (boost::algorithm::ends_with(obj.first.str, chassis))
1655 {
1656 chassis = obj.first.str;
1657 foundChassis = true;
1658 break;
1659 }
1660 }
1661 if (!foundChassis)
1662 {
1663 BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
1664 messages::resourceMissingAtURI(
Ed Tanousace85d62021-10-26 12:45:59 -07001665 response->res,
1666 crow::utility::urlFromPieces("redfish", "v1",
1667 "Chassis", chassis));
James Feist73df0db2019-03-25 15:29:35 -07001668 return;
1669 }
1670
1671 crow::connections::systemBus->async_method_call(
1672 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001673 if (ec)
1674 {
1675 BMCWEB_LOG_ERROR << "Error Adding Pid Object "
1676 << ec;
1677 messages::internalError(response->res);
1678 return;
1679 }
1680 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001681 },
1682 "xyz.openbmc_project.EntityManager", chassis,
1683 "xyz.openbmc_project.AddObject", "AddObject", output);
1684 }
1685 }
1686 }
1687 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001688
1689 ~SetPIDValues()
1690 {
1691 try
1692 {
1693 pidSetDone();
1694 }
1695 catch (...)
1696 {
1697 BMCWEB_LOG_CRITICAL << "pidSetDone threw exception";
1698 }
1699 }
1700
zhanghch058d1b46d2021-04-01 11:18:24 +08001701 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001702 std::vector<std::pair<std::string, std::optional<nlohmann::json>>>
1703 configuration;
1704 std::optional<std::string> profile;
1705 dbus::utility::ManagedObjectType managedObj;
1706 std::vector<std::string> supportedProfiles;
1707 std::string currentProfile;
1708 std::string profileConnection;
1709 std::string profilePath;
James Feist14b0b8d2020-02-12 11:52:07 -08001710 size_t objectCount = 0;
James Feist73df0db2019-03-25 15:29:35 -07001711};
James Feist83ff9ab2018-08-31 10:18:24 -07001712
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001713/**
1714 * @brief Retrieves BMC manager location data over DBus
1715 *
1716 * @param[in] aResp Shared pointer for completing asynchronous calls
1717 * @param[in] connectionName - service name
1718 * @param[in] path - object path
1719 * @return none
1720 */
zhanghch058d1b46d2021-04-01 11:18:24 +08001721inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001722 const std::string& connectionName,
1723 const std::string& path)
1724{
1725 BMCWEB_LOG_DEBUG << "Get BMC manager Location data.";
1726
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001727 sdbusplus::asio::getProperty<std::string>(
1728 *crow::connections::systemBus, connectionName, path,
1729 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001730 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001731 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001732 if (ec)
1733 {
1734 BMCWEB_LOG_DEBUG << "DBUS response error for "
1735 "Location";
1736 messages::internalError(aResp->res);
1737 return;
1738 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001739
Ed Tanous002d39b2022-05-31 08:59:27 -07001740 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
1741 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001742 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001743}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001744// avoid name collision systems.hpp
1745inline void
1746 managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001747{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001748 BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
Ed Tanous52cc1122020-07-18 13:51:21 -07001749
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001750 sdbusplus::asio::getProperty<uint64_t>(
1751 *crow::connections::systemBus, "xyz.openbmc_project.State.BMC",
1752 "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC",
1753 "LastRebootTime",
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001754 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001755 const uint64_t lastResetTime) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001756 if (ec)
1757 {
1758 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1759 return;
1760 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001761
Ed Tanous002d39b2022-05-31 08:59:27 -07001762 // LastRebootTime is epoch time, in milliseconds
1763 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
1764 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001765
Ed Tanous002d39b2022-05-31 08:59:27 -07001766 // Convert to ISO 8601 standard
1767 aResp->res.jsonValue["LastResetTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001768 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001769 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001770}
1771
1772/**
1773 * @brief Set the running firmware image
1774 *
1775 * @param[i,o] aResp - Async response object
1776 * @param[i] runningFirmwareTarget - Image to make the running image
1777 *
1778 * @return void
1779 */
1780inline void
1781 setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1782 const std::string& runningFirmwareTarget)
1783{
1784 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
1785 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
1786 if (idPos == std::string::npos)
1787 {
1788 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1789 "@odata.id");
1790 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
1791 return;
1792 }
1793 idPos++;
1794 if (idPos >= runningFirmwareTarget.size())
1795 {
1796 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1797 "@odata.id");
1798 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1799 return;
1800 }
1801 std::string firmwareId = runningFirmwareTarget.substr(idPos);
1802
1803 // Make sure the image is valid before setting priority
1804 crow::connections::systemBus->async_method_call(
Ed Tanous711ac7a2021-12-20 09:34:41 -08001805 [aResp, firmwareId,
1806 runningFirmwareTarget](const boost::system::error_code ec,
1807 dbus::utility::ManagedObjectType& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001808 if (ec)
1809 {
1810 BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
1811 messages::internalError(aResp->res);
1812 return;
1813 }
1814
1815 if (subtree.empty())
1816 {
1817 BMCWEB_LOG_DEBUG << "Can't find image!";
1818 messages::internalError(aResp->res);
1819 return;
1820 }
1821
1822 bool foundImage = false;
Ed Tanous02cad962022-06-30 16:50:15 -07001823 for (const auto& object : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -07001824 {
1825 const std::string& path =
1826 static_cast<const std::string&>(object.first);
1827 std::size_t idPos2 = path.rfind('/');
1828
1829 if (idPos2 == std::string::npos)
1830 {
1831 continue;
1832 }
1833
1834 idPos2++;
1835 if (idPos2 >= path.size())
1836 {
1837 continue;
1838 }
1839
1840 if (path.substr(idPos2) == firmwareId)
1841 {
1842 foundImage = true;
1843 break;
1844 }
1845 }
1846
1847 if (!foundImage)
1848 {
1849 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1850 "@odata.id");
1851 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1852 return;
1853 }
1854
1855 BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId
1856 << " to priority 0.";
1857
1858 // Only support Immediate
1859 // An addition could be a Redfish Setting like
1860 // ActiveSoftwareImageApplyTime and support OnReset
1861 crow::connections::systemBus->async_method_call(
Ed Tanous8a592812022-06-04 09:06:59 -07001862 [aResp](const boost::system::error_code ec2) {
1863 if (ec2)
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001864 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001865 BMCWEB_LOG_DEBUG << "D-Bus response error setting.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001866 messages::internalError(aResp->res);
1867 return;
1868 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001869 doBMCGracefulRestart(aResp);
1870 },
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001871
Ed Tanous002d39b2022-05-31 08:59:27 -07001872 "xyz.openbmc_project.Software.BMC.Updater",
1873 "/xyz/openbmc_project/software/" + firmwareId,
1874 "org.freedesktop.DBus.Properties", "Set",
1875 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
1876 dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001877 },
1878 "xyz.openbmc_project.Software.BMC.Updater",
1879 "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager",
1880 "GetManagedObjects");
1881}
Ed Tanous1abe55e2018-09-05 08:30:59 -07001882
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001883inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp,
1884 std::string datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001885{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001886 BMCWEB_LOG_DEBUG << "Set date time: " << datetime;
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001887
Ed Tanousc2e32002023-01-07 22:05:08 -08001888 std::optional<redfish::time_utils::usSinceEpoch> us =
1889 redfish::time_utils::dateStringToEpoch(datetime);
1890 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001891 {
1892 messages::propertyValueFormatError(aResp->res, datetime, "DateTime");
1893 return;
1894 }
Ed Tanousc2e32002023-01-07 22:05:08 -08001895 crow::connections::systemBus->async_method_call(
1896 [aResp{std::move(aResp)},
1897 datetime{std::move(datetime)}](const boost::system::error_code ec) {
1898 if (ec)
1899 {
1900 BMCWEB_LOG_DEBUG << "Failed to set elapsed time. "
1901 "DBUS response error "
1902 << ec;
1903 messages::internalError(aResp->res);
1904 return;
1905 }
1906 aResp->res.jsonValue["DateTime"] = datetime;
1907 },
1908 "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc",
1909 "org.freedesktop.DBus.Properties", "Set",
1910 "xyz.openbmc_project.Time.EpochTime", "Elapsed",
1911 dbus::utility::DbusVariantType(us->count()));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001912}
1913
1914inline void requestRoutesManager(App& app)
1915{
1916 std::string uuid = persistent_data::getConfig().systemUuid;
1917
1918 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07001919 .privileges(redfish::privileges::getManager)
Ed Tanous002d39b2022-05-31 08:59:27 -07001920 .methods(boost::beast::http::verb::get)(
1921 [&app, uuid](const crow::Request& req,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001922 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001923 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001924 {
1925 return;
1926 }
1927 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
Sui Chena51fc2d2022-07-14 17:21:53 -07001928 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager";
Ed Tanous002d39b2022-05-31 08:59:27 -07001929 asyncResp->res.jsonValue["Id"] = "bmc";
1930 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
1931 asyncResp->res.jsonValue["Description"] =
1932 "Baseboard Management Controller";
1933 asyncResp->res.jsonValue["PowerState"] = "On";
1934 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
1935 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
Ed Tanous14766872022-03-15 10:44:42 -07001936
Ed Tanous002d39b2022-05-31 08:59:27 -07001937 asyncResp->res.jsonValue["ManagerType"] = "BMC";
1938 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
1939 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
1940 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001941
Ed Tanous002d39b2022-05-31 08:59:27 -07001942 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
1943 "/redfish/v1/Managers/bmc/LogServices";
1944 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
1945 "/redfish/v1/Managers/bmc/NetworkProtocol";
1946 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
1947 "/redfish/v1/Managers/bmc/EthernetInterfaces";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001948
1949#ifdef BMCWEB_ENABLE_VM_NBDPROXY
Ed Tanous002d39b2022-05-31 08:59:27 -07001950 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
1951 "/redfish/v1/Managers/bmc/VirtualMedia";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001952#endif // BMCWEB_ENABLE_VM_NBDPROXY
1953
Ed Tanous002d39b2022-05-31 08:59:27 -07001954 // default oem data
1955 nlohmann::json& oem = asyncResp->res.jsonValue["Oem"];
1956 nlohmann::json& oemOpenbmc = oem["OpenBmc"];
1957 oem["@odata.type"] = "#OemManager.Oem";
1958 oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem";
1959 oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc";
1960 oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc";
Ed Tanous14766872022-03-15 10:44:42 -07001961
Ed Tanous002d39b2022-05-31 08:59:27 -07001962 nlohmann::json::object_t certificates;
1963 certificates["@odata.id"] =
1964 "/redfish/v1/Managers/bmc/Truststore/Certificates";
1965 oemOpenbmc["Certificates"] = std::move(certificates);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001966
Ed Tanous002d39b2022-05-31 08:59:27 -07001967 // Manager.Reset (an action) can be many values, OpenBMC only
1968 // supports BMC reboot.
1969 nlohmann::json& managerReset =
1970 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
1971 managerReset["target"] =
1972 "/redfish/v1/Managers/bmc/Actions/Manager.Reset";
1973 managerReset["@Redfish.ActionInfo"] =
1974 "/redfish/v1/Managers/bmc/ResetActionInfo";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001975
Ed Tanous002d39b2022-05-31 08:59:27 -07001976 // ResetToDefaults (Factory Reset) has values like
1977 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
1978 // on OpenBMC
1979 nlohmann::json& resetToDefaults =
1980 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
1981 resetToDefaults["target"] =
1982 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
Ed Tanous613dabe2022-07-09 11:17:36 -07001983 resetToDefaults["ResetType@Redfish.AllowableValues"] =
1984 nlohmann::json::array_t({"ResetAll"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001985
Ed Tanous002d39b2022-05-31 08:59:27 -07001986 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07001987 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301988
Ed Tanous002d39b2022-05-31 08:59:27 -07001989 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1990 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1991 redfishDateTimeOffset.second;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001992
Ed Tanous002d39b2022-05-31 08:59:27 -07001993 // TODO (Gunnar): Remove these one day since moved to ComputerSystem
1994 // Still used by OCP profiles
1995 // https://github.com/opencomputeproject/OCP-Profiles/issues/23
1996 // Fill in SerialConsole info
1997 asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
1998 asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
Ed Tanous613dabe2022-07-09 11:17:36 -07001999 asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
2000 nlohmann::json::array_t({"IPMI", "SSH"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002001#ifdef BMCWEB_ENABLE_KVM
Ed Tanous002d39b2022-05-31 08:59:27 -07002002 // Fill in GraphicalConsole info
2003 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
2004 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
2005 4;
Ed Tanous613dabe2022-07-09 11:17:36 -07002006 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
2007 nlohmann::json::array_t({"KVMIP"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002008#endif // BMCWEB_ENABLE_KVM
2009
Ed Tanous002d39b2022-05-31 08:59:27 -07002010 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
Ed Tanous14766872022-03-15 10:44:42 -07002011
Ed Tanous002d39b2022-05-31 08:59:27 -07002012 nlohmann::json::array_t managerForServers;
2013 nlohmann::json::object_t manager;
2014 manager["@odata.id"] = "/redfish/v1/Systems/system";
2015 managerForServers.push_back(std::move(manager));
2016
2017 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
2018 std::move(managerForServers);
2019
2020 auto health = std::make_shared<HealthPopulate>(asyncResp);
2021 health->isManagersHealth = true;
2022 health->populate();
2023
Willy Tueee00132022-06-14 14:53:17 -07002024 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
Ed Tanous002d39b2022-05-31 08:59:27 -07002025 "FirmwareVersion", true);
2026
2027 managerGetLastResetTime(asyncResp);
2028
Sui Chena51fc2d2022-07-14 17:21:53 -07002029 // ManagerDiagnosticData is added for all BMCs.
2030 nlohmann::json& managerDiagnosticData =
2031 asyncResp->res.jsonValue["ManagerDiagnosticData"];
2032 managerDiagnosticData["@odata.id"] =
2033 "/redfish/v1/Managers/bmc/ManagerDiagnosticData";
2034
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002035#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002036 auto pids = std::make_shared<GetPIDValues>(asyncResp);
2037 pids->run();
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002038#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002039
2040 getMainChassisId(asyncResp,
2041 [](const std::string& chassisId,
2042 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
2043 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
2044 nlohmann::json::array_t managerForChassis;
Ed Tanous8a592812022-06-04 09:06:59 -07002045 nlohmann::json::object_t managerObj;
2046 managerObj["@odata.id"] = "/redfish/v1/Chassis/" + chassisId;
2047 managerForChassis.push_back(std::move(managerObj));
Ed Tanous002d39b2022-05-31 08:59:27 -07002048 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
2049 std::move(managerForChassis);
2050 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
2051 "/redfish/v1/Chassis/" + chassisId;
2052 });
Ed Tanous14766872022-03-15 10:44:42 -07002053
Ed Tanous002d39b2022-05-31 08:59:27 -07002054 static bool started = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002055
Ed Tanous002d39b2022-05-31 08:59:27 -07002056 if (!started)
2057 {
2058 sdbusplus::asio::getProperty<double>(
2059 *crow::connections::systemBus, "org.freedesktop.systemd1",
2060 "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
2061 "Progress",
2062 [asyncResp](const boost::system::error_code ec,
2063 const double& val) {
2064 if (ec)
2065 {
2066 BMCWEB_LOG_ERROR << "Error while getting progress";
2067 messages::internalError(asyncResp->res);
2068 return;
2069 }
2070 if (val < 1.0)
2071 {
2072 asyncResp->res.jsonValue["Status"]["State"] = "Starting";
2073 started = true;
2074 }
2075 });
2076 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002077
George Liue99073f2022-12-09 11:06:16 +08002078 constexpr std::array<std::string_view, 1> interfaces = {
2079 "xyz.openbmc_project.Inventory.Item.Bmc"};
2080 dbus::utility::getSubTree(
2081 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07002082 [asyncResp](
George Liue99073f2022-12-09 11:06:16 +08002083 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07002084 const dbus::utility::MapperGetSubTreeResponse& subtree) {
2085 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002086 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002087 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
2088 return;
2089 }
2090 if (subtree.empty())
2091 {
2092 BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!";
2093 return;
2094 }
2095 // Assume only 1 bmc D-Bus object
2096 // Throw an error if there is more than 1
2097 if (subtree.size() > 1)
2098 {
2099 BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!";
2100 messages::internalError(asyncResp->res);
2101 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002102 }
2103
Ed Tanous002d39b2022-05-31 08:59:27 -07002104 if (subtree[0].first.empty() || subtree[0].second.size() != 1)
2105 {
2106 BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!";
2107 messages::internalError(asyncResp->res);
2108 return;
2109 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002110
Ed Tanous002d39b2022-05-31 08:59:27 -07002111 const std::string& path = subtree[0].first;
2112 const std::string& connectionName = subtree[0].second[0].first;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002113
Ed Tanous002d39b2022-05-31 08:59:27 -07002114 for (const auto& interfaceName : subtree[0].second[0].second)
2115 {
2116 if (interfaceName ==
2117 "xyz.openbmc_project.Inventory.Decorator.Asset")
2118 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002119
2120 sdbusplus::asio::getAllProperties(
2121 *crow::connections::systemBus, connectionName, path,
2122 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanous8a592812022-06-04 09:06:59 -07002123 [asyncResp](const boost::system::error_code ec2,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002124 const dbus::utility::DBusPropertiesMap&
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002125 propertiesList) {
Ed Tanous8a592812022-06-04 09:06:59 -07002126 if (ec2)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002127 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002128 BMCWEB_LOG_DEBUG << "Can't get bmc asset!";
2129 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002130 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002131
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002132 const std::string* partNumber = nullptr;
2133 const std::string* serialNumber = nullptr;
2134 const std::string* manufacturer = nullptr;
2135 const std::string* model = nullptr;
2136 const std::string* sparePartNumber = nullptr;
2137
2138 const bool success = sdbusplus::unpackPropertiesNoThrow(
2139 dbus_utils::UnpackErrorPrinter(), propertiesList,
2140 "PartNumber", partNumber, "SerialNumber",
2141 serialNumber, "Manufacturer", manufacturer, "Model",
2142 model, "SparePartNumber", sparePartNumber);
2143
2144 if (!success)
2145 {
2146 messages::internalError(asyncResp->res);
2147 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002148 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002149
2150 if (partNumber != nullptr)
2151 {
2152 asyncResp->res.jsonValue["PartNumber"] =
2153 *partNumber;
2154 }
2155
2156 if (serialNumber != nullptr)
2157 {
2158 asyncResp->res.jsonValue["SerialNumber"] =
2159 *serialNumber;
2160 }
2161
2162 if (manufacturer != nullptr)
2163 {
2164 asyncResp->res.jsonValue["Manufacturer"] =
2165 *manufacturer;
2166 }
2167
2168 if (model != nullptr)
2169 {
2170 asyncResp->res.jsonValue["Model"] = *model;
2171 }
2172
2173 if (sparePartNumber != nullptr)
2174 {
2175 asyncResp->res.jsonValue["SparePartNumber"] =
2176 *sparePartNumber;
2177 }
2178 });
Ed Tanous002d39b2022-05-31 08:59:27 -07002179 }
2180 else if (interfaceName ==
2181 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
2182 {
2183 getLocation(asyncResp, connectionName, path);
2184 }
2185 }
George Liue99073f2022-12-09 11:06:16 +08002186 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002187 });
2188
2189 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07002190 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002191 .methods(boost::beast::http::verb::patch)(
2192 [&app](const crow::Request& req,
2193 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002194 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002195 {
2196 return;
2197 }
2198 std::optional<nlohmann::json> oem;
2199 std::optional<nlohmann::json> links;
2200 std::optional<std::string> datetime;
2201
2202 if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
2203 "DateTime", datetime, "Links", links))
2204 {
2205 return;
2206 }
2207
2208 if (oem)
2209 {
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002210#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002211 std::optional<nlohmann::json> openbmc;
2212 if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc",
2213 openbmc))
2214 {
2215 BMCWEB_LOG_ERROR
2216 << "Illegal Property "
2217 << oem->dump(2, ' ', true,
2218 nlohmann::json::error_handler_t::replace);
2219 return;
2220 }
2221 if (openbmc)
2222 {
2223 std::optional<nlohmann::json> fan;
2224 if (!redfish::json_util::readJson(*openbmc, asyncResp->res,
2225 "Fan", fan))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002226 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002227 BMCWEB_LOG_ERROR
2228 << "Illegal Property "
2229 << openbmc->dump(
2230 2, ' ', true,
2231 nlohmann::json::error_handler_t::replace);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002232 return;
2233 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002234 if (fan)
2235 {
2236 auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan);
2237 pid->run();
2238 }
2239 }
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002240#else
2241 messages::propertyUnknown(asyncResp->res, "Oem");
2242 return;
2243#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002244 }
2245 if (links)
2246 {
2247 std::optional<nlohmann::json> activeSoftwareImage;
2248 if (!redfish::json_util::readJson(*links, asyncResp->res,
2249 "ActiveSoftwareImage",
2250 activeSoftwareImage))
2251 {
2252 return;
2253 }
2254 if (activeSoftwareImage)
2255 {
2256 std::optional<std::string> odataId;
2257 if (!json_util::readJson(*activeSoftwareImage, asyncResp->res,
2258 "@odata.id", odataId))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002259 {
Ed Tanous45ca1b82022-03-25 13:07:27 -07002260 return;
2261 }
2262
Ed Tanous002d39b2022-05-31 08:59:27 -07002263 if (odataId)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002264 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002265 setActiveFirmwareImage(asyncResp, *odataId);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002266 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002267 }
2268 }
2269 if (datetime)
2270 {
2271 setDateTime(asyncResp, std::move(*datetime));
2272 }
2273 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002274}
2275
2276inline void requestRoutesManagerCollection(App& app)
2277{
2278 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07002279 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002280 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002281 [&app](const crow::Request& req,
2282 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002283 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002284 {
2285 return;
2286 }
2287 // Collections don't include the static data added by SubRoute
2288 // because it has a duplicate entry for members
2289 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
2290 asyncResp->res.jsonValue["@odata.type"] =
2291 "#ManagerCollection.ManagerCollection";
2292 asyncResp->res.jsonValue["Name"] = "Manager Collection";
2293 asyncResp->res.jsonValue["Members@odata.count"] = 1;
2294 nlohmann::json::array_t members;
2295 nlohmann::json& bmc = members.emplace_back();
2296 bmc["@odata.id"] = "/redfish/v1/Managers/bmc";
2297 asyncResp->res.jsonValue["Members"] = std::move(members);
2298 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002299}
Ed Tanous1abe55e2018-09-05 08:30:59 -07002300} // namespace redfish