blob: 56abdcffa5b1ec20312cac4b8fe7618b4034a174 [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
James Feistb49ac872019-05-21 15:12:01 -070018#include "health.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010019#include "node.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080020#include "redfish_util.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010021
James Feist5b4aa862018-08-16 14:07:01 -070022#include <boost/algorithm/string/replace.hpp>
Santosh Puranikaf5d60582019-03-20 18:16:36 +053023#include <boost/date_time.hpp>
James Feist5b4aa862018-08-16 14:07:01 -070024#include <dbus_utility.hpp>
Andrew Geisslere90c5052019-06-28 13:52:27 -050025#include <utils/fw_utils.hpp>
Bernard Wong7bffdb72019-03-20 16:17:21 +080026#include <utils/systemd_utils.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050027
Gunnar Mills4bfefa72020-07-30 13:54:29 -050028#include <cstdint>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050029#include <memory>
30#include <sstream>
Ed Tanousabf2add2019-01-22 16:40:12 -080031#include <variant>
James Feist5b4aa862018-08-16 14:07:01 -070032
Ed Tanous1abe55e2018-09-05 08:30:59 -070033namespace redfish
34{
Jennifer Leeed5befb2018-08-10 11:29:45 -070035
36/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050037 * Function reboots the BMC.
38 *
39 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070040 */
Ed Tanous23a21a12020-07-25 04:45:05 +000041inline void doBMCGracefulRestart(std::shared_ptr<AsyncResp> asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050042{
43 const char* processName = "xyz.openbmc_project.State.BMC";
44 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
45 const char* interfaceName = "xyz.openbmc_project.State.BMC";
46 const std::string& propertyValue =
47 "xyz.openbmc_project.State.BMC.Transition.Reboot";
48 const char* destProperty = "RequestedBMCTransition";
49
50 // Create the D-Bus variant for D-Bus call.
51 VariantType dbusPropertyValue(propertyValue);
52
53 crow::connections::systemBus->async_method_call(
54 [asyncResp](const boost::system::error_code ec) {
55 // Use "Set" method to set the property value.
56 if (ec)
57 {
58 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
59 messages::internalError(asyncResp->res);
60 return;
61 }
62
63 messages::success(asyncResp->res);
64 },
65 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
66 interfaceName, destProperty, dbusPropertyValue);
67}
68
69/**
70 * ManagerResetAction class supports the POST method for the Reset (reboot)
71 * action.
72 */
73class ManagerResetAction : public Node
Jennifer Leeed5befb2018-08-10 11:29:45 -070074{
75 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070076 ManagerResetAction(App& app) :
Jennifer Leeed5befb2018-08-10 11:29:45 -070077 Node(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
78 {
79 entityPrivileges = {
Jennifer Leeed5befb2018-08-10 11:29:45 -070080 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
81 }
82
83 private:
84 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -070085 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -050086 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
87 * OpenBMC only supports ResetType "GracefulRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -070088 */
89 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +000090 const std::vector<std::string>&) override
Jennifer Leeed5befb2018-08-10 11:29:45 -070091 {
Gunnar Mills2a5c4402020-05-19 09:07:24 -050092 BMCWEB_LOG_DEBUG << "Post Manager Reset.";
Jennifer Leeed5befb2018-08-10 11:29:45 -070093
Gunnar Mills2a5c4402020-05-19 09:07:24 -050094 std::string resetType;
95 auto asyncResp = std::make_shared<AsyncResp>(res);
96
97 if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType))
Jennifer Leeed5befb2018-08-10 11:29:45 -070098 {
99 return;
100 }
101
102 if (resetType != "GracefulRestart")
103 {
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500104 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
Jennifer Leeed5befb2018-08-10 11:29:45 -0700105 << resetType;
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500106 messages::actionParameterNotSupported(asyncResp->res, resetType,
107 "ResetType");
108
Jennifer Leeed5befb2018-08-10 11:29:45 -0700109 return;
110 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500111 doBMCGracefulRestart(asyncResp);
Jennifer Leeed5befb2018-08-10 11:29:45 -0700112 }
113};
114
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500115/**
116 * ManagerResetToDefaultsAction class supports POST method for factory reset
117 * action.
118 */
119class ManagerResetToDefaultsAction : public Node
120{
121 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700122 ManagerResetToDefaultsAction(App& app) :
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500123 Node(app, "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
124 {
125 entityPrivileges = {
126 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
127 }
128
129 private:
130 /**
131 * Function handles ResetToDefaults POST method request.
132 *
133 * Analyzes POST body message and factory resets BMC by calling
134 * BMC code updater factory reset followed by a BMC reboot.
135 *
136 * BMC code updater factory reset wipes the whole BMC read-write
137 * filesystem which includes things like the network settings.
138 *
139 * OpenBMC only supports ResetToDefaultsType "ResetAll".
140 */
141 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +0000142 const std::vector<std::string>&) override
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500143 {
144 BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
145
146 std::string resetType;
147 auto asyncResp = std::make_shared<AsyncResp>(res);
148
149 if (!json_util::readJson(req, asyncResp->res, "ResetToDefaultsType",
150 resetType))
151 {
152 BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType.";
153
154 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
155 "ResetToDefaultsType");
156 return;
157 }
158
159 if (resetType != "ResetAll")
160 {
161 BMCWEB_LOG_DEBUG << "Invalid property value for "
162 "ResetToDefaultsType: "
163 << resetType;
164 messages::actionParameterNotSupported(asyncResp->res, resetType,
165 "ResetToDefaultsType");
166 return;
167 }
168
169 crow::connections::systemBus->async_method_call(
170 [asyncResp](const boost::system::error_code ec) {
171 if (ec)
172 {
173 BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec;
174 messages::internalError(asyncResp->res);
175 return;
176 }
177 // Factory Reset doesn't actually happen until a reboot
178 // Can't erase what the BMC is running on
179 doBMCGracefulRestart(asyncResp);
180 },
181 "xyz.openbmc_project.Software.BMC.Updater",
182 "/xyz/openbmc_project/software",
183 "xyz.openbmc_project.Common.FactoryReset", "Reset");
184 }
185};
186
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530187/**
188 * ManagerResetActionInfo derived class for delivering Manager
189 * ResetType AllowableValues using ResetInfo schema.
190 */
191class ManagerResetActionInfo : public Node
192{
193 public:
194 /*
195 * Default Constructor
196 */
Ed Tanous52cc1122020-07-18 13:51:21 -0700197 ManagerResetActionInfo(App& app) :
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530198 Node(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
199 {
200 entityPrivileges = {
201 {boost::beast::http::verb::get, {{"Login"}}},
202 {boost::beast::http::verb::head, {{"Login"}}},
203 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
204 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
205 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
206 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
207 }
208
209 private:
210 /**
211 * Functions triggers appropriate requests on DBus
212 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000213 void doGet(crow::Response& res, const crow::Request&,
214 const std::vector<std::string>&) override
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530215 {
216 res.jsonValue = {
217 {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
218 {"@odata.id", "/redfish/v1/Managers/bmc/ResetActionInfo"},
219 {"Name", "Reset Action Info"},
220 {"Id", "ResetActionInfo"},
221 {"Parameters",
222 {{{"Name", "ResetType"},
223 {"Required", true},
224 {"DataType", "String"},
225 {"AllowableValues", {"GracefulRestart"}}}}}};
226 res.end();
227 }
228};
229
James Feist5b4aa862018-08-16 14:07:01 -0700230static constexpr const char* objectManagerIface =
231 "org.freedesktop.DBus.ObjectManager";
232static constexpr const char* pidConfigurationIface =
233 "xyz.openbmc_project.Configuration.Pid";
234static constexpr const char* pidZoneConfigurationIface =
235 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feistb7a08d02018-12-11 14:55:37 -0800236static constexpr const char* stepwiseConfigurationIface =
237 "xyz.openbmc_project.Configuration.Stepwise";
James Feist73df0db2019-03-25 15:29:35 -0700238static constexpr const char* thermalModeIface =
239 "xyz.openbmc_project.Control.ThermalMode";
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100240
Ed Tanous23a21a12020-07-25 04:45:05 +0000241inline void asyncPopulatePid(const std::string& connection,
James Feist5b4aa862018-08-16 14:07:01 -0700242 const std::string& path,
James Feist73df0db2019-03-25 15:29:35 -0700243 const std::string& currentProfile,
244 const std::vector<std::string>& supportedProfiles,
James Feist5b4aa862018-08-16 14:07:01 -0700245 std::shared_ptr<AsyncResp> asyncResp)
246{
247
248 crow::connections::systemBus->async_method_call(
James Feist73df0db2019-03-25 15:29:35 -0700249 [asyncResp, currentProfile, supportedProfiles](
250 const boost::system::error_code ec,
251 const dbus::utility::ManagedObjectType& managedObj) {
James Feist5b4aa862018-08-16 14:07:01 -0700252 if (ec)
253 {
254 BMCWEB_LOG_ERROR << ec;
James Feist5b4aa862018-08-16 14:07:01 -0700255 asyncResp->res.jsonValue.clear();
Jason M. Billsf12894f2018-10-09 12:45:45 -0700256 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700257 return;
258 }
259 nlohmann::json& configRoot =
260 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"];
261 nlohmann::json& fans = configRoot["FanControllers"];
262 fans["@odata.type"] = "#OemManager.FanControllers";
James Feist5b4aa862018-08-16 14:07:01 -0700263 fans["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/"
264 "Fan/FanControllers";
265
266 nlohmann::json& pids = configRoot["PidControllers"];
267 pids["@odata.type"] = "#OemManager.PidControllers";
James Feist5b4aa862018-08-16 14:07:01 -0700268 pids["@odata.id"] =
269 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers";
270
James Feistb7a08d02018-12-11 14:55:37 -0800271 nlohmann::json& stepwise = configRoot["StepwiseControllers"];
272 stepwise["@odata.type"] = "#OemManager.StepwiseControllers";
James Feistb7a08d02018-12-11 14:55:37 -0800273 stepwise["@odata.id"] =
274 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers";
275
James Feist5b4aa862018-08-16 14:07:01 -0700276 nlohmann::json& zones = configRoot["FanZones"];
277 zones["@odata.id"] =
278 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones";
279 zones["@odata.type"] = "#OemManager.FanZones";
James Feist5b4aa862018-08-16 14:07:01 -0700280 configRoot["@odata.id"] =
281 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan";
282 configRoot["@odata.type"] = "#OemManager.Fan";
James Feist73df0db2019-03-25 15:29:35 -0700283 configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles;
284
285 if (!currentProfile.empty())
286 {
287 configRoot["Profile"] = currentProfile;
288 }
289 BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !";
James Feist5b4aa862018-08-16 14:07:01 -0700290
James Feist5b4aa862018-08-16 14:07:01 -0700291 for (const auto& pathPair : managedObj)
292 {
293 for (const auto& intfPair : pathPair.second)
294 {
295 if (intfPair.first != pidConfigurationIface &&
James Feistb7a08d02018-12-11 14:55:37 -0800296 intfPair.first != pidZoneConfigurationIface &&
297 intfPair.first != stepwiseConfigurationIface)
James Feist5b4aa862018-08-16 14:07:01 -0700298 {
299 continue;
300 }
301 auto findName = intfPair.second.find("Name");
302 if (findName == intfPair.second.end())
303 {
304 BMCWEB_LOG_ERROR << "Pid Field missing Name";
Jason M. Billsa08b46c2018-11-06 15:01:08 -0800305 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700306 return;
307 }
James Feist73df0db2019-03-25 15:29:35 -0700308
James Feist5b4aa862018-08-16 14:07:01 -0700309 const std::string* namePtr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800310 std::get_if<std::string>(&findName->second);
James Feist5b4aa862018-08-16 14:07:01 -0700311 if (namePtr == nullptr)
312 {
313 BMCWEB_LOG_ERROR << "Pid Name Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800314 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700315 return;
316 }
James Feist5b4aa862018-08-16 14:07:01 -0700317 std::string name = *namePtr;
318 dbus::utility::escapePathForDbus(name);
James Feist73df0db2019-03-25 15:29:35 -0700319
320 auto findProfiles = intfPair.second.find("Profiles");
321 if (findProfiles != intfPair.second.end())
322 {
323 const std::vector<std::string>* profiles =
324 std::get_if<std::vector<std::string>>(
325 &findProfiles->second);
326 if (profiles == nullptr)
327 {
328 BMCWEB_LOG_ERROR << "Pid Profiles Field illegal";
329 messages::internalError(asyncResp->res);
330 return;
331 }
332 if (std::find(profiles->begin(), profiles->end(),
333 currentProfile) == profiles->end())
334 {
335 BMCWEB_LOG_INFO
336 << name << " not supported in current profile";
337 continue;
338 }
339 }
James Feistb7a08d02018-12-11 14:55:37 -0800340 nlohmann::json* config = nullptr;
James Feistc33a90e2019-03-01 10:17:44 -0800341
342 const std::string* classPtr = nullptr;
343 auto findClass = intfPair.second.find("Class");
344 if (findClass != intfPair.second.end())
345 {
346 classPtr = std::get_if<std::string>(&findClass->second);
347 }
348
James Feist5b4aa862018-08-16 14:07:01 -0700349 if (intfPair.first == pidZoneConfigurationIface)
350 {
351 std::string chassis;
352 if (!dbus::utility::getNthStringFromPath(
353 pathPair.first.str, 5, chassis))
354 {
355 chassis = "#IllegalValue";
356 }
357 nlohmann::json& zone = zones[name];
358 zone["Chassis"] = {
359 {"@odata.id", "/redfish/v1/Chassis/" + chassis}};
360 zone["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/"
361 "OpenBmc/Fan/FanZones/" +
362 name;
363 zone["@odata.type"] = "#OemManager.FanZone";
James Feistb7a08d02018-12-11 14:55:37 -0800364 config = &zone;
James Feist5b4aa862018-08-16 14:07:01 -0700365 }
366
James Feistb7a08d02018-12-11 14:55:37 -0800367 else if (intfPair.first == stepwiseConfigurationIface)
368 {
James Feistc33a90e2019-03-01 10:17:44 -0800369 if (classPtr == nullptr)
370 {
371 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
372 messages::internalError(asyncResp->res);
373 return;
374 }
375
James Feistb7a08d02018-12-11 14:55:37 -0800376 nlohmann::json& controller = stepwise[name];
377 config = &controller;
378
379 controller["@odata.id"] =
380 "/redfish/v1/Managers/bmc#/Oem/"
381 "OpenBmc/Fan/StepwiseControllers/" +
Ed Tanous271584a2019-07-09 16:24:22 -0700382 name;
James Feistb7a08d02018-12-11 14:55:37 -0800383 controller["@odata.type"] =
384 "#OemManager.StepwiseController";
385
James Feistc33a90e2019-03-01 10:17:44 -0800386 controller["Direction"] = *classPtr;
James Feistb7a08d02018-12-11 14:55:37 -0800387 }
388
389 // pid and fans are off the same configuration
390 else if (intfPair.first == pidConfigurationIface)
391 {
James Feistc33a90e2019-03-01 10:17:44 -0800392
James Feistb7a08d02018-12-11 14:55:37 -0800393 if (classPtr == nullptr)
394 {
395 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
396 messages::internalError(asyncResp->res);
397 return;
398 }
399 bool isFan = *classPtr == "fan";
400 nlohmann::json& element =
401 isFan ? fans[name] : pids[name];
402 config = &element;
403 if (isFan)
404 {
405 element["@odata.id"] =
406 "/redfish/v1/Managers/bmc#/Oem/"
407 "OpenBmc/Fan/FanControllers/" +
Ed Tanous271584a2019-07-09 16:24:22 -0700408 name;
James Feistb7a08d02018-12-11 14:55:37 -0800409 element["@odata.type"] =
410 "#OemManager.FanController";
James Feistb7a08d02018-12-11 14:55:37 -0800411 }
412 else
413 {
414 element["@odata.id"] =
415 "/redfish/v1/Managers/bmc#/Oem/"
416 "OpenBmc/Fan/PidControllers/" +
Ed Tanous271584a2019-07-09 16:24:22 -0700417 name;
James Feistb7a08d02018-12-11 14:55:37 -0800418 element["@odata.type"] =
419 "#OemManager.PidController";
James Feistb7a08d02018-12-11 14:55:37 -0800420 }
421 }
422 else
423 {
424 BMCWEB_LOG_ERROR << "Unexpected configuration";
425 messages::internalError(asyncResp->res);
426 return;
427 }
428
429 // used for making maps out of 2 vectors
430 const std::vector<double>* keys = nullptr;
431 const std::vector<double>* values = nullptr;
432
James Feist5b4aa862018-08-16 14:07:01 -0700433 for (const auto& propertyPair : intfPair.second)
434 {
435 if (propertyPair.first == "Type" ||
436 propertyPair.first == "Class" ||
437 propertyPair.first == "Name")
438 {
439 continue;
440 }
441
442 // zones
443 if (intfPair.first == pidZoneConfigurationIface)
444 {
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800445 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800446 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700447 if (ptr == nullptr)
448 {
449 BMCWEB_LOG_ERROR << "Field Illegal "
450 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700451 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700452 return;
453 }
James Feistb7a08d02018-12-11 14:55:37 -0800454 (*config)[propertyPair.first] = *ptr;
455 }
456
457 if (intfPair.first == stepwiseConfigurationIface)
458 {
459 if (propertyPair.first == "Reading" ||
460 propertyPair.first == "Output")
461 {
462 const std::vector<double>* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800463 std::get_if<std::vector<double>>(
James Feistb7a08d02018-12-11 14:55:37 -0800464 &propertyPair.second);
465
466 if (ptr == nullptr)
467 {
468 BMCWEB_LOG_ERROR << "Field Illegal "
469 << propertyPair.first;
470 messages::internalError(asyncResp->res);
471 return;
472 }
473
474 if (propertyPair.first == "Reading")
475 {
476 keys = ptr;
477 }
478 else
479 {
480 values = ptr;
481 }
482 if (keys && values)
483 {
484 if (keys->size() != values->size())
485 {
486 BMCWEB_LOG_ERROR
487 << "Reading and Output size don't "
488 "match ";
489 messages::internalError(asyncResp->res);
490 return;
491 }
492 nlohmann::json& steps = (*config)["Steps"];
493 steps = nlohmann::json::array();
494 for (size_t ii = 0; ii < keys->size(); ii++)
495 {
496 steps.push_back(
497 {{"Target", (*keys)[ii]},
498 {"Output", (*values)[ii]}});
499 }
500 }
501 }
502 if (propertyPair.first == "NegativeHysteresis" ||
503 propertyPair.first == "PositiveHysteresis")
504 {
505 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800506 std::get_if<double>(&propertyPair.second);
James Feistb7a08d02018-12-11 14:55:37 -0800507 if (ptr == nullptr)
508 {
509 BMCWEB_LOG_ERROR << "Field Illegal "
510 << propertyPair.first;
511 messages::internalError(asyncResp->res);
512 return;
513 }
514 (*config)[propertyPair.first] = *ptr;
515 }
James Feist5b4aa862018-08-16 14:07:01 -0700516 }
517
518 // pid and fans are off the same configuration
James Feistb7a08d02018-12-11 14:55:37 -0800519 if (intfPair.first == pidConfigurationIface ||
520 intfPair.first == stepwiseConfigurationIface)
James Feist5b4aa862018-08-16 14:07:01 -0700521 {
James Feist5b4aa862018-08-16 14:07:01 -0700522
523 if (propertyPair.first == "Zones")
524 {
525 const std::vector<std::string>* inputs =
Ed Tanousabf2add2019-01-22 16:40:12 -0800526 std::get_if<std::vector<std::string>>(
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800527 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700528
529 if (inputs == nullptr)
530 {
531 BMCWEB_LOG_ERROR
532 << "Zones Pid Field Illegal";
Jason M. Billsa08b46c2018-11-06 15:01:08 -0800533 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700534 return;
535 }
James Feistb7a08d02018-12-11 14:55:37 -0800536 auto& data = (*config)[propertyPair.first];
James Feist5b4aa862018-08-16 14:07:01 -0700537 data = nlohmann::json::array();
538 for (std::string itemCopy : *inputs)
539 {
540 dbus::utility::escapePathForDbus(itemCopy);
541 data.push_back(
542 {{"@odata.id",
543 "/redfish/v1/Managers/bmc#/Oem/"
544 "OpenBmc/Fan/FanZones/" +
545 itemCopy}});
546 }
547 }
548 // todo(james): may never happen, but this
549 // assumes configuration data referenced in the
550 // PID config is provided by the same daemon, we
551 // could add another loop to cover all cases,
552 // but I'm okay kicking this can down the road a
553 // bit
554
555 else if (propertyPair.first == "Inputs" ||
556 propertyPair.first == "Outputs")
557 {
James Feistb7a08d02018-12-11 14:55:37 -0800558 auto& data = (*config)[propertyPair.first];
James Feist5b4aa862018-08-16 14:07:01 -0700559 const std::vector<std::string>* inputs =
Ed Tanousabf2add2019-01-22 16:40:12 -0800560 std::get_if<std::vector<std::string>>(
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800561 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700562
563 if (inputs == nullptr)
564 {
565 BMCWEB_LOG_ERROR << "Field Illegal "
566 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700567 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700568 return;
569 }
570 data = *inputs;
James Feistb943aae2019-07-11 16:33:56 -0700571 }
572 else if (propertyPair.first == "SetPointOffset")
573 {
574 const std::string* ptr =
575 std::get_if<std::string>(
576 &propertyPair.second);
577
578 if (ptr == nullptr)
579 {
580 BMCWEB_LOG_ERROR << "Field Illegal "
581 << propertyPair.first;
582 messages::internalError(asyncResp->res);
583 return;
584 }
585 // translate from dbus to redfish
586 if (*ptr == "WarningHigh")
587 {
588 (*config)["SetPointOffset"] =
589 "UpperThresholdNonCritical";
590 }
591 else if (*ptr == "WarningLow")
592 {
593 (*config)["SetPointOffset"] =
594 "LowerThresholdNonCritical";
595 }
596 else if (*ptr == "CriticalHigh")
597 {
598 (*config)["SetPointOffset"] =
599 "UpperThresholdCritical";
600 }
601 else if (*ptr == "CriticalLow")
602 {
603 (*config)["SetPointOffset"] =
604 "LowerThresholdCritical";
605 }
606 else
607 {
608 BMCWEB_LOG_ERROR << "Value Illegal "
609 << *ptr;
610 messages::internalError(asyncResp->res);
611 return;
612 }
613 }
614 // doubles
James Feist5b4aa862018-08-16 14:07:01 -0700615 else if (propertyPair.first ==
616 "FFGainCoefficient" ||
617 propertyPair.first == "FFOffCoefficient" ||
618 propertyPair.first == "ICoefficient" ||
619 propertyPair.first == "ILimitMax" ||
620 propertyPair.first == "ILimitMin" ||
James Feistaad1a252019-02-19 10:13:52 -0800621 propertyPair.first ==
622 "PositiveHysteresis" ||
623 propertyPair.first ==
624 "NegativeHysteresis" ||
James Feist5b4aa862018-08-16 14:07:01 -0700625 propertyPair.first == "OutLimitMax" ||
626 propertyPair.first == "OutLimitMin" ||
627 propertyPair.first == "PCoefficient" ||
James Feist7625cb82019-01-23 11:58:21 -0800628 propertyPair.first == "SetPoint" ||
James Feist5b4aa862018-08-16 14:07:01 -0700629 propertyPair.first == "SlewNeg" ||
630 propertyPair.first == "SlewPos")
631 {
632 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800633 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700634 if (ptr == nullptr)
635 {
636 BMCWEB_LOG_ERROR << "Field Illegal "
637 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700638 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700639 return;
640 }
James Feistb7a08d02018-12-11 14:55:37 -0800641 (*config)[propertyPair.first] = *ptr;
James Feist5b4aa862018-08-16 14:07:01 -0700642 }
643 }
644 }
645 }
646 }
647 },
648 connection, path, objectManagerIface, "GetManagedObjects");
649}
Jennifer Leeca537922018-08-10 10:07:30 -0700650
James Feist83ff9ab2018-08-31 10:18:24 -0700651enum class CreatePIDRet
652{
653 fail,
654 del,
655 patch
656};
657
Ed Tanous23a21a12020-07-25 04:45:05 +0000658inline bool getZonesFromJsonReq(const std::shared_ptr<AsyncResp>& response,
James Feist5f2caae2018-12-12 14:08:25 -0800659 std::vector<nlohmann::json>& config,
660 std::vector<std::string>& zones)
661{
James Feistb6baeaa2019-02-21 10:41:40 -0800662 if (config.empty())
663 {
664 BMCWEB_LOG_ERROR << "Empty Zones";
665 messages::propertyValueFormatError(response->res,
666 nlohmann::json::array(), "Zones");
667 return false;
668 }
James Feist5f2caae2018-12-12 14:08:25 -0800669 for (auto& odata : config)
670 {
671 std::string path;
672 if (!redfish::json_util::readJson(odata, response->res, "@odata.id",
673 path))
674 {
675 return false;
676 }
677 std::string input;
James Feist61adbda2019-03-25 13:03:51 -0700678
679 // 8 below comes from
680 // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left
681 // 0 1 2 3 4 5 6 7 8
682 if (!dbus::utility::getNthStringFromPath(path, 8, input))
James Feist5f2caae2018-12-12 14:08:25 -0800683 {
684 BMCWEB_LOG_ERROR << "Got invalid path " << path;
685 BMCWEB_LOG_ERROR << "Illegal Type Zones";
686 messages::propertyValueFormatError(response->res, odata.dump(),
687 "Zones");
688 return false;
689 }
690 boost::replace_all(input, "_", " ");
691 zones.emplace_back(std::move(input));
692 }
693 return true;
694}
695
Ed Tanous23a21a12020-07-25 04:45:05 +0000696inline const dbus::utility::ManagedItem*
James Feist73df0db2019-03-25 15:29:35 -0700697 findChassis(const dbus::utility::ManagedObjectType& managedObj,
698 const std::string& value, std::string& chassis)
James Feistb6baeaa2019-02-21 10:41:40 -0800699{
700 BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n";
701
702 std::string escaped = boost::replace_all_copy(value, " ", "_");
703 escaped = "/" + escaped;
704 auto it = std::find_if(
705 managedObj.begin(), managedObj.end(), [&escaped](const auto& obj) {
706 if (boost::algorithm::ends_with(obj.first.str, escaped))
707 {
708 BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n";
709 return true;
710 }
711 return false;
712 });
713
714 if (it == managedObj.end())
715 {
James Feist73df0db2019-03-25 15:29:35 -0700716 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800717 }
718 // 5 comes from <chassis-name> being the 5th element
719 // /xyz/openbmc_project/inventory/system/chassis/<chassis-name>
James Feist73df0db2019-03-25 15:29:35 -0700720 if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis))
721 {
722 return &(*it);
723 }
724
725 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800726}
727
Ed Tanous23a21a12020-07-25 04:45:05 +0000728inline CreatePIDRet createPidInterface(
James Feist83ff9ab2018-08-31 10:18:24 -0700729 const std::shared_ptr<AsyncResp>& response, const std::string& type,
James Feistb6baeaa2019-02-21 10:41:40 -0800730 nlohmann::json::iterator it, const std::string& path,
James Feist83ff9ab2018-08-31 10:18:24 -0700731 const dbus::utility::ManagedObjectType& managedObj, bool createNewObject,
732 boost::container::flat_map<std::string, dbus::utility::DbusVariantType>&
733 output,
James Feist73df0db2019-03-25 15:29:35 -0700734 std::string& chassis, const std::string& profile)
James Feist83ff9ab2018-08-31 10:18:24 -0700735{
736
James Feist5f2caae2018-12-12 14:08:25 -0800737 // common deleter
James Feistb6baeaa2019-02-21 10:41:40 -0800738 if (it.value() == nullptr)
James Feist5f2caae2018-12-12 14:08:25 -0800739 {
740 std::string iface;
741 if (type == "PidControllers" || type == "FanControllers")
742 {
743 iface = pidConfigurationIface;
744 }
745 else if (type == "FanZones")
746 {
747 iface = pidZoneConfigurationIface;
748 }
749 else if (type == "StepwiseControllers")
750 {
751 iface = stepwiseConfigurationIface;
752 }
753 else
754 {
755 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type "
756 << type;
757 messages::propertyUnknown(response->res, type);
758 return CreatePIDRet::fail;
759 }
James Feist6ee7f772020-02-06 16:25:27 -0800760
761 BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n";
James Feist5f2caae2018-12-12 14:08:25 -0800762 // delete interface
763 crow::connections::systemBus->async_method_call(
764 [response, path](const boost::system::error_code ec) {
765 if (ec)
766 {
767 BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec;
768 messages::internalError(response->res);
James Feistb6baeaa2019-02-21 10:41:40 -0800769 return;
James Feist5f2caae2018-12-12 14:08:25 -0800770 }
James Feistb6baeaa2019-02-21 10:41:40 -0800771 messages::success(response->res);
James Feist5f2caae2018-12-12 14:08:25 -0800772 },
773 "xyz.openbmc_project.EntityManager", path, iface, "Delete");
774 return CreatePIDRet::del;
775 }
776
James Feist73df0db2019-03-25 15:29:35 -0700777 const dbus::utility::ManagedItem* managedItem = nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800778 if (!createNewObject)
779 {
780 // if we aren't creating a new object, we should be able to find it on
781 // d-bus
James Feist73df0db2019-03-25 15:29:35 -0700782 managedItem = findChassis(managedObj, it.key(), chassis);
783 if (managedItem == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800784 {
785 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
786 messages::invalidObject(response->res, it.key());
787 return CreatePIDRet::fail;
788 }
789 }
790
James Feist73df0db2019-03-25 15:29:35 -0700791 if (profile.size() &&
792 (type == "PidControllers" || type == "FanControllers" ||
793 type == "StepwiseControllers"))
794 {
795 if (managedItem == nullptr)
796 {
797 output["Profiles"] = std::vector<std::string>{profile};
798 }
799 else
800 {
801 std::string interface;
802 if (type == "StepwiseControllers")
803 {
804 interface = stepwiseConfigurationIface;
805 }
806 else
807 {
808 interface = pidConfigurationIface;
809 }
810 auto findConfig = managedItem->second.find(interface);
811 if (findConfig == managedItem->second.end())
812 {
813 BMCWEB_LOG_ERROR
814 << "Failed to find interface in managed object";
815 messages::internalError(response->res);
816 return CreatePIDRet::fail;
817 }
818 auto findProfiles = findConfig->second.find("Profiles");
819 if (findProfiles != findConfig->second.end())
820 {
821 const std::vector<std::string>* curProfiles =
822 std::get_if<std::vector<std::string>>(
823 &(findProfiles->second));
824 if (curProfiles == nullptr)
825 {
826 BMCWEB_LOG_ERROR << "Illegal profiles in managed object";
827 messages::internalError(response->res);
828 return CreatePIDRet::fail;
829 }
830 if (std::find(curProfiles->begin(), curProfiles->end(),
831 profile) == curProfiles->end())
832 {
833 std::vector<std::string> newProfiles = *curProfiles;
834 newProfiles.push_back(profile);
835 output["Profiles"] = newProfiles;
836 }
837 }
838 }
839 }
840
James Feist83ff9ab2018-08-31 10:18:24 -0700841 if (type == "PidControllers" || type == "FanControllers")
842 {
843 if (createNewObject)
844 {
845 output["Class"] = type == "PidControllers" ? std::string("temp")
846 : std::string("fan");
847 output["Type"] = std::string("Pid");
848 }
James Feist5f2caae2018-12-12 14:08:25 -0800849
850 std::optional<std::vector<nlohmann::json>> zones;
851 std::optional<std::vector<std::string>> inputs;
852 std::optional<std::vector<std::string>> outputs;
853 std::map<std::string, std::optional<double>> doubles;
James Feistb943aae2019-07-11 16:33:56 -0700854 std::optional<std::string> setpointOffset;
James Feist5f2caae2018-12-12 14:08:25 -0800855 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -0800856 it.value(), response->res, "Inputs", inputs, "Outputs", outputs,
James Feist5f2caae2018-12-12 14:08:25 -0800857 "Zones", zones, "FFGainCoefficient",
858 doubles["FFGainCoefficient"], "FFOffCoefficient",
859 doubles["FFOffCoefficient"], "ICoefficient",
860 doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"],
861 "ILimitMin", doubles["ILimitMin"], "OutLimitMax",
862 doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"],
863 "PCoefficient", doubles["PCoefficient"], "SetPoint",
James Feistb943aae2019-07-11 16:33:56 -0700864 doubles["SetPoint"], "SetPointOffset", setpointOffset,
865 "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"],
866 "PositiveHysteresis", doubles["PositiveHysteresis"],
867 "NegativeHysteresis", doubles["NegativeHysteresis"]))
James Feist83ff9ab2018-08-31 10:18:24 -0700868 {
James Feist5f2caae2018-12-12 14:08:25 -0800869 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
James Feistb6baeaa2019-02-21 10:41:40 -0800870 << it.value().dump();
James Feist5f2caae2018-12-12 14:08:25 -0800871 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700872 }
James Feist5f2caae2018-12-12 14:08:25 -0800873 if (zones)
James Feist83ff9ab2018-08-31 10:18:24 -0700874 {
James Feist5f2caae2018-12-12 14:08:25 -0800875 std::vector<std::string> zonesStr;
876 if (!getZonesFromJsonReq(response, *zones, zonesStr))
James Feist83ff9ab2018-08-31 10:18:24 -0700877 {
James Feist5f2caae2018-12-12 14:08:25 -0800878 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones";
879 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700880 }
James Feistb6baeaa2019-02-21 10:41:40 -0800881 if (chassis.empty() &&
882 !findChassis(managedObj, zonesStr[0], chassis))
883 {
884 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
885 messages::invalidObject(response->res, it.key());
886 return CreatePIDRet::fail;
887 }
888
James Feist5f2caae2018-12-12 14:08:25 -0800889 output["Zones"] = std::move(zonesStr);
890 }
891 if (inputs || outputs)
892 {
893 std::array<std::optional<std::vector<std::string>>*, 2> containers =
894 {&inputs, &outputs};
895 size_t index = 0;
896 for (const auto& containerPtr : containers)
James Feist83ff9ab2018-08-31 10:18:24 -0700897 {
James Feist5f2caae2018-12-12 14:08:25 -0800898 std::optional<std::vector<std::string>>& container =
899 *containerPtr;
900 if (!container)
James Feist83ff9ab2018-08-31 10:18:24 -0700901 {
James Feist5f2caae2018-12-12 14:08:25 -0800902 index++;
903 continue;
James Feist83ff9ab2018-08-31 10:18:24 -0700904 }
James Feist5f2caae2018-12-12 14:08:25 -0800905
906 for (std::string& value : *container)
James Feist83ff9ab2018-08-31 10:18:24 -0700907 {
James Feist5f2caae2018-12-12 14:08:25 -0800908 boost::replace_all(value, "_", " ");
James Feist83ff9ab2018-08-31 10:18:24 -0700909 }
James Feist5f2caae2018-12-12 14:08:25 -0800910 std::string key;
911 if (index == 0)
James Feist83ff9ab2018-08-31 10:18:24 -0700912 {
James Feist5f2caae2018-12-12 14:08:25 -0800913 key = "Inputs";
James Feist83ff9ab2018-08-31 10:18:24 -0700914 }
James Feist5f2caae2018-12-12 14:08:25 -0800915 else
916 {
917 key = "Outputs";
918 }
919 output[key] = *container;
920 index++;
James Feist83ff9ab2018-08-31 10:18:24 -0700921 }
James Feist5f2caae2018-12-12 14:08:25 -0800922 }
James Feist83ff9ab2018-08-31 10:18:24 -0700923
James Feistb943aae2019-07-11 16:33:56 -0700924 if (setpointOffset)
925 {
926 // translate between redfish and dbus names
927 if (*setpointOffset == "UpperThresholdNonCritical")
928 {
929 output["SetPointOffset"] = std::string("WarningLow");
930 }
931 else if (*setpointOffset == "LowerThresholdNonCritical")
932 {
933 output["SetPointOffset"] = std::string("WarningHigh");
934 }
935 else if (*setpointOffset == "LowerThresholdCritical")
936 {
937 output["SetPointOffset"] = std::string("CriticalLow");
938 }
939 else if (*setpointOffset == "UpperThresholdCritical")
940 {
941 output["SetPointOffset"] = std::string("CriticalHigh");
942 }
943 else
944 {
945 BMCWEB_LOG_ERROR << "Invalid setpointoffset "
946 << *setpointOffset;
947 messages::invalidObject(response->res, it.key());
948 return CreatePIDRet::fail;
949 }
950 }
951
James Feist5f2caae2018-12-12 14:08:25 -0800952 // doubles
953 for (const auto& pairs : doubles)
954 {
955 if (!pairs.second)
James Feist83ff9ab2018-08-31 10:18:24 -0700956 {
James Feist5f2caae2018-12-12 14:08:25 -0800957 continue;
James Feist83ff9ab2018-08-31 10:18:24 -0700958 }
James Feist5f2caae2018-12-12 14:08:25 -0800959 BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second;
960 output[pairs.first] = *(pairs.second);
James Feist83ff9ab2018-08-31 10:18:24 -0700961 }
962 }
James Feist5f2caae2018-12-12 14:08:25 -0800963
James Feist83ff9ab2018-08-31 10:18:24 -0700964 else if (type == "FanZones")
965 {
James Feist83ff9ab2018-08-31 10:18:24 -0700966 output["Type"] = std::string("Pid.Zone");
967
James Feist5f2caae2018-12-12 14:08:25 -0800968 std::optional<nlohmann::json> chassisContainer;
969 std::optional<double> failSafePercent;
James Feistd3ec07f2019-02-25 14:51:15 -0800970 std::optional<double> minThermalOutput;
James Feistb6baeaa2019-02-21 10:41:40 -0800971 if (!redfish::json_util::readJson(it.value(), response->res, "Chassis",
James Feist5f2caae2018-12-12 14:08:25 -0800972 chassisContainer, "FailSafePercent",
James Feistd3ec07f2019-02-25 14:51:15 -0800973 failSafePercent, "MinThermalOutput",
974 minThermalOutput))
James Feist83ff9ab2018-08-31 10:18:24 -0700975 {
James Feist5f2caae2018-12-12 14:08:25 -0800976 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
James Feistb6baeaa2019-02-21 10:41:40 -0800977 << it.value().dump();
James Feist5f2caae2018-12-12 14:08:25 -0800978 return CreatePIDRet::fail;
979 }
James Feist83ff9ab2018-08-31 10:18:24 -0700980
James Feist5f2caae2018-12-12 14:08:25 -0800981 if (chassisContainer)
982 {
983
984 std::string chassisId;
985 if (!redfish::json_util::readJson(*chassisContainer, response->res,
986 "@odata.id", chassisId))
James Feist83ff9ab2018-08-31 10:18:24 -0700987 {
James Feist5f2caae2018-12-12 14:08:25 -0800988 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
989 << chassisContainer->dump();
James Feist83ff9ab2018-08-31 10:18:24 -0700990 return CreatePIDRet::fail;
991 }
James Feist5f2caae2018-12-12 14:08:25 -0800992
AppaRao Puli717794d2019-10-18 22:54:53 +0530993 // /redfish/v1/chassis/chassis_name/
James Feist5f2caae2018-12-12 14:08:25 -0800994 if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis))
995 {
996 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
997 messages::invalidObject(response->res, chassisId);
998 return CreatePIDRet::fail;
999 }
1000 }
James Feistd3ec07f2019-02-25 14:51:15 -08001001 if (minThermalOutput)
James Feist5f2caae2018-12-12 14:08:25 -08001002 {
James Feistd3ec07f2019-02-25 14:51:15 -08001003 output["MinThermalOutput"] = *minThermalOutput;
James Feist5f2caae2018-12-12 14:08:25 -08001004 }
1005 if (failSafePercent)
1006 {
1007 output["FailSafePercent"] = *failSafePercent;
1008 }
1009 }
1010 else if (type == "StepwiseControllers")
1011 {
1012 output["Type"] = std::string("Stepwise");
1013
1014 std::optional<std::vector<nlohmann::json>> zones;
1015 std::optional<std::vector<nlohmann::json>> steps;
1016 std::optional<std::vector<std::string>> inputs;
1017 std::optional<double> positiveHysteresis;
1018 std::optional<double> negativeHysteresis;
James Feistc33a90e2019-03-01 10:17:44 -08001019 std::optional<std::string> direction; // upper clipping curve vs lower
James Feist5f2caae2018-12-12 14:08:25 -08001020 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -08001021 it.value(), response->res, "Zones", zones, "Steps", steps,
1022 "Inputs", inputs, "PositiveHysteresis", positiveHysteresis,
James Feistc33a90e2019-03-01 10:17:44 -08001023 "NegativeHysteresis", negativeHysteresis, "Direction",
1024 direction))
James Feist5f2caae2018-12-12 14:08:25 -08001025 {
1026 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
James Feistb6baeaa2019-02-21 10:41:40 -08001027 << it.value().dump();
James Feist5f2caae2018-12-12 14:08:25 -08001028 return CreatePIDRet::fail;
1029 }
1030
1031 if (zones)
1032 {
James Feistb6baeaa2019-02-21 10:41:40 -08001033 std::vector<std::string> zonesStrs;
1034 if (!getZonesFromJsonReq(response, *zones, zonesStrs))
James Feist5f2caae2018-12-12 14:08:25 -08001035 {
1036 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Zones";
1037 return CreatePIDRet::fail;
1038 }
James Feistb6baeaa2019-02-21 10:41:40 -08001039 if (chassis.empty() &&
1040 !findChassis(managedObj, zonesStrs[0], chassis))
1041 {
1042 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
1043 messages::invalidObject(response->res, it.key());
1044 return CreatePIDRet::fail;
1045 }
1046 output["Zones"] = std::move(zonesStrs);
James Feist5f2caae2018-12-12 14:08:25 -08001047 }
1048 if (steps)
1049 {
1050 std::vector<double> readings;
1051 std::vector<double> outputs;
1052 for (auto& step : *steps)
1053 {
1054 double target;
Ed Tanous23a21a12020-07-25 04:45:05 +00001055 double out;
James Feist5f2caae2018-12-12 14:08:25 -08001056
1057 if (!redfish::json_util::readJson(step, response->res, "Target",
Ed Tanous23a21a12020-07-25 04:45:05 +00001058 target, "Output", out))
James Feist5f2caae2018-12-12 14:08:25 -08001059 {
1060 BMCWEB_LOG_ERROR << "Line:" << __LINE__
James Feistb6baeaa2019-02-21 10:41:40 -08001061 << ", Illegal Property "
1062 << it.value().dump();
James Feist5f2caae2018-12-12 14:08:25 -08001063 return CreatePIDRet::fail;
1064 }
1065 readings.emplace_back(target);
Ed Tanous23a21a12020-07-25 04:45:05 +00001066 outputs.emplace_back(out);
James Feist5f2caae2018-12-12 14:08:25 -08001067 }
1068 output["Reading"] = std::move(readings);
1069 output["Output"] = std::move(outputs);
1070 }
1071 if (inputs)
1072 {
1073 for (std::string& value : *inputs)
1074 {
James Feist5f2caae2018-12-12 14:08:25 -08001075 boost::replace_all(value, "_", " ");
1076 }
1077 output["Inputs"] = std::move(*inputs);
1078 }
1079 if (negativeHysteresis)
1080 {
1081 output["NegativeHysteresis"] = *negativeHysteresis;
1082 }
1083 if (positiveHysteresis)
1084 {
1085 output["PositiveHysteresis"] = *positiveHysteresis;
James Feist83ff9ab2018-08-31 10:18:24 -07001086 }
James Feistc33a90e2019-03-01 10:17:44 -08001087 if (direction)
1088 {
1089 constexpr const std::array<const char*, 2> allowedDirections = {
1090 "Ceiling", "Floor"};
1091 if (std::find(allowedDirections.begin(), allowedDirections.end(),
1092 *direction) == allowedDirections.end())
1093 {
1094 messages::propertyValueTypeError(response->res, "Direction",
1095 *direction);
1096 return CreatePIDRet::fail;
1097 }
1098 output["Class"] = *direction;
1099 }
James Feist83ff9ab2018-08-31 10:18:24 -07001100 }
1101 else
1102 {
James Feist5f2caae2018-12-12 14:08:25 -08001103 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Type " << type;
Jason M. Bills35a62c72018-10-09 12:45:45 -07001104 messages::propertyUnknown(response->res, type);
James Feist83ff9ab2018-08-31 10:18:24 -07001105 return CreatePIDRet::fail;
1106 }
1107 return CreatePIDRet::patch;
1108}
James Feist73df0db2019-03-25 15:29:35 -07001109struct GetPIDValues : std::enable_shared_from_this<GetPIDValues>
1110{
1111
Ed Tanous23a21a12020-07-25 04:45:05 +00001112 GetPIDValues(const std::shared_ptr<AsyncResp>& asyncRespIn) :
1113 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001114
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001115 {}
James Feist73df0db2019-03-25 15:29:35 -07001116
1117 void run()
1118 {
1119 std::shared_ptr<GetPIDValues> self = shared_from_this();
1120
1121 // get all configurations
1122 crow::connections::systemBus->async_method_call(
1123 [self](const boost::system::error_code ec,
Ed Tanous23a21a12020-07-25 04:45:05 +00001124 const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) {
James Feist73df0db2019-03-25 15:29:35 -07001125 if (ec)
1126 {
1127 BMCWEB_LOG_ERROR << ec;
1128 messages::internalError(self->asyncResp->res);
1129 return;
1130 }
Ed Tanous23a21a12020-07-25 04:45:05 +00001131 self->subtree = subtreeLocal;
James Feist73df0db2019-03-25 15:29:35 -07001132 },
1133 "xyz.openbmc_project.ObjectMapper",
1134 "/xyz/openbmc_project/object_mapper",
1135 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1136 std::array<const char*, 4>{
1137 pidConfigurationIface, pidZoneConfigurationIface,
1138 objectManagerIface, stepwiseConfigurationIface});
1139
1140 // at the same time get the selected profile
1141 crow::connections::systemBus->async_method_call(
1142 [self](const boost::system::error_code ec,
Ed Tanous23a21a12020-07-25 04:45:05 +00001143 const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) {
1144 if (ec || subtreeLocal.empty())
James Feist73df0db2019-03-25 15:29:35 -07001145 {
1146 return;
1147 }
Ed Tanous23a21a12020-07-25 04:45:05 +00001148 if (subtreeLocal[0].second.size() != 1)
James Feist73df0db2019-03-25 15:29:35 -07001149 {
1150 // invalid mapper response, should never happen
1151 BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error";
1152 messages::internalError(self->asyncResp->res);
1153 return;
1154 }
1155
Ed Tanous23a21a12020-07-25 04:45:05 +00001156 const std::string& path = subtreeLocal[0].first;
1157 const std::string& owner = subtreeLocal[0].second[0].first;
James Feist73df0db2019-03-25 15:29:35 -07001158 crow::connections::systemBus->async_method_call(
1159 [path, owner, self](
Ed Tanous23a21a12020-07-25 04:45:05 +00001160 const boost::system::error_code ec2,
James Feist73df0db2019-03-25 15:29:35 -07001161 const boost::container::flat_map<
1162 std::string, std::variant<std::vector<std::string>,
1163 std::string>>& resp) {
Ed Tanous23a21a12020-07-25 04:45:05 +00001164 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001165 {
1166 BMCWEB_LOG_ERROR << "GetPIDValues: Can't get "
1167 "thermalModeIface "
1168 << path;
1169 messages::internalError(self->asyncResp->res);
1170 return;
1171 }
Ed Tanous271584a2019-07-09 16:24:22 -07001172 const std::string* current = nullptr;
1173 const std::vector<std::string>* supported = nullptr;
James Feist73df0db2019-03-25 15:29:35 -07001174 for (auto& [key, value] : resp)
1175 {
1176 if (key == "Current")
1177 {
1178 current = std::get_if<std::string>(&value);
1179 if (current == nullptr)
1180 {
1181 BMCWEB_LOG_ERROR
1182 << "GetPIDValues: thermal mode "
1183 "iface invalid "
1184 << path;
1185 messages::internalError(
1186 self->asyncResp->res);
1187 return;
1188 }
1189 }
1190 if (key == "Supported")
1191 {
1192 supported =
1193 std::get_if<std::vector<std::string>>(
1194 &value);
1195 if (supported == nullptr)
1196 {
1197 BMCWEB_LOG_ERROR
1198 << "GetPIDValues: thermal mode "
1199 "iface invalid"
1200 << path;
1201 messages::internalError(
1202 self->asyncResp->res);
1203 return;
1204 }
1205 }
1206 }
1207 if (current == nullptr || supported == nullptr)
1208 {
1209 BMCWEB_LOG_ERROR << "GetPIDValues: thermal mode "
1210 "iface invalid "
1211 << path;
1212 messages::internalError(self->asyncResp->res);
1213 return;
1214 }
1215 self->currentProfile = *current;
1216 self->supportedProfiles = *supported;
1217 },
1218 owner, path, "org.freedesktop.DBus.Properties", "GetAll",
1219 thermalModeIface);
1220 },
1221 "xyz.openbmc_project.ObjectMapper",
1222 "/xyz/openbmc_project/object_mapper",
1223 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1224 std::array<const char*, 1>{thermalModeIface});
1225 }
1226
1227 ~GetPIDValues()
1228 {
1229 if (asyncResp->res.result() != boost::beast::http::status::ok)
1230 {
1231 return;
1232 }
1233 // create map of <connection, path to objMgr>>
1234 boost::container::flat_map<std::string, std::string> objectMgrPaths;
1235 boost::container::flat_set<std::string> calledConnections;
1236 for (const auto& pathGroup : subtree)
1237 {
1238 for (const auto& connectionGroup : pathGroup.second)
1239 {
1240 auto findConnection =
1241 calledConnections.find(connectionGroup.first);
1242 if (findConnection != calledConnections.end())
1243 {
1244 break;
1245 }
1246 for (const std::string& interface : connectionGroup.second)
1247 {
1248 if (interface == objectManagerIface)
1249 {
1250 objectMgrPaths[connectionGroup.first] = pathGroup.first;
1251 }
1252 // this list is alphabetical, so we
1253 // should have found the objMgr by now
1254 if (interface == pidConfigurationIface ||
1255 interface == pidZoneConfigurationIface ||
1256 interface == stepwiseConfigurationIface)
1257 {
1258 auto findObjMgr =
1259 objectMgrPaths.find(connectionGroup.first);
1260 if (findObjMgr == objectMgrPaths.end())
1261 {
1262 BMCWEB_LOG_DEBUG << connectionGroup.first
1263 << "Has no Object Manager";
1264 continue;
1265 }
1266
1267 calledConnections.insert(connectionGroup.first);
1268
1269 asyncPopulatePid(findObjMgr->first, findObjMgr->second,
1270 currentProfile, supportedProfiles,
1271 asyncResp);
1272 break;
1273 }
1274 }
1275 }
1276 }
1277 }
1278
1279 std::vector<std::string> supportedProfiles;
1280 std::string currentProfile;
1281 crow::openbmc_mapper::GetSubTreeType subtree;
1282 std::shared_ptr<AsyncResp> asyncResp;
1283};
1284
1285struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
1286{
1287
Ed Tanous271584a2019-07-09 16:24:22 -07001288 SetPIDValues(const std::shared_ptr<AsyncResp>& asyncRespIn,
James Feist73df0db2019-03-25 15:29:35 -07001289 nlohmann::json& data) :
Ed Tanous271584a2019-07-09 16:24:22 -07001290 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001291 {
1292
1293 std::optional<nlohmann::json> pidControllers;
1294 std::optional<nlohmann::json> fanControllers;
1295 std::optional<nlohmann::json> fanZones;
1296 std::optional<nlohmann::json> stepwiseControllers;
1297
1298 if (!redfish::json_util::readJson(
1299 data, asyncResp->res, "PidControllers", pidControllers,
1300 "FanControllers", fanControllers, "FanZones", fanZones,
1301 "StepwiseControllers", stepwiseControllers, "Profile", profile))
1302 {
1303 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
1304 << data.dump();
1305 return;
1306 }
1307 configuration.emplace_back("PidControllers", std::move(pidControllers));
1308 configuration.emplace_back("FanControllers", std::move(fanControllers));
1309 configuration.emplace_back("FanZones", std::move(fanZones));
1310 configuration.emplace_back("StepwiseControllers",
1311 std::move(stepwiseControllers));
1312 }
1313 void run()
1314 {
1315 if (asyncResp->res.result() != boost::beast::http::status::ok)
1316 {
1317 return;
1318 }
1319
1320 std::shared_ptr<SetPIDValues> self = shared_from_this();
1321
1322 // todo(james): might make sense to do a mapper call here if this
1323 // interface gets more traction
1324 crow::connections::systemBus->async_method_call(
1325 [self](const boost::system::error_code ec,
Ed Tanous271584a2019-07-09 16:24:22 -07001326 dbus::utility::ManagedObjectType& mObj) {
James Feist73df0db2019-03-25 15:29:35 -07001327 if (ec)
1328 {
1329 BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
1330 messages::internalError(self->asyncResp->res);
1331 return;
1332 }
James Feiste69d9de2020-02-07 12:23:27 -08001333 const std::array<const char*, 3> configurations = {
1334 pidConfigurationIface, pidZoneConfigurationIface,
1335 stepwiseConfigurationIface};
1336
James Feist14b0b8d2020-02-12 11:52:07 -08001337 for (const auto& [path, object] : mObj)
James Feiste69d9de2020-02-07 12:23:27 -08001338 {
James Feist14b0b8d2020-02-12 11:52:07 -08001339 for (const auto& [interface, _] : object)
James Feiste69d9de2020-02-07 12:23:27 -08001340 {
1341 if (std::find(configurations.begin(),
1342 configurations.end(),
1343 interface) != configurations.end())
1344 {
James Feist14b0b8d2020-02-12 11:52:07 -08001345 self->objectCount++;
James Feiste69d9de2020-02-07 12:23:27 -08001346 break;
1347 }
1348 }
James Feiste69d9de2020-02-07 12:23:27 -08001349 }
Ed Tanous271584a2019-07-09 16:24:22 -07001350 self->managedObj = std::move(mObj);
James Feist73df0db2019-03-25 15:29:35 -07001351 },
1352 "xyz.openbmc_project.EntityManager", "/", objectManagerIface,
1353 "GetManagedObjects");
1354
1355 // at the same time get the profile information
1356 crow::connections::systemBus->async_method_call(
1357 [self](const boost::system::error_code ec,
1358 const crow::openbmc_mapper::GetSubTreeType& subtree) {
1359 if (ec || subtree.empty())
1360 {
1361 return;
1362 }
1363 if (subtree[0].second.empty())
1364 {
1365 // invalid mapper response, should never happen
1366 BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error";
1367 messages::internalError(self->asyncResp->res);
1368 return;
1369 }
1370
1371 const std::string& path = subtree[0].first;
1372 const std::string& owner = subtree[0].second[0].first;
1373 crow::connections::systemBus->async_method_call(
1374 [self, path, owner](
Ed Tanouscb13a392020-07-25 19:02:03 +00001375 const boost::system::error_code ec2,
James Feist73df0db2019-03-25 15:29:35 -07001376 const boost::container::flat_map<
1377 std::string, std::variant<std::vector<std::string>,
Ed Tanous271584a2019-07-09 16:24:22 -07001378 std::string>>& r) {
Ed Tanouscb13a392020-07-25 19:02:03 +00001379 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001380 {
1381 BMCWEB_LOG_ERROR << "SetPIDValues: Can't get "
1382 "thermalModeIface "
1383 << path;
1384 messages::internalError(self->asyncResp->res);
1385 return;
1386 }
Ed Tanous271584a2019-07-09 16:24:22 -07001387 const std::string* current = nullptr;
1388 const std::vector<std::string>* supported = nullptr;
1389 for (auto& [key, value] : r)
James Feist73df0db2019-03-25 15:29:35 -07001390 {
1391 if (key == "Current")
1392 {
1393 current = std::get_if<std::string>(&value);
1394 if (current == nullptr)
1395 {
1396 BMCWEB_LOG_ERROR
1397 << "SetPIDValues: thermal mode "
1398 "iface invalid "
1399 << path;
1400 messages::internalError(
1401 self->asyncResp->res);
1402 return;
1403 }
1404 }
1405 if (key == "Supported")
1406 {
1407 supported =
1408 std::get_if<std::vector<std::string>>(
1409 &value);
1410 if (supported == nullptr)
1411 {
1412 BMCWEB_LOG_ERROR
1413 << "SetPIDValues: thermal mode "
1414 "iface invalid"
1415 << path;
1416 messages::internalError(
1417 self->asyncResp->res);
1418 return;
1419 }
1420 }
1421 }
1422 if (current == nullptr || supported == nullptr)
1423 {
1424 BMCWEB_LOG_ERROR << "SetPIDValues: thermal mode "
1425 "iface invalid "
1426 << path;
1427 messages::internalError(self->asyncResp->res);
1428 return;
1429 }
1430 self->currentProfile = *current;
1431 self->supportedProfiles = *supported;
1432 self->profileConnection = owner;
1433 self->profilePath = path;
1434 },
1435 owner, path, "org.freedesktop.DBus.Properties", "GetAll",
1436 thermalModeIface);
1437 },
1438 "xyz.openbmc_project.ObjectMapper",
1439 "/xyz/openbmc_project/object_mapper",
1440 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1441 std::array<const char*, 1>{thermalModeIface});
1442 }
1443 ~SetPIDValues()
1444 {
1445 if (asyncResp->res.result() != boost::beast::http::status::ok)
1446 {
1447 return;
1448 }
1449
1450 std::shared_ptr<AsyncResp> response = asyncResp;
1451
1452 if (profile)
1453 {
1454 if (std::find(supportedProfiles.begin(), supportedProfiles.end(),
1455 *profile) == supportedProfiles.end())
1456 {
1457 messages::actionParameterUnknown(response->res, "Profile",
1458 *profile);
1459 return;
1460 }
1461 currentProfile = *profile;
1462 crow::connections::systemBus->async_method_call(
1463 [response](const boost::system::error_code ec) {
1464 if (ec)
1465 {
1466 BMCWEB_LOG_ERROR << "Error patching profile" << ec;
1467 messages::internalError(response->res);
1468 }
1469 },
1470 profileConnection, profilePath,
1471 "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
1472 "Current", std::variant<std::string>(*profile));
1473 }
1474
1475 for (auto& containerPair : configuration)
1476 {
1477 auto& container = containerPair.second;
1478 if (!container)
1479 {
1480 continue;
1481 }
James Feist6ee7f772020-02-06 16:25:27 -08001482 BMCWEB_LOG_DEBUG << *container;
1483
James Feist73df0db2019-03-25 15:29:35 -07001484 std::string& type = containerPair.first;
1485
1486 for (nlohmann::json::iterator it = container->begin();
1487 it != container->end(); it++)
1488 {
1489 const auto& name = it.key();
James Feist6ee7f772020-02-06 16:25:27 -08001490 BMCWEB_LOG_DEBUG << "looking for " << name;
1491
James Feist73df0db2019-03-25 15:29:35 -07001492 auto pathItr =
1493 std::find_if(managedObj.begin(), managedObj.end(),
1494 [&name](const auto& obj) {
1495 return boost::algorithm::ends_with(
1496 obj.first.str, "/" + name);
1497 });
1498 boost::container::flat_map<std::string,
1499 dbus::utility::DbusVariantType>
1500 output;
1501
1502 output.reserve(16); // The pid interface length
1503
1504 // determines if we're patching entity-manager or
1505 // creating a new object
1506 bool createNewObject = (pathItr == managedObj.end());
James Feist6ee7f772020-02-06 16:25:27 -08001507 BMCWEB_LOG_DEBUG << "Found = " << !createNewObject;
1508
James Feist73df0db2019-03-25 15:29:35 -07001509 std::string iface;
1510 if (type == "PidControllers" || type == "FanControllers")
1511 {
1512 iface = pidConfigurationIface;
1513 if (!createNewObject &&
1514 pathItr->second.find(pidConfigurationIface) ==
1515 pathItr->second.end())
1516 {
1517 createNewObject = true;
1518 }
1519 }
1520 else if (type == "FanZones")
1521 {
1522 iface = pidZoneConfigurationIface;
1523 if (!createNewObject &&
1524 pathItr->second.find(pidZoneConfigurationIface) ==
1525 pathItr->second.end())
1526 {
1527
1528 createNewObject = true;
1529 }
1530 }
1531 else if (type == "StepwiseControllers")
1532 {
1533 iface = stepwiseConfigurationIface;
1534 if (!createNewObject &&
1535 pathItr->second.find(stepwiseConfigurationIface) ==
1536 pathItr->second.end())
1537 {
1538 createNewObject = true;
1539 }
1540 }
James Feist6ee7f772020-02-06 16:25:27 -08001541
1542 if (createNewObject && it.value() == nullptr)
1543 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -05001544 // can't delete a non-existent object
James Feist6ee7f772020-02-06 16:25:27 -08001545 messages::invalidObject(response->res, name);
1546 continue;
1547 }
1548
1549 std::string path;
1550 if (pathItr != managedObj.end())
1551 {
1552 path = pathItr->first.str;
1553 }
1554
James Feist73df0db2019-03-25 15:29:35 -07001555 BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n";
James Feiste69d9de2020-02-07 12:23:27 -08001556
1557 // arbitrary limit to avoid attacks
1558 constexpr const size_t controllerLimit = 500;
James Feist14b0b8d2020-02-12 11:52:07 -08001559 if (createNewObject && objectCount >= controllerLimit)
James Feiste69d9de2020-02-07 12:23:27 -08001560 {
1561 messages::resourceExhaustion(response->res, type);
1562 continue;
1563 }
1564
James Feist73df0db2019-03-25 15:29:35 -07001565 output["Name"] = boost::replace_all_copy(name, "_", " ");
1566
1567 std::string chassis;
1568 CreatePIDRet ret = createPidInterface(
James Feist6ee7f772020-02-06 16:25:27 -08001569 response, type, it, path, managedObj, createNewObject,
1570 output, chassis, currentProfile);
James Feist73df0db2019-03-25 15:29:35 -07001571 if (ret == CreatePIDRet::fail)
1572 {
1573 return;
1574 }
1575 else if (ret == CreatePIDRet::del)
1576 {
1577 continue;
1578 }
1579
1580 if (!createNewObject)
1581 {
1582 for (const auto& property : output)
1583 {
1584 crow::connections::systemBus->async_method_call(
1585 [response,
1586 propertyName{std::string(property.first)}](
1587 const boost::system::error_code ec) {
1588 if (ec)
1589 {
1590 BMCWEB_LOG_ERROR << "Error patching "
1591 << propertyName << ": "
1592 << ec;
1593 messages::internalError(response->res);
1594 return;
1595 }
1596 messages::success(response->res);
1597 },
James Feist6ee7f772020-02-06 16:25:27 -08001598 "xyz.openbmc_project.EntityManager", path,
James Feist73df0db2019-03-25 15:29:35 -07001599 "org.freedesktop.DBus.Properties", "Set", iface,
1600 property.first, property.second);
1601 }
1602 }
1603 else
1604 {
1605 if (chassis.empty())
1606 {
1607 BMCWEB_LOG_ERROR << "Failed to get chassis from config";
1608 messages::invalidObject(response->res, name);
1609 return;
1610 }
1611
1612 bool foundChassis = false;
1613 for (const auto& obj : managedObj)
1614 {
1615 if (boost::algorithm::ends_with(obj.first.str, chassis))
1616 {
1617 chassis = obj.first.str;
1618 foundChassis = true;
1619 break;
1620 }
1621 }
1622 if (!foundChassis)
1623 {
1624 BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
1625 messages::resourceMissingAtURI(
1626 response->res, "/redfish/v1/Chassis/" + chassis);
1627 return;
1628 }
1629
1630 crow::connections::systemBus->async_method_call(
1631 [response](const boost::system::error_code ec) {
1632 if (ec)
1633 {
1634 BMCWEB_LOG_ERROR << "Error Adding Pid Object "
1635 << ec;
1636 messages::internalError(response->res);
1637 return;
1638 }
1639 messages::success(response->res);
1640 },
1641 "xyz.openbmc_project.EntityManager", chassis,
1642 "xyz.openbmc_project.AddObject", "AddObject", output);
1643 }
1644 }
1645 }
1646 }
1647 std::shared_ptr<AsyncResp> asyncResp;
1648 std::vector<std::pair<std::string, std::optional<nlohmann::json>>>
1649 configuration;
1650 std::optional<std::string> profile;
1651 dbus::utility::ManagedObjectType managedObj;
1652 std::vector<std::string> supportedProfiles;
1653 std::string currentProfile;
1654 std::string profileConnection;
1655 std::string profilePath;
James Feist14b0b8d2020-02-12 11:52:07 -08001656 size_t objectCount = 0;
James Feist73df0db2019-03-25 15:29:35 -07001657};
James Feist83ff9ab2018-08-31 10:18:24 -07001658
Ed Tanous1abe55e2018-09-05 08:30:59 -07001659class Manager : public Node
1660{
1661 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001662 Manager(App& app) : Node(app, "/redfish/v1/Managers/bmc/")
Ed Tanous1abe55e2018-09-05 08:30:59 -07001663 {
Ed Tanous52cc1122020-07-18 13:51:21 -07001664
1665 uuid = persistent_data::getConfig().systemUuid;
Ed Tanous1abe55e2018-09-05 08:30:59 -07001666 entityPrivileges = {
1667 {boost::beast::http::verb::get, {{"Login"}}},
1668 {boost::beast::http::verb::head, {{"Login"}}},
1669 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1670 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1671 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1672 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001673 }
1674
Ed Tanous1abe55e2018-09-05 08:30:59 -07001675 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001676 void doGet(crow::Response& res, const crow::Request&,
1677 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -07001678 {
Ed Tanous0f74e642018-11-12 15:17:05 -08001679 res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
Gunnar Mills4bf2b032020-06-23 22:28:31 -05001680 res.jsonValue["@odata.type"] = "#Manager.v1_9_0.Manager";
Ed Tanous0f74e642018-11-12 15:17:05 -08001681 res.jsonValue["Id"] = "bmc";
1682 res.jsonValue["Name"] = "OpenBmc Manager";
1683 res.jsonValue["Description"] = "Baseboard Management Controller";
1684 res.jsonValue["PowerState"] = "On";
Ed Tanous029573d2019-02-01 10:57:49 -08001685 res.jsonValue["Status"] = {{"State", "Enabled"}, {"Health", "OK"}};
Ed Tanous0f74e642018-11-12 15:17:05 -08001686 res.jsonValue["ManagerType"] = "BMC";
Ed Tanous3602e232019-05-13 11:11:44 -07001687 res.jsonValue["UUID"] = systemd_utils::getUuid();
1688 res.jsonValue["ServiceEntryPointUUID"] = uuid;
Ed Tanous75176582018-12-14 08:14:34 -08001689 res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
Ed Tanous0f74e642018-11-12 15:17:05 -08001690
1691 res.jsonValue["LogServices"] = {
1692 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices"}};
1693
1694 res.jsonValue["NetworkProtocol"] = {
1695 {"@odata.id", "/redfish/v1/Managers/bmc/NetworkProtocol"}};
1696
1697 res.jsonValue["EthernetInterfaces"] = {
1698 {"@odata.id", "/redfish/v1/Managers/bmc/EthernetInterfaces"}};
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001699
1700#ifdef BMCWEB_ENABLE_VM_NBDPROXY
1701 res.jsonValue["VirtualMedia"] = {
1702 {"@odata.id", "/redfish/v1/Managers/bmc/VirtualMedia"}};
1703#endif // BMCWEB_ENABLE_VM_NBDPROXY
1704
Ed Tanous0f74e642018-11-12 15:17:05 -08001705 // default oem data
1706 nlohmann::json& oem = res.jsonValue["Oem"];
1707 nlohmann::json& oemOpenbmc = oem["OpenBmc"];
1708 oem["@odata.type"] = "#OemManager.Oem";
1709 oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem";
Ed Tanous0f74e642018-11-12 15:17:05 -08001710 oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc";
1711 oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc";
Marri Devender Raocfcd5f62019-05-17 08:34:37 -05001712 oemOpenbmc["Certificates"] = {
1713 {"@odata.id", "/redfish/v1/Managers/bmc/Truststore/Certificates"}};
Ed Tanous0f74e642018-11-12 15:17:05 -08001714
Gunnar Mills2a5c4402020-05-19 09:07:24 -05001715 // Manager.Reset (an action) can be many values, OpenBMC only supports
1716 // BMC reboot.
1717 nlohmann::json& managerReset =
Ed Tanous0f74e642018-11-12 15:17:05 -08001718 res.jsonValue["Actions"]["#Manager.Reset"];
Gunnar Mills2a5c4402020-05-19 09:07:24 -05001719 managerReset["target"] =
Jennifer Leeed5befb2018-08-10 11:29:45 -07001720 "/redfish/v1/Managers/bmc/Actions/Manager.Reset";
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +05301721 managerReset["@Redfish.ActionInfo"] =
1722 "/redfish/v1/Managers/bmc/ResetActionInfo";
Jennifer Leeca537922018-08-10 10:07:30 -07001723
Gunnar Mills3e40fc72020-05-19 19:18:17 -05001724 // ResetToDefaults (Factory Reset) has values like
1725 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
1726 // on OpenBMC
1727 nlohmann::json& resetToDefaults =
1728 res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
1729 resetToDefaults["target"] =
1730 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
1731 resetToDefaults["ResetType@Redfish.AllowableValues"] = {"ResetAll"};
1732
Andrew Geisslercb92c032018-08-17 07:56:14 -07001733 res.jsonValue["DateTime"] = crow::utility::dateTimeNow();
Santosh Puranik474bfad2019-04-02 16:00:09 +05301734
Kuiying Wangf8c3e6f2019-08-22 13:35:56 +08001735 // Fill in SerialConsole info
Santosh Puranik474bfad2019-04-02 16:00:09 +05301736 res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
Kuiying Wangf8c3e6f2019-08-22 13:35:56 +08001737 res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
Santosh Puranik474bfad2019-04-02 16:00:09 +05301738 res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = {"IPMI",
1739 "SSH"};
Santosh Puranikef47bb12019-04-30 10:28:52 +05301740#ifdef BMCWEB_ENABLE_KVM
Kuiying Wangf8c3e6f2019-08-22 13:35:56 +08001741 // Fill in GraphicalConsole info
Santosh Puranikef47bb12019-04-30 10:28:52 +05301742 res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
Jae Hyun Yoo704fae62019-10-02 13:01:27 -07001743 res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4;
Santosh Puranikef47bb12019-04-30 10:28:52 +05301744 res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"};
1745#endif // BMCWEB_ENABLE_KVM
Santosh Puranik474bfad2019-04-02 16:00:09 +05301746
Gunnar Mills603a6642019-01-21 17:03:51 -06001747 res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
1748 res.jsonValue["Links"]["ManagerForServers"] = {
1749 {{"@odata.id", "/redfish/v1/Systems/system"}}};
Shawn McCarney26f03892019-05-03 13:20:24 -05001750
Jennifer Leeed5befb2018-08-10 11:29:45 -07001751 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
James Feist5b4aa862018-08-16 14:07:01 -07001752
James Feistb49ac872019-05-21 15:12:01 -07001753 auto health = std::make_shared<HealthPopulate>(asyncResp);
1754 health->isManagersHealth = true;
1755 health->populate();
1756
Andrew Geisslere90c5052019-06-28 13:52:27 -05001757 fw_util::getActiveFwVersion(asyncResp, fw_util::bmcPurpose,
Gunnar Mills72d566d2020-07-21 12:44:00 -05001758 "FirmwareVersion", true);
James Feist0f6b00b2019-06-10 14:15:53 -07001759
Gunnar Mills4bf2b032020-06-23 22:28:31 -05001760 getLastResetTime(asyncResp);
1761
James Feist73df0db2019-03-25 15:29:35 -07001762 auto pids = std::make_shared<GetPIDValues>(asyncResp);
1763 pids->run();
Jennifer Leec5d03ff2019-03-08 15:42:58 -08001764
1765 getMainChassisId(asyncResp, [](const std::string& chassisId,
1766 const std::shared_ptr<AsyncResp> aRsp) {
1767 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
1768 aRsp->res.jsonValue["Links"]["ManagerForChassis"] = {
1769 {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}};
Jason M. Bills2c0feb02019-07-26 16:35:20 -07001770 aRsp->res.jsonValue["Links"]["ManagerInChassis"] = {
1771 {"@odata.id", "/redfish/v1/Chassis/" + chassisId}};
Jennifer Leec5d03ff2019-03-08 15:42:58 -08001772 });
James Feist0f6b00b2019-06-10 14:15:53 -07001773
1774 static bool started = false;
1775
1776 if (!started)
1777 {
1778 crow::connections::systemBus->async_method_call(
1779 [asyncResp](const boost::system::error_code ec,
1780 const std::variant<double>& resp) {
1781 if (ec)
1782 {
1783 BMCWEB_LOG_ERROR << "Error while getting progress";
1784 messages::internalError(asyncResp->res);
1785 return;
1786 }
1787 const double* val = std::get_if<double>(&resp);
1788 if (val == nullptr)
1789 {
1790 BMCWEB_LOG_ERROR
1791 << "Invalid response while getting progress";
1792 messages::internalError(asyncResp->res);
1793 return;
1794 }
1795 if (*val < 1.0)
1796 {
1797 asyncResp->res.jsonValue["Status"]["State"] =
1798 "Starting";
1799 started = true;
1800 }
1801 },
1802 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1803 "org.freedesktop.DBus.Properties", "Get",
1804 "org.freedesktop.systemd1.Manager", "Progress");
1805 }
James Feist83ff9ab2018-08-31 10:18:24 -07001806 }
James Feist5b4aa862018-08-16 14:07:01 -07001807
1808 void doPatch(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001809 const std::vector<std::string>&) override
James Feist5b4aa862018-08-16 14:07:01 -07001810 {
Ed Tanous0627a2c2018-11-29 17:09:23 -08001811 std::optional<nlohmann::json> oem;
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001812 std::optional<nlohmann::json> links;
Santosh Puranikaf5d60582019-03-20 18:16:36 +05301813 std::optional<std::string> datetime;
Santosh Puranik41352c22019-07-03 05:35:49 -05001814 std::shared_ptr<AsyncResp> response = std::make_shared<AsyncResp>(res);
Ed Tanous0627a2c2018-11-29 17:09:23 -08001815
Santosh Puranik41352c22019-07-03 05:35:49 -05001816 if (!json_util::readJson(req, response->res, "Oem", oem, "DateTime",
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001817 datetime, "Links", links))
James Feist83ff9ab2018-08-31 10:18:24 -07001818 {
1819 return;
1820 }
Ed Tanous0627a2c2018-11-29 17:09:23 -08001821
Ed Tanous0627a2c2018-11-29 17:09:23 -08001822 if (oem)
James Feist83ff9ab2018-08-31 10:18:24 -07001823 {
Ed Tanous43b761d2019-02-13 20:10:56 -08001824 std::optional<nlohmann::json> openbmc;
1825 if (!redfish::json_util::readJson(*oem, res, "OpenBmc", openbmc))
James Feist83ff9ab2018-08-31 10:18:24 -07001826 {
Ed Tanous43b761d2019-02-13 20:10:56 -08001827 BMCWEB_LOG_ERROR << "Line:" << __LINE__ << ", Illegal Property "
1828 << oem->dump();
1829 return;
1830 }
1831 if (openbmc)
1832 {
1833 std::optional<nlohmann::json> fan;
1834 if (!redfish::json_util::readJson(*openbmc, res, "Fan", fan))
James Feist83ff9ab2018-08-31 10:18:24 -07001835 {
James Feist5f2caae2018-12-12 14:08:25 -08001836 BMCWEB_LOG_ERROR << "Line:" << __LINE__
Ed Tanous43b761d2019-02-13 20:10:56 -08001837 << ", Illegal Property "
1838 << openbmc->dump();
James Feist5f2caae2018-12-12 14:08:25 -08001839 return;
1840 }
Ed Tanous43b761d2019-02-13 20:10:56 -08001841 if (fan)
James Feist5f2caae2018-12-12 14:08:25 -08001842 {
James Feist73df0db2019-03-25 15:29:35 -07001843 auto pid = std::make_shared<SetPIDValues>(response, *fan);
1844 pid->run();
James Feist83ff9ab2018-08-31 10:18:24 -07001845 }
James Feist83ff9ab2018-08-31 10:18:24 -07001846 }
1847 }
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001848 if (links)
1849 {
1850 std::optional<nlohmann::json> activeSoftwareImage;
1851 if (!redfish::json_util::readJson(
1852 *links, res, "ActiveSoftwareImage", activeSoftwareImage))
1853 {
1854 return;
1855 }
1856 if (activeSoftwareImage)
1857 {
1858 std::optional<std::string> odataId;
1859 if (!json_util::readJson(*activeSoftwareImage, res, "@odata.id",
1860 odataId))
1861 {
1862 return;
1863 }
1864
1865 if (odataId)
1866 {
1867 setActiveFirmwareImage(response, std::move(*odataId));
1868 }
1869 }
1870 }
Santosh Puranikaf5d60582019-03-20 18:16:36 +05301871 if (datetime)
1872 {
1873 setDateTime(response, std::move(*datetime));
1874 }
1875 }
1876
Gunnar Mills4bf2b032020-06-23 22:28:31 -05001877 void getLastResetTime(std::shared_ptr<AsyncResp> aResp)
1878 {
1879 BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
1880
1881 crow::connections::systemBus->async_method_call(
1882 [aResp](const boost::system::error_code ec,
1883 std::variant<uint64_t>& lastResetTime) {
1884 if (ec)
1885 {
1886 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1887 return;
1888 }
1889
1890 const uint64_t* lastResetTimePtr =
1891 std::get_if<uint64_t>(&lastResetTime);
1892
1893 if (!lastResetTimePtr)
1894 {
1895 messages::internalError(aResp->res);
1896 return;
1897 }
1898 // LastRebootTime is epoch time, in milliseconds
1899 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
1900 time_t lastResetTimeStamp =
1901 static_cast<time_t>(*lastResetTimePtr / 1000);
1902
1903 // Convert to ISO 8601 standard
1904 aResp->res.jsonValue["LastResetTime"] =
1905 crow::utility::getDateTime(lastResetTimeStamp);
1906 },
1907 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
1908 "org.freedesktop.DBus.Properties", "Get",
1909 "xyz.openbmc_project.State.BMC", "LastRebootTime");
1910 }
1911
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001912 /**
1913 * @brief Set the running firmware image
1914 *
1915 * @param[i,o] aResp - Async response object
1916 * @param[i] runningFirmwareTarget - Image to make the running image
1917 *
1918 * @return void
1919 */
1920 void setActiveFirmwareImage(std::shared_ptr<AsyncResp> aResp,
1921 const std::string&& runningFirmwareTarget)
1922 {
1923 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
1924 std::string::size_type idPos = runningFirmwareTarget.rfind("/");
1925 if (idPos == std::string::npos)
1926 {
1927 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1928 "@odata.id");
1929 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
1930 return;
1931 }
1932 idPos++;
1933 if (idPos >= runningFirmwareTarget.size())
1934 {
1935 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1936 "@odata.id");
1937 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1938 return;
1939 }
1940 std::string firmwareId = runningFirmwareTarget.substr(idPos);
1941
1942 // Make sure the image is valid before setting priority
1943 crow::connections::systemBus->async_method_call(
1944 [aResp, firmwareId,
1945 runningFirmwareTarget](const boost::system::error_code ec,
1946 ManagedObjectType& subtree) {
1947 if (ec)
1948 {
1949 BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
1950 messages::internalError(aResp->res);
1951 return;
1952 }
1953
1954 if (subtree.size() == 0)
1955 {
1956 BMCWEB_LOG_DEBUG << "Can't find image!";
1957 messages::internalError(aResp->res);
1958 return;
1959 }
1960
1961 bool foundImage = false;
1962 for (auto& object : subtree)
1963 {
1964 const std::string& path =
1965 static_cast<const std::string&>(object.first);
1966 std::size_t idPos2 = path.rfind("/");
1967
1968 if (idPos2 == std::string::npos)
1969 {
1970 continue;
1971 }
1972
1973 idPos2++;
1974 if (idPos2 >= path.size())
1975 {
1976 continue;
1977 }
1978
1979 if (path.substr(idPos2) == firmwareId)
1980 {
1981 foundImage = true;
1982 break;
1983 }
1984 }
1985
1986 if (!foundImage)
1987 {
1988 messages::propertyValueNotInList(
1989 aResp->res, runningFirmwareTarget, "@odata.id");
1990 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1991 return;
1992 }
1993
1994 BMCWEB_LOG_DEBUG << "Setting firmware version " + firmwareId +
1995 " to priority 0.";
1996
1997 // Only support Immediate
1998 // An addition could be a Redfish Setting like
1999 // ActiveSoftwareImageApplyTime and support OnReset
2000 crow::connections::systemBus->async_method_call(
2001 [aResp](const boost::system::error_code ec) {
2002 if (ec)
2003 {
2004 BMCWEB_LOG_DEBUG << "D-Bus response error setting.";
2005 messages::internalError(aResp->res);
2006 return;
2007 }
2008 doBMCGracefulRestart(aResp);
2009 },
2010
2011 "xyz.openbmc_project.Software.BMC.Updater",
2012 "/xyz/openbmc_project/software/" + firmwareId,
2013 "org.freedesktop.DBus.Properties", "Set",
2014 "xyz.openbmc_project.Software.RedundancyPriority",
2015 "Priority", std::variant<uint8_t>(static_cast<uint8_t>(0)));
2016 },
2017 "xyz.openbmc_project.Software.BMC.Updater",
2018 "/xyz/openbmc_project/software",
2019 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
2020 }
2021
Santosh Puranikaf5d60582019-03-20 18:16:36 +05302022 void setDateTime(std::shared_ptr<AsyncResp> aResp,
2023 std::string datetime) const
2024 {
2025 BMCWEB_LOG_DEBUG << "Set date time: " << datetime;
2026
2027 std::stringstream stream(datetime);
2028 // Convert from ISO 8601 to boost local_time
2029 // (BMC only has time in UTC)
2030 boost::posix_time::ptime posixTime;
2031 boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
2032 // Facet gets deleted with the stringsteam
2033 auto ifc = std::make_unique<boost::local_time::local_time_input_facet>(
2034 "%Y-%m-%d %H:%M:%S%F %ZP");
2035 stream.imbue(std::locale(stream.getloc(), ifc.release()));
2036
2037 boost::local_time::local_date_time ldt(
2038 boost::local_time::not_a_date_time);
2039
2040 if (stream >> ldt)
2041 {
2042 posixTime = ldt.utc_time();
2043 boost::posix_time::time_duration dur = posixTime - epoch;
2044 uint64_t durMicroSecs =
2045 static_cast<uint64_t>(dur.total_microseconds());
2046 crow::connections::systemBus->async_method_call(
2047 [aResp{std::move(aResp)}, datetime{std::move(datetime)}](
2048 const boost::system::error_code ec) {
2049 if (ec)
2050 {
2051 BMCWEB_LOG_DEBUG << "Failed to set elapsed time. "
2052 "DBUS response error "
2053 << ec;
2054 messages::internalError(aResp->res);
2055 return;
2056 }
2057 aResp->res.jsonValue["DateTime"] = datetime;
2058 },
2059 "xyz.openbmc_project.Time.Manager",
2060 "/xyz/openbmc_project/time/bmc",
2061 "org.freedesktop.DBus.Properties", "Set",
2062 "xyz.openbmc_project.Time.EpochTime", "Elapsed",
2063 std::variant<uint64_t>(durMicroSecs));
2064 }
2065 else
2066 {
2067 messages::propertyValueFormatError(aResp->res, datetime,
2068 "DateTime");
2069 return;
2070 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07002071 }
2072
Ed Tanous0f74e642018-11-12 15:17:05 -08002073 std::string uuid;
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01002074};
2075
Ed Tanous1abe55e2018-09-05 08:30:59 -07002076class ManagerCollection : public Node
2077{
2078 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002079 ManagerCollection(App& app) : Node(app, "/redfish/v1/Managers/")
Ed Tanous1abe55e2018-09-05 08:30:59 -07002080 {
Ed Tanous1abe55e2018-09-05 08:30:59 -07002081 entityPrivileges = {
2082 {boost::beast::http::verb::get, {{"Login"}}},
2083 {boost::beast::http::verb::head, {{"Login"}}},
2084 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2085 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2086 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2087 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2088 }
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01002089
Ed Tanous1abe55e2018-09-05 08:30:59 -07002090 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002091 void doGet(crow::Response& res, const crow::Request&,
2092 const std::vector<std::string>&) override
Ed Tanous1abe55e2018-09-05 08:30:59 -07002093 {
James Feist83ff9ab2018-08-31 10:18:24 -07002094 // Collections don't include the static data added by SubRoute
2095 // because it has a duplicate entry for members
Ed Tanous1abe55e2018-09-05 08:30:59 -07002096 res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
2097 res.jsonValue["@odata.type"] = "#ManagerCollection.ManagerCollection";
Ed Tanous1abe55e2018-09-05 08:30:59 -07002098 res.jsonValue["Name"] = "Manager Collection";
2099 res.jsonValue["Members@odata.count"] = 1;
2100 res.jsonValue["Members"] = {
James Feist5b4aa862018-08-16 14:07:01 -07002101 {{"@odata.id", "/redfish/v1/Managers/bmc"}}};
Ed Tanous1abe55e2018-09-05 08:30:59 -07002102 res.end();
2103 }
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01002104};
Ed Tanous1abe55e2018-09-05 08:30:59 -07002105} // namespace redfish