Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 8 | #include "app.hpp" |
| 9 | #include "dbus_utility.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 10 | #include "generated/enums/action_info.hpp" |
| 11 | #include "generated/enums/manager.hpp" |
| 12 | #include "generated/enums/resource.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 13 | #include "query.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 14 | #include "redfish_util.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 15 | #include "registries/privilege_registry.hpp" |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 16 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 17 | #include "utils/json_utils.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 18 | #include "utils/sw_utils.hpp" |
| 19 | #include "utils/systemd_utils.hpp" |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 20 | #include "utils/time_utils.hpp" |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 21 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 22 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 23 | #include <boost/url/format.hpp> |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 24 | #include <sdbusplus/asio/property.hpp> |
| 25 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 26 | |
Ed Tanous | a170f27 | 2022-06-30 21:53:27 -0700 | [diff] [blame] | 27 | #include <algorithm> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 28 | #include <array> |
Gunnar Mills | 4bfefa7 | 2020-07-30 13:54:29 -0500 | [diff] [blame] | 29 | #include <cstdint> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 30 | #include <memory> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 31 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 32 | #include <ranges> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 33 | #include <sstream> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 34 | #include <string> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 35 | #include <string_view> |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 36 | #include <variant> |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 37 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 38 | namespace redfish |
| 39 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 40 | |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 41 | inline std::string getBMCUpdateServiceName() |
| 42 | { |
| 43 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 44 | { |
| 45 | return "xyz.openbmc_project.Software.Manager"; |
| 46 | } |
| 47 | return "xyz.openbmc_project.Software.BMC.Updater"; |
| 48 | } |
| 49 | |
| 50 | inline std::string getBMCUpdateServicePath() |
| 51 | { |
| 52 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 53 | { |
| 54 | return "/xyz/openbmc_project/software/bmc"; |
| 55 | } |
| 56 | return "/xyz/openbmc_project/software"; |
| 57 | } |
| 58 | |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 59 | /** |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 60 | * Function reboots the BMC. |
| 61 | * |
| 62 | * @param[in] asyncResp - Shared pointer for completing asynchronous calls |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 63 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 64 | inline void |
| 65 | doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 66 | { |
| 67 | const char* processName = "xyz.openbmc_project.State.BMC"; |
| 68 | const char* objectPath = "/xyz/openbmc_project/state/bmc0"; |
| 69 | const char* interfaceName = "xyz.openbmc_project.State.BMC"; |
| 70 | const std::string& propertyValue = |
| 71 | "xyz.openbmc_project.State.BMC.Transition.Reboot"; |
| 72 | const char* destProperty = "RequestedBMCTransition"; |
| 73 | |
| 74 | // Create the D-Bus variant for D-Bus call. |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 75 | sdbusplus::asio::setProperty( |
| 76 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 77 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 78 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 79 | // Use "Set" method to set the property value. |
| 80 | if (ec) |
| 81 | { |
| 82 | BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); |
| 83 | messages::internalError(asyncResp->res); |
| 84 | return; |
| 85 | } |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 86 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 87 | messages::success(asyncResp->res); |
| 88 | }); |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 89 | } |
| 90 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 91 | inline void |
| 92 | doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 93 | { |
| 94 | const char* processName = "xyz.openbmc_project.State.BMC"; |
| 95 | const char* objectPath = "/xyz/openbmc_project/state/bmc0"; |
| 96 | const char* interfaceName = "xyz.openbmc_project.State.BMC"; |
| 97 | const std::string& propertyValue = |
| 98 | "xyz.openbmc_project.State.BMC.Transition.HardReboot"; |
| 99 | const char* destProperty = "RequestedBMCTransition"; |
| 100 | |
| 101 | // Create the D-Bus variant for D-Bus call. |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 102 | sdbusplus::asio::setProperty( |
| 103 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 104 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 105 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 106 | // Use "Set" method to set the property value. |
| 107 | if (ec) |
| 108 | { |
| 109 | BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); |
| 110 | messages::internalError(asyncResp->res); |
| 111 | return; |
| 112 | } |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 113 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 114 | messages::success(asyncResp->res); |
| 115 | }); |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 118 | /** |
| 119 | * ManagerResetAction class supports the POST method for the Reset (reboot) |
| 120 | * action. |
| 121 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 122 | inline void requestRoutesManagerResetAction(App& app) |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 123 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 124 | /** |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 125 | * Function handles POST method request. |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 126 | * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 127 | * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 128 | */ |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 129 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 130 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 131 | .privileges(redfish::privileges::postManager) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 132 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 133 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 134 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 135 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 136 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 137 | { |
| 138 | return; |
| 139 | } |
| 140 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 141 | { |
| 142 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 143 | managerId); |
| 144 | return; |
| 145 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 146 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 147 | BMCWEB_LOG_DEBUG("Post Manager Reset."); |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 148 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 149 | std::string resetType; |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 150 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 151 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", |
| 152 | resetType)) |
| 153 | { |
| 154 | return; |
| 155 | } |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 156 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 157 | if (resetType == "GracefulRestart") |
| 158 | { |
| 159 | BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); |
| 160 | doBMCGracefulRestart(asyncResp); |
| 161 | return; |
| 162 | } |
| 163 | if (resetType == "ForceRestart") |
| 164 | { |
| 165 | BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); |
| 166 | doBMCForceRestart(asyncResp); |
| 167 | return; |
| 168 | } |
| 169 | BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", |
| 170 | resetType); |
| 171 | messages::actionParameterNotSupported(asyncResp->res, resetType, |
| 172 | "ResetType"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 173 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 174 | return; |
| 175 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 176 | } |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 177 | |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 178 | /** |
| 179 | * ManagerResetToDefaultsAction class supports POST method for factory reset |
| 180 | * action. |
| 181 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 182 | inline void requestRoutesManagerResetToDefaultsAction(App& app) |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 183 | { |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 184 | /** |
| 185 | * Function handles ResetToDefaults POST method request. |
| 186 | * |
| 187 | * Analyzes POST body message and factory resets BMC by calling |
| 188 | * BMC code updater factory reset followed by a BMC reboot. |
| 189 | * |
| 190 | * BMC code updater factory reset wipes the whole BMC read-write |
| 191 | * filesystem which includes things like the network settings. |
| 192 | * |
| 193 | * OpenBMC only supports ResetToDefaultsType "ResetAll". |
| 194 | */ |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 195 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 196 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 197 | "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 198 | .privileges(redfish::privileges::postManager) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 199 | .methods( |
| 200 | boost::beast::http::verb:: |
| 201 | post)([&app]( |
| 202 | const crow::Request& req, |
| 203 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 204 | const std::string& managerId) { |
| 205 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 206 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 207 | return; |
| 208 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 209 | |
| 210 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 211 | { |
| 212 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 213 | managerId); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | BMCWEB_LOG_DEBUG("Post ResetToDefaults."); |
| 218 | |
| 219 | std::optional<std::string> resetType; |
| 220 | std::optional<std::string> resetToDefaultsType; |
| 221 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 222 | if (!json_util::readJsonAction( // |
| 223 | req, asyncResp->res, // |
| 224 | "ResetToDefaultsType", resetToDefaultsType, // |
| 225 | "ResetType", resetType // |
| 226 | )) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 227 | { |
| 228 | BMCWEB_LOG_DEBUG("Missing property ResetType."); |
| 229 | |
| 230 | messages::actionParameterMissing( |
| 231 | asyncResp->res, "ResetToDefaults", "ResetType"); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | if (resetToDefaultsType && !resetType) |
| 236 | { |
| 237 | BMCWEB_LOG_WARNING( |
| 238 | "Using deprecated ResetToDefaultsType, should be ResetType." |
| 239 | "Support for the ResetToDefaultsType will be dropped in 2Q24"); |
| 240 | resetType = resetToDefaultsType; |
| 241 | } |
| 242 | |
| 243 | if (resetType != "ResetAll") |
| 244 | { |
| 245 | BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", |
| 246 | *resetType); |
| 247 | messages::actionParameterNotSupported(asyncResp->res, |
| 248 | *resetType, "ResetType"); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | crow::connections::systemBus->async_method_call( |
| 253 | [asyncResp](const boost::system::error_code& ec) { |
| 254 | if (ec) |
| 255 | { |
| 256 | BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec); |
| 257 | messages::internalError(asyncResp->res); |
| 258 | return; |
| 259 | } |
| 260 | // Factory Reset doesn't actually happen until a reboot |
| 261 | // Can't erase what the BMC is running on |
| 262 | doBMCGracefulRestart(asyncResp); |
| 263 | }, |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 264 | getBMCUpdateServiceName(), getBMCUpdateServicePath(), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 265 | "xyz.openbmc_project.Common.FactoryReset", "Reset"); |
| 266 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 267 | } |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 268 | |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 269 | /** |
| 270 | * ManagerResetActionInfo derived class for delivering Manager |
| 271 | * ResetType AllowableValues using ResetInfo schema. |
| 272 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 273 | inline void requestRoutesManagerResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 274 | { |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 275 | /** |
| 276 | * Functions triggers appropriate requests on DBus |
| 277 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 278 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 279 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 280 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 281 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 282 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 283 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 284 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 285 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 286 | { |
| 287 | return; |
| 288 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 289 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 290 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 291 | { |
| 292 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 293 | managerId); |
| 294 | return; |
| 295 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 296 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 297 | asyncResp->res.jsonValue["@odata.type"] = |
| 298 | "#ActionInfo.v1_1_2.ActionInfo"; |
| 299 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 300 | "/redfish/v1/Managers/{}/ResetActionInfo", |
| 301 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 302 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
| 303 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 304 | nlohmann::json::object_t parameter; |
| 305 | parameter["Name"] = "ResetType"; |
| 306 | parameter["Required"] = true; |
| 307 | parameter["DataType"] = action_info::ParameterTypes::String; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 308 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 309 | nlohmann::json::array_t allowableValues; |
| 310 | allowableValues.emplace_back("GracefulRestart"); |
| 311 | allowableValues.emplace_back("ForceRestart"); |
| 312 | parameter["AllowableValues"] = std::move(allowableValues); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 313 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 314 | nlohmann::json::array_t parameters; |
| 315 | parameters.emplace_back(std::move(parameter)); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 316 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 317 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
| 318 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 319 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 320 | |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 321 | static constexpr const char* objectManagerIface = |
| 322 | "org.freedesktop.DBus.ObjectManager"; |
| 323 | static constexpr const char* pidConfigurationIface = |
| 324 | "xyz.openbmc_project.Configuration.Pid"; |
| 325 | static constexpr const char* pidZoneConfigurationIface = |
| 326 | "xyz.openbmc_project.Configuration.Pid.Zone"; |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 327 | static constexpr const char* stepwiseConfigurationIface = |
| 328 | "xyz.openbmc_project.Configuration.Stepwise"; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 329 | static constexpr const char* thermalModeIface = |
| 330 | "xyz.openbmc_project.Control.ThermalMode"; |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 331 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 332 | inline void |
| 333 | asyncPopulatePid(const std::string& connection, const std::string& path, |
| 334 | const std::string& currentProfile, |
| 335 | const std::vector<std::string>& supportedProfiles, |
| 336 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 337 | { |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 338 | sdbusplus::message::object_path objPath(path); |
| 339 | dbus::utility::getManagedObjects( |
| 340 | connection, objPath, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 341 | [asyncResp, currentProfile, supportedProfiles]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 342 | const boost::system::error_code& ec, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 343 | const dbus::utility::ManagedObjectType& managedObj) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 344 | if (ec) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 345 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 346 | BMCWEB_LOG_ERROR("{}", ec); |
| 347 | messages::internalError(asyncResp->res); |
| 348 | return; |
| 349 | } |
| 350 | nlohmann::json& configRoot = |
| 351 | asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; |
| 352 | nlohmann::json& fans = configRoot["FanControllers"]; |
| 353 | fans["@odata.type"] = |
| 354 | "#OpenBMCManager.v1_0_0.Manager.FanControllers"; |
| 355 | fans["@odata.id"] = boost::urls::format( |
| 356 | "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/FanControllers", |
| 357 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 358 | |
| 359 | nlohmann::json& pids = configRoot["PidControllers"]; |
| 360 | pids["@odata.type"] = |
| 361 | "#OpenBMCManager.v1_0_0.Manager.PidControllers"; |
| 362 | pids["@odata.id"] = boost::urls::format( |
| 363 | "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/PidControllers", |
| 364 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 365 | |
| 366 | nlohmann::json& stepwise = configRoot["StepwiseControllers"]; |
| 367 | stepwise["@odata.type"] = |
| 368 | "#OpenBMCManager.v1_0_0.Manager.StepwiseControllers"; |
| 369 | stepwise["@odata.id"] = boost::urls::format( |
| 370 | "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/StepwiseControllers", |
| 371 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 372 | |
| 373 | nlohmann::json& zones = configRoot["FanZones"]; |
| 374 | zones["@odata.id"] = boost::urls::format( |
| 375 | "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/FanZones", |
| 376 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 377 | zones["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager.FanZones"; |
| 378 | configRoot["@odata.id"] = |
| 379 | boost::urls::format("/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan", |
| 380 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 381 | configRoot["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager.Fan"; |
| 382 | configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; |
| 383 | |
| 384 | if (!currentProfile.empty()) |
| 385 | { |
| 386 | configRoot["Profile"] = currentProfile; |
| 387 | } |
| 388 | BMCWEB_LOG_DEBUG("profile = {} !", currentProfile); |
| 389 | |
| 390 | for (const auto& pathPair : managedObj) |
| 391 | { |
| 392 | for (const auto& intfPair : pathPair.second) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 393 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 394 | if (intfPair.first != pidConfigurationIface && |
| 395 | intfPair.first != pidZoneConfigurationIface && |
| 396 | intfPair.first != stepwiseConfigurationIface) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 397 | { |
| 398 | continue; |
| 399 | } |
| 400 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 401 | std::string name; |
| 402 | |
| 403 | for (const std::pair<std::string, |
| 404 | dbus::utility::DbusVariantType>& |
| 405 | propPair : intfPair.second) |
| 406 | { |
| 407 | if (propPair.first == "Name") |
| 408 | { |
| 409 | const std::string* namePtr = |
| 410 | std::get_if<std::string>(&propPair.second); |
| 411 | if (namePtr == nullptr) |
| 412 | { |
| 413 | BMCWEB_LOG_ERROR("Pid Name Field illegal"); |
| 414 | messages::internalError(asyncResp->res); |
| 415 | return; |
| 416 | } |
| 417 | name = *namePtr; |
| 418 | dbus::utility::escapePathForDbus(name); |
| 419 | } |
| 420 | else if (propPair.first == "Profiles") |
| 421 | { |
| 422 | const std::vector<std::string>* profiles = |
| 423 | std::get_if<std::vector<std::string>>( |
| 424 | &propPair.second); |
| 425 | if (profiles == nullptr) |
| 426 | { |
| 427 | BMCWEB_LOG_ERROR("Pid Profiles Field illegal"); |
| 428 | messages::internalError(asyncResp->res); |
| 429 | return; |
| 430 | } |
| 431 | if (std::find(profiles->begin(), profiles->end(), |
| 432 | currentProfile) == profiles->end()) |
| 433 | { |
| 434 | BMCWEB_LOG_INFO( |
| 435 | "{} not supported in current profile", |
| 436 | name); |
| 437 | continue; |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | nlohmann::json* config = nullptr; |
| 442 | const std::string* classPtr = nullptr; |
| 443 | |
| 444 | for (const std::pair<std::string, |
| 445 | dbus::utility::DbusVariantType>& |
| 446 | propPair : intfPair.second) |
| 447 | { |
| 448 | if (propPair.first == "Class") |
| 449 | { |
| 450 | classPtr = |
| 451 | std::get_if<std::string>(&propPair.second); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | boost::urls::url url( |
| 456 | boost::urls::format("/redfish/v1/Managers/{}", |
| 457 | BMCWEB_REDFISH_MANAGER_URI_NAME)); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 458 | if (intfPair.first == pidZoneConfigurationIface) |
| 459 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 460 | std::string chassis; |
| 461 | if (!dbus::utility::getNthStringFromPath( |
| 462 | pathPair.first.str, 5, chassis)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 463 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 464 | chassis = "#IllegalValue"; |
| 465 | } |
| 466 | nlohmann::json& zone = zones[name]; |
| 467 | zone["Chassis"]["@odata.id"] = boost::urls::format( |
| 468 | "/redfish/v1/Chassis/{}", chassis); |
| 469 | url.set_fragment( |
| 470 | ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) |
| 471 | .to_string()); |
| 472 | zone["@odata.id"] = std::move(url); |
| 473 | zone["@odata.type"] = |
| 474 | "#OpenBMCManager.v1_0_0.Manager.FanZone"; |
| 475 | config = &zone; |
| 476 | } |
| 477 | |
| 478 | else if (intfPair.first == stepwiseConfigurationIface) |
| 479 | { |
| 480 | if (classPtr == nullptr) |
| 481 | { |
| 482 | BMCWEB_LOG_ERROR("Pid Class Field illegal"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 483 | messages::internalError(asyncResp->res); |
| 484 | return; |
| 485 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 486 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 487 | nlohmann::json& controller = stepwise[name]; |
| 488 | config = &controller; |
| 489 | url.set_fragment( |
| 490 | ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / |
| 491 | name) |
| 492 | .to_string()); |
| 493 | controller["@odata.id"] = std::move(url); |
| 494 | controller["@odata.type"] = |
| 495 | "#OpenBMCManager.v1_0_0.Manager.StepwiseController"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 496 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 497 | controller["Direction"] = *classPtr; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 498 | } |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 499 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 500 | // pid and fans are off the same configuration |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 501 | else if (intfPair.first == pidConfigurationIface) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 502 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 503 | if (classPtr == nullptr) |
James Feist | b7a08d0 | 2018-12-11 14:55:37 -0800 | [diff] [blame] | 504 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 505 | BMCWEB_LOG_ERROR("Pid Class Field illegal"); |
| 506 | messages::internalError(asyncResp->res); |
| 507 | return; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 508 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 509 | bool isFan = *classPtr == "fan"; |
| 510 | nlohmann::json& element = |
| 511 | isFan ? fans[name] : pids[name]; |
| 512 | config = &element; |
| 513 | if (isFan) |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 514 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 515 | url.set_fragment( |
| 516 | ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / |
| 517 | name) |
| 518 | .to_string()); |
| 519 | element["@odata.id"] = std::move(url); |
| 520 | element["@odata.type"] = |
| 521 | "#OpenBMCManager.v1_0_0.Manager.FanController"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 522 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 523 | else |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 524 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 525 | url.set_fragment( |
| 526 | ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / |
| 527 | name) |
| 528 | .to_string()); |
| 529 | element["@odata.id"] = std::move(url); |
| 530 | element["@odata.type"] = |
| 531 | "#OpenBMCManager.v1_0_0.Manager.PidController"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 532 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 533 | } |
| 534 | else |
| 535 | { |
| 536 | BMCWEB_LOG_ERROR("Unexpected configuration"); |
| 537 | messages::internalError(asyncResp->res); |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | // used for making maps out of 2 vectors |
| 542 | const std::vector<double>* keys = nullptr; |
| 543 | const std::vector<double>* values = nullptr; |
| 544 | |
| 545 | for (const auto& propertyPair : intfPair.second) |
| 546 | { |
| 547 | if (propertyPair.first == "Type" || |
| 548 | propertyPair.first == "Class" || |
| 549 | propertyPair.first == "Name") |
| 550 | { |
| 551 | continue; |
| 552 | } |
| 553 | |
| 554 | // zones |
| 555 | if (intfPair.first == pidZoneConfigurationIface) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 556 | { |
| 557 | const double* ptr = |
| 558 | std::get_if<double>(&propertyPair.second); |
| 559 | if (ptr == nullptr) |
| 560 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 561 | BMCWEB_LOG_ERROR("Field Illegal {}", |
| 562 | propertyPair.first); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 563 | messages::internalError(asyncResp->res); |
| 564 | return; |
| 565 | } |
| 566 | (*config)[propertyPair.first] = *ptr; |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 567 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 568 | |
| 569 | if (intfPair.first == stepwiseConfigurationIface) |
| 570 | { |
| 571 | if (propertyPair.first == "Reading" || |
| 572 | propertyPair.first == "Output") |
| 573 | { |
| 574 | const std::vector<double>* ptr = |
| 575 | std::get_if<std::vector<double>>( |
| 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 | |
| 586 | if (propertyPair.first == "Reading") |
| 587 | { |
| 588 | keys = ptr; |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | values = ptr; |
| 593 | } |
| 594 | if (keys != nullptr && values != nullptr) |
| 595 | { |
| 596 | if (keys->size() != values->size()) |
| 597 | { |
| 598 | BMCWEB_LOG_ERROR( |
| 599 | "Reading and Output size don't match "); |
| 600 | messages::internalError(asyncResp->res); |
| 601 | return; |
| 602 | } |
| 603 | nlohmann::json& steps = (*config)["Steps"]; |
| 604 | steps = nlohmann::json::array(); |
| 605 | for (size_t ii = 0; ii < keys->size(); ii++) |
| 606 | { |
| 607 | nlohmann::json::object_t step; |
| 608 | step["Target"] = (*keys)[ii]; |
| 609 | step["Output"] = (*values)[ii]; |
| 610 | steps.emplace_back(std::move(step)); |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | if (propertyPair.first == "NegativeHysteresis" || |
| 615 | propertyPair.first == "PositiveHysteresis") |
| 616 | { |
| 617 | const double* ptr = |
| 618 | std::get_if<double>(&propertyPair.second); |
| 619 | if (ptr == nullptr) |
| 620 | { |
| 621 | BMCWEB_LOG_ERROR("Field Illegal {}", |
| 622 | propertyPair.first); |
| 623 | messages::internalError(asyncResp->res); |
| 624 | return; |
| 625 | } |
| 626 | (*config)[propertyPair.first] = *ptr; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // pid and fans are off the same configuration |
| 631 | if (intfPair.first == pidConfigurationIface || |
| 632 | intfPair.first == stepwiseConfigurationIface) |
| 633 | { |
| 634 | if (propertyPair.first == "Zones") |
| 635 | { |
| 636 | const std::vector<std::string>* inputs = |
| 637 | std::get_if<std::vector<std::string>>( |
| 638 | &propertyPair.second); |
| 639 | |
| 640 | if (inputs == nullptr) |
| 641 | { |
| 642 | BMCWEB_LOG_ERROR("Zones Pid Field Illegal"); |
| 643 | messages::internalError(asyncResp->res); |
| 644 | return; |
| 645 | } |
| 646 | auto& data = (*config)[propertyPair.first]; |
| 647 | data = nlohmann::json::array(); |
| 648 | for (std::string itemCopy : *inputs) |
| 649 | { |
| 650 | dbus::utility::escapePathForDbus(itemCopy); |
| 651 | nlohmann::json::object_t input; |
| 652 | boost::urls::url managerUrl = |
| 653 | boost::urls::format( |
| 654 | "/redfish/v1/Managers/{}#{}", |
| 655 | BMCWEB_REDFISH_MANAGER_URI_NAME, |
| 656 | ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / |
| 657 | itemCopy) |
| 658 | .to_string()); |
| 659 | input["@odata.id"] = std::move(managerUrl); |
| 660 | data.emplace_back(std::move(input)); |
| 661 | } |
| 662 | } |
| 663 | // todo(james): may never happen, but this |
| 664 | // assumes configuration data referenced in the |
| 665 | // PID config is provided by the same daemon, we |
| 666 | // could add another loop to cover all cases, |
| 667 | // but I'm okay kicking this can down the road a |
| 668 | // bit |
| 669 | |
| 670 | else if (propertyPair.first == "Inputs" || |
| 671 | propertyPair.first == "Outputs") |
| 672 | { |
| 673 | auto& data = (*config)[propertyPair.first]; |
| 674 | const std::vector<std::string>* inputs = |
| 675 | std::get_if<std::vector<std::string>>( |
| 676 | &propertyPair.second); |
| 677 | |
| 678 | if (inputs == nullptr) |
| 679 | { |
| 680 | BMCWEB_LOG_ERROR("Field Illegal {}", |
| 681 | propertyPair.first); |
| 682 | messages::internalError(asyncResp->res); |
| 683 | return; |
| 684 | } |
| 685 | data = *inputs; |
| 686 | } |
| 687 | else if (propertyPair.first == "SetPointOffset") |
| 688 | { |
| 689 | const std::string* ptr = |
| 690 | std::get_if<std::string>( |
| 691 | &propertyPair.second); |
| 692 | |
| 693 | if (ptr == nullptr) |
| 694 | { |
| 695 | BMCWEB_LOG_ERROR("Field Illegal {}", |
| 696 | propertyPair.first); |
| 697 | messages::internalError(asyncResp->res); |
| 698 | return; |
| 699 | } |
| 700 | // translate from dbus to redfish |
| 701 | if (*ptr == "WarningHigh") |
| 702 | { |
| 703 | (*config)["SetPointOffset"] = |
| 704 | "UpperThresholdNonCritical"; |
| 705 | } |
| 706 | else if (*ptr == "WarningLow") |
| 707 | { |
| 708 | (*config)["SetPointOffset"] = |
| 709 | "LowerThresholdNonCritical"; |
| 710 | } |
| 711 | else if (*ptr == "CriticalHigh") |
| 712 | { |
| 713 | (*config)["SetPointOffset"] = |
| 714 | "UpperThresholdCritical"; |
| 715 | } |
| 716 | else if (*ptr == "CriticalLow") |
| 717 | { |
| 718 | (*config)["SetPointOffset"] = |
| 719 | "LowerThresholdCritical"; |
| 720 | } |
| 721 | else |
| 722 | { |
| 723 | BMCWEB_LOG_ERROR("Value Illegal {}", *ptr); |
| 724 | messages::internalError(asyncResp->res); |
| 725 | return; |
| 726 | } |
| 727 | } |
| 728 | // doubles |
| 729 | else if (propertyPair.first == |
| 730 | "FFGainCoefficient" || |
| 731 | propertyPair.first == "FFOffCoefficient" || |
| 732 | propertyPair.first == "ICoefficient" || |
| 733 | propertyPair.first == "ILimitMax" || |
| 734 | propertyPair.first == "ILimitMin" || |
| 735 | propertyPair.first == |
| 736 | "PositiveHysteresis" || |
| 737 | propertyPair.first == |
| 738 | "NegativeHysteresis" || |
| 739 | propertyPair.first == "OutLimitMax" || |
| 740 | propertyPair.first == "OutLimitMin" || |
| 741 | propertyPair.first == "PCoefficient" || |
| 742 | propertyPair.first == "SetPoint" || |
| 743 | propertyPair.first == "SlewNeg" || |
| 744 | propertyPair.first == "SlewPos") |
| 745 | { |
| 746 | const double* ptr = |
| 747 | std::get_if<double>(&propertyPair.second); |
| 748 | if (ptr == nullptr) |
| 749 | { |
| 750 | BMCWEB_LOG_ERROR("Field Illegal {}", |
| 751 | propertyPair.first); |
| 752 | messages::internalError(asyncResp->res); |
| 753 | return; |
| 754 | } |
| 755 | (*config)[propertyPair.first] = *ptr; |
| 756 | } |
| 757 | } |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 761 | }); |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 762 | } |
Jennifer Lee | ca53792 | 2018-08-10 10:07:30 -0700 | [diff] [blame] | 763 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 764 | enum class CreatePIDRet |
| 765 | { |
| 766 | fail, |
| 767 | del, |
| 768 | patch |
| 769 | }; |
| 770 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 771 | inline bool |
| 772 | getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 773 | std::vector<nlohmann::json::object_t>& config, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 774 | std::vector<std::string>& zones) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 775 | { |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 776 | if (config.empty()) |
| 777 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 778 | BMCWEB_LOG_ERROR("Empty Zones"); |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 779 | messages::propertyValueFormatError(response->res, config, "Zones"); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 780 | return false; |
| 781 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 782 | for (auto& odata : config) |
| 783 | { |
| 784 | std::string path; |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 785 | if (!redfish::json_util::readJsonObject(odata, response->res, |
| 786 | "@odata.id", path)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 787 | { |
| 788 | return false; |
| 789 | } |
| 790 | std::string input; |
James Feist | 61adbda | 2019-03-25 13:03:51 -0700 | [diff] [blame] | 791 | |
| 792 | // 8 below comes from |
| 793 | // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left |
| 794 | // 0 1 2 3 4 5 6 7 8 |
| 795 | if (!dbus::utility::getNthStringFromPath(path, 8, input)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 796 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 797 | BMCWEB_LOG_ERROR("Got invalid path {}", path); |
| 798 | BMCWEB_LOG_ERROR("Illegal Type Zones"); |
Ed Tanous | f818b04 | 2022-06-27 13:17:35 -0700 | [diff] [blame] | 799 | messages::propertyValueFormatError(response->res, odata, "Zones"); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 800 | return false; |
| 801 | } |
Ed Tanous | a170f27 | 2022-06-30 21:53:27 -0700 | [diff] [blame] | 802 | std::replace(input.begin(), input.end(), '_', ' '); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 803 | zones.emplace_back(std::move(input)); |
| 804 | } |
| 805 | return true; |
| 806 | } |
| 807 | |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 808 | inline const dbus::utility::ManagedObjectType::value_type* |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 809 | findChassis(const dbus::utility::ManagedObjectType& managedObj, |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 810 | std::string_view value, std::string& chassis) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 811 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 812 | BMCWEB_LOG_DEBUG("Find Chassis: {}", value); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 813 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 814 | std::string escaped(value); |
Yaswanth Reddy M | 6ce82fa | 2023-03-10 07:29:45 +0000 | [diff] [blame] | 815 | std::replace(escaped.begin(), escaped.end(), ' ', '_'); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 816 | escaped = "/" + escaped; |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 817 | auto it = std::ranges::find_if(managedObj, [&escaped](const auto& obj) { |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 818 | if (obj.first.str.ends_with(escaped)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 819 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 820 | BMCWEB_LOG_DEBUG("Matched {}", obj.first.str); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 821 | return true; |
| 822 | } |
| 823 | return false; |
| 824 | }); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 825 | |
| 826 | if (it == managedObj.end()) |
| 827 | { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 828 | return nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 829 | } |
| 830 | // 5 comes from <chassis-name> being the 5th element |
| 831 | // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 832 | if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) |
| 833 | { |
| 834 | return &(*it); |
| 835 | } |
| 836 | |
| 837 | return nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 838 | } |
| 839 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 840 | inline CreatePIDRet createPidInterface( |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 841 | const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 842 | std::string_view name, nlohmann::json& jsonValue, const std::string& path, |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 843 | const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 844 | dbus::utility::DBusPropertiesMap& output, std::string& chassis, |
| 845 | const std::string& profile) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 846 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 847 | // common deleter |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 848 | if (jsonValue == nullptr) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 849 | { |
| 850 | std::string iface; |
| 851 | if (type == "PidControllers" || type == "FanControllers") |
| 852 | { |
| 853 | iface = pidConfigurationIface; |
| 854 | } |
| 855 | else if (type == "FanZones") |
| 856 | { |
| 857 | iface = pidZoneConfigurationIface; |
| 858 | } |
| 859 | else if (type == "StepwiseControllers") |
| 860 | { |
| 861 | iface = stepwiseConfigurationIface; |
| 862 | } |
| 863 | else |
| 864 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 865 | BMCWEB_LOG_ERROR("Illegal Type {}", type); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 866 | messages::propertyUnknown(response->res, type); |
| 867 | return CreatePIDRet::fail; |
| 868 | } |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 869 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 870 | BMCWEB_LOG_DEBUG("del {} {}", path, iface); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 871 | // delete interface |
| 872 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 873 | [response, path](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 874 | if (ec) |
| 875 | { |
| 876 | BMCWEB_LOG_ERROR("Error patching {}: {}", path, ec); |
| 877 | messages::internalError(response->res); |
| 878 | return; |
| 879 | } |
| 880 | messages::success(response->res); |
| 881 | }, |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 882 | "xyz.openbmc_project.EntityManager", path, iface, "Delete"); |
| 883 | return CreatePIDRet::del; |
| 884 | } |
| 885 | |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 886 | const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 887 | if (!createNewObject) |
| 888 | { |
| 889 | // if we aren't creating a new object, we should be able to find it on |
| 890 | // d-bus |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 891 | managedItem = findChassis(managedObj, name, chassis); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 892 | if (managedItem == nullptr) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 893 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 894 | BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 895 | messages::invalidObject( |
| 896 | response->res, |
| 897 | boost::urls::format("/redfish/v1/Chassis/{}", chassis)); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 898 | return CreatePIDRet::fail; |
| 899 | } |
| 900 | } |
| 901 | |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 902 | if (!profile.empty() && |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 903 | (type == "PidControllers" || type == "FanControllers" || |
| 904 | type == "StepwiseControllers")) |
| 905 | { |
| 906 | if (managedItem == nullptr) |
| 907 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 908 | output.emplace_back("Profiles", std::vector<std::string>{profile}); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 909 | } |
| 910 | else |
| 911 | { |
| 912 | std::string interface; |
| 913 | if (type == "StepwiseControllers") |
| 914 | { |
| 915 | interface = stepwiseConfigurationIface; |
| 916 | } |
| 917 | else |
| 918 | { |
| 919 | interface = pidConfigurationIface; |
| 920 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 921 | bool ifaceFound = false; |
| 922 | for (const auto& iface : managedItem->second) |
| 923 | { |
| 924 | if (iface.first == interface) |
| 925 | { |
| 926 | ifaceFound = true; |
| 927 | for (const auto& prop : iface.second) |
| 928 | { |
| 929 | if (prop.first == "Profiles") |
| 930 | { |
| 931 | const std::vector<std::string>* curProfiles = |
| 932 | std::get_if<std::vector<std::string>>( |
| 933 | &(prop.second)); |
| 934 | if (curProfiles == nullptr) |
| 935 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 936 | BMCWEB_LOG_ERROR( |
| 937 | "Illegal profiles in managed object"); |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 938 | messages::internalError(response->res); |
| 939 | return CreatePIDRet::fail; |
| 940 | } |
| 941 | if (std::find(curProfiles->begin(), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 942 | curProfiles->end(), profile) == |
| 943 | curProfiles->end()) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 944 | { |
| 945 | std::vector<std::string> newProfiles = |
| 946 | *curProfiles; |
| 947 | newProfiles.push_back(profile); |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 948 | output.emplace_back("Profiles", newProfiles); |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | if (!ifaceFound) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 956 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 957 | BMCWEB_LOG_ERROR("Failed to find interface in managed object"); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 958 | messages::internalError(response->res); |
| 959 | return CreatePIDRet::fail; |
| 960 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 964 | if (type == "PidControllers" || type == "FanControllers") |
| 965 | { |
| 966 | if (createNewObject) |
| 967 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 968 | output.emplace_back("Class", |
| 969 | type == "PidControllers" ? "temp" : "fan"); |
| 970 | output.emplace_back("Type", "Pid"); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 971 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 972 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 973 | std::optional<std::vector<nlohmann::json::object_t>> zones; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 974 | std::optional<std::vector<std::string>> inputs; |
| 975 | std::optional<std::vector<std::string>> outputs; |
| 976 | std::map<std::string, std::optional<double>> doubles; |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 977 | std::optional<std::string> setpointOffset; |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 978 | if (!redfish::json_util::readJson( // |
| 979 | jsonValue, response->res, // |
| 980 | "FFGainCoefficient", doubles["FFGainCoefficient"], // |
| 981 | "FFOffCoefficient", doubles["FFOffCoefficient"], // |
| 982 | "ICoefficient", doubles["ICoefficient"], // |
| 983 | "ILimitMax", doubles["ILimitMax"], // |
| 984 | "ILimitMin", doubles["ILimitMin"], // |
| 985 | "Inputs", inputs, // |
| 986 | "NegativeHysteresis", doubles["NegativeHysteresis"], // |
| 987 | "OutLimitMax", doubles["OutLimitMax"], // |
| 988 | "OutLimitMin", doubles["OutLimitMin"], // |
| 989 | "Outputs", outputs, // |
| 990 | "PCoefficient", doubles["PCoefficient"], // |
| 991 | "PositiveHysteresis", doubles["PositiveHysteresis"], // |
| 992 | "SetPoint", doubles["SetPoint"], // |
| 993 | "SetPointOffset", setpointOffset, // |
| 994 | "SlewNeg", doubles["SlewNeg"], // |
| 995 | "SlewPos", doubles["SlewPos"], // |
| 996 | "Zones", zones // |
| 997 | )) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 998 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 999 | return CreatePIDRet::fail; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1000 | } |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 1001 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1002 | if (zones) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1003 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1004 | std::vector<std::string> zonesStr; |
| 1005 | if (!getZonesFromJsonReq(response, *zones, zonesStr)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1006 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1007 | BMCWEB_LOG_ERROR("Illegal Zones"); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1008 | return CreatePIDRet::fail; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1009 | } |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1010 | if (chassis.empty() && |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 1011 | findChassis(managedObj, zonesStr[0], chassis) == nullptr) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1012 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1013 | BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1014 | messages::invalidObject( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1015 | response->res, |
| 1016 | boost::urls::format("/redfish/v1/Chassis/{}", chassis)); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1017 | return CreatePIDRet::fail; |
| 1018 | } |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1019 | output.emplace_back("Zones", std::move(zonesStr)); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1020 | } |
Ed Tanous | afb9ee0 | 2022-12-21 11:59:17 -0800 | [diff] [blame] | 1021 | |
| 1022 | if (inputs) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1023 | { |
Ed Tanous | afb9ee0 | 2022-12-21 11:59:17 -0800 | [diff] [blame] | 1024 | for (std::string& value : *inputs) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1025 | { |
Ed Tanous | afb9ee0 | 2022-12-21 11:59:17 -0800 | [diff] [blame] | 1026 | std::replace(value.begin(), value.end(), '_', ' '); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1027 | } |
Ed Tanous | afb9ee0 | 2022-12-21 11:59:17 -0800 | [diff] [blame] | 1028 | output.emplace_back("Inputs", *inputs); |
| 1029 | } |
| 1030 | |
| 1031 | if (outputs) |
| 1032 | { |
| 1033 | for (std::string& value : *outputs) |
| 1034 | { |
| 1035 | std::replace(value.begin(), value.end(), '_', ' '); |
| 1036 | } |
| 1037 | output.emplace_back("Outputs", *outputs); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1038 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1039 | |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1040 | if (setpointOffset) |
| 1041 | { |
| 1042 | // translate between redfish and dbus names |
| 1043 | if (*setpointOffset == "UpperThresholdNonCritical") |
| 1044 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1045 | output.emplace_back("SetPointOffset", "WarningLow"); |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1046 | } |
| 1047 | else if (*setpointOffset == "LowerThresholdNonCritical") |
| 1048 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1049 | output.emplace_back("SetPointOffset", "WarningHigh"); |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1050 | } |
| 1051 | else if (*setpointOffset == "LowerThresholdCritical") |
| 1052 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1053 | output.emplace_back("SetPointOffset", "CriticalLow"); |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1054 | } |
| 1055 | else if (*setpointOffset == "UpperThresholdCritical") |
| 1056 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1057 | output.emplace_back("SetPointOffset", "CriticalHigh"); |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1058 | } |
| 1059 | else |
| 1060 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1061 | BMCWEB_LOG_ERROR("Invalid setpointoffset {}", *setpointOffset); |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1062 | messages::propertyValueNotInList(response->res, name, |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1063 | "SetPointOffset"); |
James Feist | b943aae | 2019-07-11 16:33:56 -0700 | [diff] [blame] | 1064 | return CreatePIDRet::fail; |
| 1065 | } |
| 1066 | } |
| 1067 | |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1068 | // doubles |
| 1069 | for (const auto& pairs : doubles) |
| 1070 | { |
| 1071 | if (!pairs.second) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1072 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1073 | continue; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1074 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1075 | BMCWEB_LOG_DEBUG("{} = {}", pairs.first, *pairs.second); |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1076 | output.emplace_back(pairs.first, *pairs.second); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1079 | |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1080 | else if (type == "FanZones") |
| 1081 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1082 | output.emplace_back("Type", "Pid.Zone"); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1083 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1084 | std::optional<std::string> chassisId; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1085 | std::optional<double> failSafePercent; |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 1086 | std::optional<double> minThermalOutput; |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 1087 | if (!redfish::json_util::readJson( // |
| 1088 | jsonValue, response->res, // |
| 1089 | "Chassis/@odata.id", chassisId, // |
| 1090 | "FailSafePercent", failSafePercent, // |
| 1091 | "MinThermalOutput", minThermalOutput)) |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1092 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1093 | return CreatePIDRet::fail; |
| 1094 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1095 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1096 | if (chassisId) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1097 | { |
AppaRao Puli | 717794d | 2019-10-18 22:54:53 +0530 | [diff] [blame] | 1098 | // /redfish/v1/chassis/chassis_name/ |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1099 | if (!dbus::utility::getNthStringFromPath(*chassisId, 3, chassis)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1100 | { |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1101 | BMCWEB_LOG_ERROR("Got invalid path {}", *chassisId); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1102 | messages::invalidObject( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1103 | response->res, |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1104 | boost::urls::format("/redfish/v1/Chassis/{}", *chassisId)); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1105 | return CreatePIDRet::fail; |
| 1106 | } |
| 1107 | } |
James Feist | d3ec07f | 2019-02-25 14:51:15 -0800 | [diff] [blame] | 1108 | if (minThermalOutput) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1109 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1110 | output.emplace_back("MinThermalOutput", *minThermalOutput); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1111 | } |
| 1112 | if (failSafePercent) |
| 1113 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1114 | output.emplace_back("FailSafePercent", *failSafePercent); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | else if (type == "StepwiseControllers") |
| 1118 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1119 | output.emplace_back("Type", "Stepwise"); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1120 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1121 | std::optional<std::vector<nlohmann::json::object_t>> zones; |
| 1122 | std::optional<std::vector<nlohmann::json::object_t>> steps; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1123 | std::optional<std::vector<std::string>> inputs; |
| 1124 | std::optional<double> positiveHysteresis; |
| 1125 | std::optional<double> negativeHysteresis; |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 1126 | std::optional<std::string> direction; // upper clipping curve vs lower |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 1127 | if (!redfish::json_util::readJson( // |
| 1128 | jsonValue, response->res, // |
| 1129 | "Direction", direction, // |
| 1130 | "Inputs", inputs, // |
| 1131 | "NegativeHysteresis", negativeHysteresis, // |
| 1132 | "PositiveHysteresis", positiveHysteresis, // |
| 1133 | "Steps", steps, // |
| 1134 | "Zones", zones // |
| 1135 | )) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1136 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1137 | return CreatePIDRet::fail; |
| 1138 | } |
| 1139 | |
| 1140 | if (zones) |
| 1141 | { |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1142 | std::vector<std::string> zonesStrs; |
| 1143 | if (!getZonesFromJsonReq(response, *zones, zonesStrs)) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1144 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1145 | BMCWEB_LOG_ERROR("Illegal Zones"); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1146 | return CreatePIDRet::fail; |
| 1147 | } |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1148 | if (chassis.empty() && |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 1149 | findChassis(managedObj, zonesStrs[0], chassis) == nullptr) |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1150 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1151 | BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1152 | messages::invalidObject( |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1153 | response->res, |
| 1154 | boost::urls::format("/redfish/v1/Chassis/{}", chassis)); |
James Feist | b6baeaa | 2019-02-21 10:41:40 -0800 | [diff] [blame] | 1155 | return CreatePIDRet::fail; |
| 1156 | } |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1157 | output.emplace_back("Zones", std::move(zonesStrs)); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1158 | } |
| 1159 | if (steps) |
| 1160 | { |
| 1161 | std::vector<double> readings; |
| 1162 | std::vector<double> outputs; |
| 1163 | for (auto& step : *steps) |
| 1164 | { |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 1165 | double target = 0.0; |
| 1166 | double out = 0.0; |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1167 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 1168 | if (!redfish::json_util::readJsonObject( // |
| 1169 | step, response->res, // |
| 1170 | "Output", out, // |
| 1171 | "Target", target // |
| 1172 | )) |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1173 | { |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1174 | return CreatePIDRet::fail; |
| 1175 | } |
| 1176 | readings.emplace_back(target); |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1177 | outputs.emplace_back(out); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1178 | } |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1179 | output.emplace_back("Reading", std::move(readings)); |
| 1180 | output.emplace_back("Output", std::move(outputs)); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1181 | } |
| 1182 | if (inputs) |
| 1183 | { |
| 1184 | for (std::string& value : *inputs) |
| 1185 | { |
Ed Tanous | a170f27 | 2022-06-30 21:53:27 -0700 | [diff] [blame] | 1186 | std::replace(value.begin(), value.end(), '_', ' '); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1187 | } |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1188 | output.emplace_back("Inputs", std::move(*inputs)); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1189 | } |
| 1190 | if (negativeHysteresis) |
| 1191 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1192 | output.emplace_back("NegativeHysteresis", *negativeHysteresis); |
James Feist | 5f2caae | 2018-12-12 14:08:25 -0800 | [diff] [blame] | 1193 | } |
| 1194 | if (positiveHysteresis) |
| 1195 | { |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1196 | output.emplace_back("PositiveHysteresis", *positiveHysteresis); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1197 | } |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 1198 | if (direction) |
| 1199 | { |
| 1200 | constexpr const std::array<const char*, 2> allowedDirections = { |
| 1201 | "Ceiling", "Floor"}; |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1202 | if (std::ranges::find(allowedDirections, *direction) == |
| 1203 | allowedDirections.end()) |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 1204 | { |
| 1205 | messages::propertyValueTypeError(response->res, "Direction", |
| 1206 | *direction); |
| 1207 | return CreatePIDRet::fail; |
| 1208 | } |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1209 | output.emplace_back("Class", *direction); |
James Feist | c33a90e | 2019-03-01 10:17:44 -0800 | [diff] [blame] | 1210 | } |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1211 | } |
| 1212 | else |
| 1213 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1214 | BMCWEB_LOG_ERROR("Illegal Type {}", type); |
Jason M. Bills | 35a62c7 | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1215 | messages::propertyUnknown(response->res, type); |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1216 | return CreatePIDRet::fail; |
| 1217 | } |
| 1218 | return CreatePIDRet::patch; |
| 1219 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1220 | struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> |
| 1221 | { |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1222 | struct CompletionValues |
| 1223 | { |
| 1224 | std::vector<std::string> supportedProfiles; |
| 1225 | std::string currentProfile; |
| 1226 | dbus::utility::MapperGetSubTreeResponse subtree; |
| 1227 | }; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1228 | |
Ed Tanous | 4e23a44 | 2022-06-06 09:57:26 -0700 | [diff] [blame] | 1229 | explicit GetPIDValues( |
| 1230 | const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1231 | asyncResp(asyncRespIn) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1232 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1233 | {} |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1234 | |
| 1235 | void run() |
| 1236 | { |
| 1237 | std::shared_ptr<GetPIDValues> self = shared_from_this(); |
| 1238 | |
| 1239 | // get all configurations |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1240 | constexpr std::array<std::string_view, 4> interfaces = { |
| 1241 | pidConfigurationIface, pidZoneConfigurationIface, |
| 1242 | objectManagerIface, stepwiseConfigurationIface}; |
| 1243 | dbus::utility::getSubTree( |
| 1244 | "/", 0, interfaces, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1245 | [self]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1246 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1247 | const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1248 | if (ec) |
| 1249 | { |
| 1250 | BMCWEB_LOG_ERROR("{}", ec); |
| 1251 | messages::internalError(self->asyncResp->res); |
| 1252 | return; |
| 1253 | } |
| 1254 | self->complete.subtree = subtreeLocal; |
| 1255 | }); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1256 | |
| 1257 | // at the same time get the selected profile |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1258 | constexpr std::array<std::string_view, 1> thermalModeIfaces = { |
| 1259 | thermalModeIface}; |
| 1260 | dbus::utility::getSubTree( |
| 1261 | "/", 0, thermalModeIfaces, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1262 | [self]( |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1263 | const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1264 | const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1265 | if (ec || subtreeLocal.empty()) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1266 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1267 | return; |
| 1268 | } |
| 1269 | if (subtreeLocal[0].second.size() != 1) |
| 1270 | { |
| 1271 | // invalid mapper response, should never happen |
| 1272 | BMCWEB_LOG_ERROR("GetPIDValues: Mapper Error"); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1273 | messages::internalError(self->asyncResp->res); |
| 1274 | return; |
| 1275 | } |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1276 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1277 | const std::string& path = subtreeLocal[0].first; |
| 1278 | const std::string& owner = subtreeLocal[0].second[0].first; |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1279 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1280 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1281 | *crow::connections::systemBus, owner, path, |
| 1282 | thermalModeIface, |
| 1283 | [path, owner, |
| 1284 | self](const boost::system::error_code& ec2, |
| 1285 | const dbus::utility::DBusPropertiesMap& resp) { |
| 1286 | if (ec2) |
| 1287 | { |
| 1288 | BMCWEB_LOG_ERROR( |
| 1289 | "GetPIDValues: Can't get thermalModeIface {}", |
| 1290 | path); |
| 1291 | messages::internalError(self->asyncResp->res); |
| 1292 | return; |
| 1293 | } |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1294 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1295 | const std::string* current = nullptr; |
| 1296 | const std::vector<std::string>* supported = nullptr; |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1297 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1298 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1299 | dbus_utils::UnpackErrorPrinter(), resp, "Current", |
| 1300 | current, "Supported", supported); |
| 1301 | |
| 1302 | if (!success) |
| 1303 | { |
| 1304 | messages::internalError(self->asyncResp->res); |
| 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | if (current == nullptr || supported == nullptr) |
| 1309 | { |
| 1310 | BMCWEB_LOG_ERROR( |
| 1311 | "GetPIDValues: thermal mode iface invalid {}", |
| 1312 | path); |
| 1313 | messages::internalError(self->asyncResp->res); |
| 1314 | return; |
| 1315 | } |
| 1316 | self->complete.currentProfile = *current; |
| 1317 | self->complete.supportedProfiles = *supported; |
| 1318 | }); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1319 | }); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1322 | static void |
| 1323 | processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1324 | const CompletionValues& completion) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1325 | { |
| 1326 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1327 | { |
| 1328 | return; |
| 1329 | } |
| 1330 | // create map of <connection, path to objMgr>> |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1331 | boost::container::flat_map< |
| 1332 | std::string, std::string, std::less<>, |
| 1333 | std::vector<std::pair<std::string, std::string>>> |
| 1334 | objectMgrPaths; |
| 1335 | boost::container::flat_set<std::string, std::less<>, |
| 1336 | std::vector<std::string>> |
| 1337 | calledConnections; |
| 1338 | for (const auto& pathGroup : completion.subtree) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1339 | { |
| 1340 | for (const auto& connectionGroup : pathGroup.second) |
| 1341 | { |
| 1342 | auto findConnection = |
| 1343 | calledConnections.find(connectionGroup.first); |
| 1344 | if (findConnection != calledConnections.end()) |
| 1345 | { |
| 1346 | break; |
| 1347 | } |
| 1348 | for (const std::string& interface : connectionGroup.second) |
| 1349 | { |
| 1350 | if (interface == objectManagerIface) |
| 1351 | { |
| 1352 | objectMgrPaths[connectionGroup.first] = pathGroup.first; |
| 1353 | } |
| 1354 | // this list is alphabetical, so we |
| 1355 | // should have found the objMgr by now |
| 1356 | if (interface == pidConfigurationIface || |
| 1357 | interface == pidZoneConfigurationIface || |
| 1358 | interface == stepwiseConfigurationIface) |
| 1359 | { |
| 1360 | auto findObjMgr = |
| 1361 | objectMgrPaths.find(connectionGroup.first); |
| 1362 | if (findObjMgr == objectMgrPaths.end()) |
| 1363 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1364 | BMCWEB_LOG_DEBUG("{}Has no Object Manager", |
| 1365 | connectionGroup.first); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1366 | continue; |
| 1367 | } |
| 1368 | |
| 1369 | calledConnections.insert(connectionGroup.first); |
| 1370 | |
| 1371 | asyncPopulatePid(findObjMgr->first, findObjMgr->second, |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1372 | completion.currentProfile, |
| 1373 | completion.supportedProfiles, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1374 | asyncResp); |
| 1375 | break; |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | } |
| 1381 | |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1382 | ~GetPIDValues() |
| 1383 | { |
| 1384 | boost::asio::post(crow::connections::systemBus->get_io_context(), |
| 1385 | std::bind_front(&processingComplete, asyncResp, |
| 1386 | std::move(complete))); |
| 1387 | } |
| 1388 | |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 1389 | GetPIDValues(const GetPIDValues&) = delete; |
| 1390 | GetPIDValues(GetPIDValues&&) = delete; |
| 1391 | GetPIDValues& operator=(const GetPIDValues&) = delete; |
| 1392 | GetPIDValues& operator=(GetPIDValues&&) = delete; |
| 1393 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1394 | std::shared_ptr<bmcweb::AsyncResp> asyncResp; |
Ed Tanous | 6936afe | 2022-09-08 15:10:39 -0700 | [diff] [blame] | 1395 | CompletionValues complete; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1396 | }; |
| 1397 | |
| 1398 | struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> |
| 1399 | { |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1400 | SetPIDValues( |
| 1401 | const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, |
| 1402 | std::vector< |
| 1403 | std::pair<std::string, std::optional<nlohmann::json::object_t>>>&& |
| 1404 | configurationsIn, |
| 1405 | std::optional<std::string>& profileIn) : |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1406 | asyncResp(asyncRespIn), configuration(std::move(configurationsIn)), |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1407 | profile(std::move(profileIn)) |
| 1408 | {} |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 1409 | |
| 1410 | SetPIDValues(const SetPIDValues&) = delete; |
| 1411 | SetPIDValues(SetPIDValues&&) = delete; |
| 1412 | SetPIDValues& operator=(const SetPIDValues&) = delete; |
| 1413 | SetPIDValues& operator=(SetPIDValues&&) = delete; |
| 1414 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1415 | void run() |
| 1416 | { |
| 1417 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1418 | { |
| 1419 | return; |
| 1420 | } |
| 1421 | |
| 1422 | std::shared_ptr<SetPIDValues> self = shared_from_this(); |
| 1423 | |
| 1424 | // todo(james): might make sense to do a mapper call here if this |
| 1425 | // interface gets more traction |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1426 | sdbusplus::message::object_path objPath( |
| 1427 | "/xyz/openbmc_project/inventory"); |
| 1428 | dbus::utility::getManagedObjects( |
| 1429 | "xyz.openbmc_project.EntityManager", objPath, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1430 | [self](const boost::system::error_code& ec, |
Ed Tanous | 914e2d5 | 2022-01-07 11:38:34 -0800 | [diff] [blame] | 1431 | const dbus::utility::ManagedObjectType& mObj) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1432 | if (ec) |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1433 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1434 | BMCWEB_LOG_ERROR("Error communicating to Entity Manager"); |
| 1435 | messages::internalError(self->asyncResp->res); |
| 1436 | return; |
| 1437 | } |
| 1438 | const std::array<const char*, 3> configurations = { |
| 1439 | pidConfigurationIface, pidZoneConfigurationIface, |
| 1440 | stepwiseConfigurationIface}; |
| 1441 | |
| 1442 | for (const auto& [path, object] : mObj) |
| 1443 | { |
| 1444 | for (const auto& [interface, _] : object) |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1445 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1446 | if (std::ranges::find(configurations, interface) != |
| 1447 | configurations.end()) |
| 1448 | { |
| 1449 | self->objectCount++; |
| 1450 | break; |
| 1451 | } |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1452 | } |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1453 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1454 | self->managedObj = mObj; |
| 1455 | }); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1456 | |
| 1457 | // at the same time get the profile information |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1458 | constexpr std::array<std::string_view, 1> thermalModeIfaces = { |
| 1459 | thermalModeIface}; |
| 1460 | dbus::utility::getSubTree( |
| 1461 | "/", 0, thermalModeIfaces, |
| 1462 | [self](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1463 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1464 | if (ec || subtree.empty()) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1465 | { |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1466 | return; |
| 1467 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1468 | if (subtree[0].second.empty()) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1469 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1470 | // invalid mapper response, should never happen |
| 1471 | BMCWEB_LOG_ERROR("SetPIDValues: Mapper Error"); |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1472 | messages::internalError(self->asyncResp->res); |
| 1473 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1474 | } |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 1475 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1476 | const std::string& path = subtree[0].first; |
| 1477 | const std::string& owner = subtree[0].second[0].first; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1478 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1479 | *crow::connections::systemBus, owner, path, |
| 1480 | thermalModeIface, |
| 1481 | [self, path, |
| 1482 | owner](const boost::system::error_code& ec2, |
| 1483 | const dbus::utility::DBusPropertiesMap& r) { |
| 1484 | if (ec2) |
| 1485 | { |
| 1486 | BMCWEB_LOG_ERROR( |
| 1487 | "SetPIDValues: Can't get thermalModeIface {}", |
| 1488 | path); |
| 1489 | messages::internalError(self->asyncResp->res); |
| 1490 | return; |
| 1491 | } |
| 1492 | const std::string* current = nullptr; |
| 1493 | const std::vector<std::string>* supported = nullptr; |
| 1494 | |
| 1495 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1496 | dbus_utils::UnpackErrorPrinter(), r, "Current", |
| 1497 | current, "Supported", supported); |
| 1498 | |
| 1499 | if (!success) |
| 1500 | { |
| 1501 | messages::internalError(self->asyncResp->res); |
| 1502 | return; |
| 1503 | } |
| 1504 | |
| 1505 | if (current == nullptr || supported == nullptr) |
| 1506 | { |
| 1507 | BMCWEB_LOG_ERROR( |
| 1508 | "SetPIDValues: thermal mode iface invalid {}", |
| 1509 | path); |
| 1510 | messages::internalError(self->asyncResp->res); |
| 1511 | return; |
| 1512 | } |
| 1513 | self->currentProfile = *current; |
| 1514 | self->supportedProfiles = *supported; |
| 1515 | self->profileConnection = owner; |
| 1516 | self->profilePath = path; |
| 1517 | }); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1518 | }); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1519 | } |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 1520 | void pidSetDone() |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1521 | { |
| 1522 | if (asyncResp->res.result() != boost::beast::http::status::ok) |
| 1523 | { |
| 1524 | return; |
| 1525 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1526 | std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1527 | if (profile) |
| 1528 | { |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1529 | if (std::ranges::find(supportedProfiles, *profile) == |
| 1530 | supportedProfiles.end()) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1531 | { |
| 1532 | messages::actionParameterUnknown(response->res, "Profile", |
| 1533 | *profile); |
| 1534 | return; |
| 1535 | } |
| 1536 | currentProfile = *profile; |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 1537 | sdbusplus::asio::setProperty( |
| 1538 | *crow::connections::systemBus, profileConnection, profilePath, |
| 1539 | thermalModeIface, "Current", *profile, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1540 | [response](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1541 | if (ec) |
| 1542 | { |
| 1543 | BMCWEB_LOG_ERROR("Error patching profile{}", ec); |
| 1544 | messages::internalError(response->res); |
| 1545 | } |
| 1546 | }); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | for (auto& containerPair : configuration) |
| 1550 | { |
| 1551 | auto& container = containerPair.second; |
| 1552 | if (!container) |
| 1553 | { |
| 1554 | continue; |
| 1555 | } |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1556 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 1557 | const std::string& type = containerPair.first; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1558 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1559 | for (auto& [name, value] : *container) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1560 | { |
Potin Lai | cddbf3d | 2023-02-14 14:28:58 +0800 | [diff] [blame] | 1561 | std::string dbusObjName = name; |
| 1562 | std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1563 | BMCWEB_LOG_DEBUG("looking for {}", name); |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1564 | |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 1565 | auto pathItr = std::ranges::find_if( |
| 1566 | managedObj, [&dbusObjName](const auto& obj) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1567 | return obj.first.filename() == dbusObjName; |
| 1568 | }); |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1569 | dbus::utility::DBusPropertiesMap output; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1570 | |
| 1571 | output.reserve(16); // The pid interface length |
| 1572 | |
| 1573 | // determines if we're patching entity-manager or |
| 1574 | // creating a new object |
| 1575 | bool createNewObject = (pathItr == managedObj.end()); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1576 | BMCWEB_LOG_DEBUG("Found = {}", !createNewObject); |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1577 | |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1578 | std::string iface; |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1579 | if (!createNewObject) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1580 | { |
Potin Lai | 8be2b5b | 2022-11-22 13:27:16 +0800 | [diff] [blame] | 1581 | bool findInterface = false; |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1582 | for (const auto& interface : pathItr->second) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1583 | { |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1584 | if (interface.first == pidConfigurationIface) |
| 1585 | { |
| 1586 | if (type == "PidControllers" || |
| 1587 | type == "FanControllers") |
| 1588 | { |
| 1589 | iface = pidConfigurationIface; |
Potin Lai | 8be2b5b | 2022-11-22 13:27:16 +0800 | [diff] [blame] | 1590 | findInterface = true; |
| 1591 | break; |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | else if (interface.first == pidZoneConfigurationIface) |
| 1595 | { |
| 1596 | if (type == "FanZones") |
| 1597 | { |
PavanKumarIntel | da39350 | 2024-03-15 05:47:02 +0000 | [diff] [blame] | 1598 | iface = pidZoneConfigurationIface; |
Potin Lai | 8be2b5b | 2022-11-22 13:27:16 +0800 | [diff] [blame] | 1599 | findInterface = true; |
| 1600 | break; |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | else if (interface.first == stepwiseConfigurationIface) |
| 1604 | { |
| 1605 | if (type == "StepwiseControllers") |
| 1606 | { |
| 1607 | iface = stepwiseConfigurationIface; |
Potin Lai | 8be2b5b | 2022-11-22 13:27:16 +0800 | [diff] [blame] | 1608 | findInterface = true; |
| 1609 | break; |
Ed Tanous | ea2b670 | 2022-03-07 16:48:38 -0800 | [diff] [blame] | 1610 | } |
| 1611 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1612 | } |
Potin Lai | 8be2b5b | 2022-11-22 13:27:16 +0800 | [diff] [blame] | 1613 | |
| 1614 | // create new object if interface not found |
| 1615 | if (!findInterface) |
| 1616 | { |
| 1617 | createNewObject = true; |
| 1618 | } |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1619 | } |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1620 | |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1621 | if (createNewObject && value == nullptr) |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1622 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 1623 | // can't delete a non-existent object |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1624 | messages::propertyValueNotInList(response->res, value, |
Ed Tanous | e2616cc | 2022-06-27 12:45:55 -0700 | [diff] [blame] | 1625 | name); |
James Feist | 6ee7f77 | 2020-02-06 16:25:27 -0800 | [diff] [blame] | 1626 | continue; |
| 1627 | } |
| 1628 | |
| 1629 | std::string path; |
| 1630 | if (pathItr != managedObj.end()) |
| 1631 | { |
| 1632 | path = pathItr->first.str; |
| 1633 | } |
| 1634 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1635 | BMCWEB_LOG_DEBUG("Create new = {}", createNewObject); |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1636 | |
| 1637 | // arbitrary limit to avoid attacks |
| 1638 | constexpr const size_t controllerLimit = 500; |
James Feist | 14b0b8d | 2020-02-12 11:52:07 -0800 | [diff] [blame] | 1639 | if (createNewObject && objectCount >= controllerLimit) |
James Feist | e69d9de | 2020-02-07 12:23:27 -0800 | [diff] [blame] | 1640 | { |
| 1641 | messages::resourceExhaustion(response->res, type); |
| 1642 | continue; |
| 1643 | } |
Ed Tanous | a170f27 | 2022-06-30 21:53:27 -0700 | [diff] [blame] | 1644 | std::string escaped = name; |
| 1645 | std::replace(escaped.begin(), escaped.end(), '_', ' '); |
| 1646 | output.emplace_back("Name", escaped); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1647 | |
| 1648 | std::string chassis; |
| 1649 | CreatePIDRet ret = createPidInterface( |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1650 | response, type, name, value, path, managedObj, |
| 1651 | createNewObject, output, chassis, currentProfile); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1652 | if (ret == CreatePIDRet::fail) |
| 1653 | { |
| 1654 | return; |
| 1655 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1656 | if (ret == CreatePIDRet::del) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1657 | { |
| 1658 | continue; |
| 1659 | } |
| 1660 | |
| 1661 | if (!createNewObject) |
| 1662 | { |
| 1663 | for (const auto& property : output) |
| 1664 | { |
Potin Lai | 7a69697 | 2023-11-09 12:18:20 +0800 | [diff] [blame] | 1665 | crow::connections::systemBus->async_method_call( |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1666 | [response, |
| 1667 | propertyName{std::string(property.first)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1668 | const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1669 | if (ec) |
| 1670 | { |
| 1671 | BMCWEB_LOG_ERROR("Error patching {}: {}", |
| 1672 | propertyName, ec); |
| 1673 | messages::internalError(response->res); |
| 1674 | return; |
| 1675 | } |
| 1676 | messages::success(response->res); |
| 1677 | }, |
Potin Lai | 7a69697 | 2023-11-09 12:18:20 +0800 | [diff] [blame] | 1678 | "xyz.openbmc_project.EntityManager", path, |
| 1679 | "org.freedesktop.DBus.Properties", "Set", iface, |
| 1680 | property.first, property.second); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | if (chassis.empty()) |
| 1686 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1687 | BMCWEB_LOG_ERROR("Failed to get chassis from config"); |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1688 | messages::internalError(response->res); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1689 | return; |
| 1690 | } |
| 1691 | |
| 1692 | bool foundChassis = false; |
| 1693 | for (const auto& obj : managedObj) |
| 1694 | { |
Ed Tanous | 91f75ca | 2024-06-10 13:56:43 -0700 | [diff] [blame] | 1695 | if (obj.first.filename() == chassis) |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1696 | { |
| 1697 | chassis = obj.first.str; |
| 1698 | foundChassis = true; |
| 1699 | break; |
| 1700 | } |
| 1701 | } |
| 1702 | if (!foundChassis) |
| 1703 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1704 | BMCWEB_LOG_ERROR("Failed to find chassis on dbus"); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1705 | messages::resourceMissingAtURI( |
Ed Tanous | ace85d6 | 2021-10-26 12:45:59 -0700 | [diff] [blame] | 1706 | response->res, |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 1707 | boost::urls::format("/redfish/v1/Chassis/{}", |
| 1708 | chassis)); |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1709 | return; |
| 1710 | } |
| 1711 | |
| 1712 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 1713 | [response](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1714 | if (ec) |
| 1715 | { |
| 1716 | BMCWEB_LOG_ERROR("Error Adding Pid Object {}", |
| 1717 | ec); |
| 1718 | messages::internalError(response->res); |
| 1719 | return; |
| 1720 | } |
| 1721 | messages::success(response->res); |
| 1722 | }, |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1723 | "xyz.openbmc_project.EntityManager", chassis, |
| 1724 | "xyz.openbmc_project.AddObject", "AddObject", output); |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | } |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 1729 | |
| 1730 | ~SetPIDValues() |
| 1731 | { |
| 1732 | try |
| 1733 | { |
| 1734 | pidSetDone(); |
| 1735 | } |
| 1736 | catch (...) |
| 1737 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1738 | BMCWEB_LOG_CRITICAL("pidSetDone threw exception"); |
Ed Tanous | 24b2fe8 | 2022-01-06 12:45:54 -0800 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 1742 | std::shared_ptr<bmcweb::AsyncResp> asyncResp; |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 1743 | std::vector<std::pair<std::string, std::optional<nlohmann::json::object_t>>> |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1744 | configuration; |
| 1745 | std::optional<std::string> profile; |
| 1746 | dbus::utility::ManagedObjectType managedObj; |
| 1747 | std::vector<std::string> supportedProfiles; |
| 1748 | std::string currentProfile; |
| 1749 | std::string profileConnection; |
| 1750 | std::string profilePath; |
James Feist | 14b0b8d | 2020-02-12 11:52:07 -0800 | [diff] [blame] | 1751 | size_t objectCount = 0; |
James Feist | 73df0db | 2019-03-25 15:29:35 -0700 | [diff] [blame] | 1752 | }; |
James Feist | 83ff9ab | 2018-08-31 10:18:24 -0700 | [diff] [blame] | 1753 | |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1754 | /** |
| 1755 | * @brief Retrieves BMC manager location data over DBus |
| 1756 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1757 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1758 | * @param[in] connectionName - service name |
| 1759 | * @param[in] path - object path |
| 1760 | * @return none |
| 1761 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1762 | inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1763 | const std::string& connectionName, |
| 1764 | const std::string& path) |
| 1765 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1766 | BMCWEB_LOG_DEBUG("Get BMC manager Location data."); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1767 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1768 | dbus::utility::getProperty<std::string>( |
| 1769 | connectionName, path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1770 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1771 | [asyncResp](const boost::system::error_code& ec, |
| 1772 | const std::string& property) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1773 | if (ec) |
| 1774 | { |
| 1775 | BMCWEB_LOG_DEBUG("DBUS response error for " |
| 1776 | "Location"); |
| 1777 | messages::internalError(asyncResp->res); |
| 1778 | return; |
| 1779 | } |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1780 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1781 | asyncResp->res |
| 1782 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 1783 | property; |
| 1784 | }); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 1785 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1786 | // avoid name collision systems.hpp |
| 1787 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1788 | managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1789 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1790 | BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1791 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1792 | dbus::utility::getProperty<uint64_t>( |
| 1793 | "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", |
| 1794 | "xyz.openbmc_project.State.BMC", "LastRebootTime", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1795 | [asyncResp](const boost::system::error_code& ec, |
| 1796 | const uint64_t lastResetTime) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1797 | if (ec) |
| 1798 | { |
| 1799 | BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); |
| 1800 | return; |
| 1801 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1802 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1803 | // LastRebootTime is epoch time, in milliseconds |
| 1804 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 |
| 1805 | uint64_t lastResetTimeStamp = lastResetTime / 1000; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1806 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1807 | // Convert to ISO 8601 standard |
| 1808 | asyncResp->res.jsonValue["LastResetTime"] = |
| 1809 | redfish::time_utils::getDateTimeUint(lastResetTimeStamp); |
| 1810 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * @brief Set the running firmware image |
| 1815 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1816 | * @param[i,o] asyncResp - Async response object |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1817 | * @param[i] runningFirmwareTarget - Image to make the running image |
| 1818 | * |
| 1819 | * @return void |
| 1820 | */ |
| 1821 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1822 | setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1823 | const std::string& runningFirmwareTarget) |
| 1824 | { |
| 1825 | // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> |
| 1826 | std::string::size_type idPos = runningFirmwareTarget.rfind('/'); |
| 1827 | if (idPos == std::string::npos) |
| 1828 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1829 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1830 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1831 | BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1832 | return; |
| 1833 | } |
| 1834 | idPos++; |
| 1835 | if (idPos >= runningFirmwareTarget.size()) |
| 1836 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1837 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1838 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1839 | BMCWEB_LOG_DEBUG("Invalid firmware ID."); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1840 | return; |
| 1841 | } |
| 1842 | std::string firmwareId = runningFirmwareTarget.substr(idPos); |
| 1843 | |
| 1844 | // Make sure the image is valid before setting priority |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1845 | sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); |
| 1846 | dbus::utility::getManagedObjects( |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 1847 | getBMCUpdateServiceName(), objPath, |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1848 | [asyncResp, firmwareId, runningFirmwareTarget]( |
| 1849 | const boost::system::error_code& ec, |
| 1850 | const dbus::utility::ManagedObjectType& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1851 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1852 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1853 | BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1854 | messages::internalError(asyncResp->res); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1855 | return; |
| 1856 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1857 | |
| 1858 | if (subtree.empty()) |
| 1859 | { |
| 1860 | BMCWEB_LOG_DEBUG("Can't find image!"); |
| 1861 | messages::internalError(asyncResp->res); |
| 1862 | return; |
| 1863 | } |
| 1864 | |
| 1865 | bool foundImage = false; |
| 1866 | for (const auto& object : subtree) |
| 1867 | { |
| 1868 | const std::string& path = |
| 1869 | static_cast<const std::string&>(object.first); |
| 1870 | std::size_t idPos2 = path.rfind('/'); |
| 1871 | |
| 1872 | if (idPos2 == std::string::npos) |
| 1873 | { |
| 1874 | continue; |
| 1875 | } |
| 1876 | |
| 1877 | idPos2++; |
| 1878 | if (idPos2 >= path.size()) |
| 1879 | { |
| 1880 | continue; |
| 1881 | } |
| 1882 | |
| 1883 | if (path.substr(idPos2) == firmwareId) |
| 1884 | { |
| 1885 | foundImage = true; |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | if (!foundImage) |
| 1891 | { |
| 1892 | messages::propertyValueNotInList( |
| 1893 | asyncResp->res, runningFirmwareTarget, "@odata.id"); |
| 1894 | BMCWEB_LOG_DEBUG("Invalid firmware ID."); |
| 1895 | return; |
| 1896 | } |
| 1897 | |
| 1898 | BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", |
| 1899 | firmwareId); |
| 1900 | |
| 1901 | // Only support Immediate |
| 1902 | // An addition could be a Redfish Setting like |
| 1903 | // ActiveSoftwareImageApplyTime and support OnReset |
| 1904 | sdbusplus::asio::setProperty( |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 1905 | *crow::connections::systemBus, getBMCUpdateServiceName(), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1906 | "/xyz/openbmc_project/software/" + firmwareId, |
| 1907 | "xyz.openbmc_project.Software.RedundancyPriority", "Priority", |
| 1908 | static_cast<uint8_t>(0), |
| 1909 | [asyncResp](const boost::system::error_code& ec2) { |
| 1910 | if (ec2) |
| 1911 | { |
| 1912 | BMCWEB_LOG_DEBUG("D-Bus response error setting."); |
| 1913 | messages::internalError(asyncResp->res); |
| 1914 | return; |
| 1915 | } |
| 1916 | doBMCGracefulRestart(asyncResp); |
| 1917 | }); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 1918 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1919 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1920 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1921 | inline void afterSetDateTime( |
| 1922 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1923 | const boost::system::error_code& ec, const sdbusplus::message_t& msg) |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 1924 | { |
| 1925 | if (ec) |
| 1926 | { |
| 1927 | BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", |
| 1928 | ec); |
| 1929 | const sd_bus_error* dbusError = msg.get_error(); |
| 1930 | if (dbusError != nullptr) |
| 1931 | { |
| 1932 | std::string_view errorName(dbusError->name); |
| 1933 | if (errorName == |
| 1934 | "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") |
| 1935 | { |
| 1936 | BMCWEB_LOG_DEBUG("Setting conflict"); |
| 1937 | messages::propertyValueConflict( |
| 1938 | asyncResp->res, "DateTime", |
| 1939 | "Managers/NetworkProtocol/NTPProcotolEnabled"); |
| 1940 | return; |
| 1941 | } |
| 1942 | } |
| 1943 | messages::internalError(asyncResp->res); |
| 1944 | return; |
| 1945 | } |
| 1946 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 1947 | } |
| 1948 | |
| 1949 | inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1950 | const std::string& datetime) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1951 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1952 | BMCWEB_LOG_DEBUG("Set date time: {}", datetime); |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 1953 | |
Ed Tanous | c2e3200 | 2023-01-07 22:05:08 -0800 | [diff] [blame] | 1954 | std::optional<redfish::time_utils::usSinceEpoch> us = |
| 1955 | redfish::time_utils::dateStringToEpoch(datetime); |
| 1956 | if (!us) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1957 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1958 | messages::propertyValueFormatError(asyncResp->res, datetime, |
| 1959 | "DateTime"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1960 | return; |
| 1961 | } |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 1962 | // Set the absolute datetime |
| 1963 | bool relative = false; |
| 1964 | bool interactive = false; |
| 1965 | crow::connections::systemBus->async_method_call( |
| 1966 | [asyncResp](const boost::system::error_code& ec, |
| 1967 | const sdbusplus::message_t& msg) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1968 | afterSetDateTime(asyncResp, ec, msg); |
| 1969 | }, |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 1970 | "org.freedesktop.timedate1", "/org/freedesktop/timedate1", |
| 1971 | "org.freedesktop.timedate1", "SetTime", us->count(), relative, |
| 1972 | interactive); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 1975 | inline void |
| 1976 | checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 1977 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1978 | dbus::utility::getProperty<std::string>( |
| 1979 | "org.freedesktop.systemd1", |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 1980 | "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", |
| 1981 | "org.freedesktop.systemd1.Unit", "ActiveState", |
| 1982 | [asyncResp](const boost::system::error_code& ec, |
| 1983 | const std::string& val) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1984 | if (!ec) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 1985 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1986 | if (val == "active") |
| 1987 | { |
| 1988 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 1989 | resource::Health::Critical; |
| 1990 | asyncResp->res.jsonValue["Status"]["State"] = |
| 1991 | resource::State::Quiesced; |
| 1992 | return; |
| 1993 | } |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 1994 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1995 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
| 1996 | asyncResp->res.jsonValue["Status"]["State"] = |
| 1997 | resource::State::Enabled; |
| 1998 | }); |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2001 | inline void requestRoutesManager(App& app) |
| 2002 | { |
| 2003 | std::string uuid = persistent_data::getConfig().systemUuid; |
| 2004 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2005 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2006 | .privileges(redfish::privileges::getManager) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2007 | .methods( |
| 2008 | boost::beast::http::verb:: |
| 2009 | get)([&app, |
| 2010 | uuid](const crow::Request& req, |
| 2011 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2012 | const std::string& managerId) { |
| 2013 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2014 | { |
| 2015 | return; |
| 2016 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2017 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2018 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2019 | { |
| 2020 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 2021 | managerId); |
| 2022 | return; |
| 2023 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2024 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2025 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 2026 | "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2027 | asyncResp->res.jsonValue["@odata.type"] = |
| 2028 | "#Manager.v1_14_0.Manager"; |
| 2029 | asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME; |
| 2030 | asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; |
| 2031 | asyncResp->res.jsonValue["Description"] = |
| 2032 | "Baseboard Management Controller"; |
| 2033 | asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 2034 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2035 | asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC; |
| 2036 | asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); |
| 2037 | asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; |
| 2038 | asyncResp->res.jsonValue["Model"] = |
| 2039 | "OpenBmc"; // TODO(ed), get model |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2040 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2041 | asyncResp->res.jsonValue["LogServices"]["@odata.id"] = |
| 2042 | boost::urls::format("/redfish/v1/Managers/{}/LogServices", |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2043 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2044 | asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = |
| 2045 | boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol", |
| 2046 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2047 | asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = |
| 2048 | boost::urls::format( |
| 2049 | "/redfish/v1/Managers/{}/EthernetInterfaces", |
| 2050 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2051 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2052 | if constexpr (BMCWEB_VM_NBDPROXY) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 2053 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2054 | asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = |
| 2055 | boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", |
| 2056 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2059 | // default oem data |
| 2060 | nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; |
| 2061 | nlohmann::json& oemOpenbmc = oem["OpenBmc"]; |
| 2062 | oem["@odata.id"] = |
| 2063 | boost::urls::format("/redfish/v1/Managers/{}#/Oem", |
| 2064 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2065 | oemOpenbmc["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager"; |
| 2066 | oemOpenbmc["@odata.id"] = |
| 2067 | boost::urls::format("/redfish/v1/Managers/{}#/Oem/OpenBmc", |
| 2068 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2069 | |
| 2070 | nlohmann::json::object_t certificates; |
| 2071 | certificates["@odata.id"] = boost::urls::format( |
| 2072 | "/redfish/v1/Managers/{}/Truststore/Certificates", |
| 2073 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2074 | oemOpenbmc["Certificates"] = std::move(certificates); |
| 2075 | |
| 2076 | // Manager.Reset (an action) can be many values, OpenBMC only |
| 2077 | // supports BMC reboot. |
| 2078 | nlohmann::json& managerReset = |
| 2079 | asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; |
| 2080 | managerReset["target"] = boost::urls::format( |
| 2081 | "/redfish/v1/Managers/{}/Actions/Manager.Reset", |
| 2082 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2083 | managerReset["@Redfish.ActionInfo"] = |
| 2084 | boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", |
| 2085 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2086 | |
| 2087 | // ResetToDefaults (Factory Reset) has values like |
| 2088 | // PreserveNetworkAndUsers and PreserveNetwork that aren't supported |
| 2089 | // on OpenBMC |
| 2090 | nlohmann::json& resetToDefaults = |
| 2091 | asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; |
| 2092 | resetToDefaults["target"] = boost::urls::format( |
| 2093 | "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", |
| 2094 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2095 | resetToDefaults["ResetType@Redfish.AllowableValues"] = |
| 2096 | nlohmann::json::array_t({"ResetAll"}); |
| 2097 | |
| 2098 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 2099 | redfish::time_utils::getDateTimeOffsetNow(); |
| 2100 | |
| 2101 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 2102 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 2103 | redfishDateTimeOffset.second; |
| 2104 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2105 | if constexpr (BMCWEB_KVM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2106 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2107 | // Fill in GraphicalConsole info |
| 2108 | asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = |
| 2109 | true; |
| 2110 | asyncResp->res |
| 2111 | .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; |
| 2112 | asyncResp->res |
| 2113 | .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = |
| 2114 | nlohmann::json::array_t({"KVMIP"}); |
| 2115 | } |
| 2116 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 2117 | { |
| 2118 | asyncResp->res |
| 2119 | .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; |
| 2120 | |
| 2121 | nlohmann::json::array_t managerForServers; |
| 2122 | nlohmann::json::object_t manager; |
| 2123 | manager["@odata.id"] = std::format( |
| 2124 | "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 2125 | managerForServers.emplace_back(std::move(manager)); |
| 2126 | |
| 2127 | asyncResp->res.jsonValue["Links"]["ManagerForServers"] = |
| 2128 | std::move(managerForServers); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2129 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2130 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2131 | sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, |
| 2132 | "FirmwareVersion", true); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2133 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2134 | managerGetLastResetTime(asyncResp); |
| 2135 | |
| 2136 | // ManagerDiagnosticData is added for all BMCs. |
| 2137 | nlohmann::json& managerDiagnosticData = |
| 2138 | asyncResp->res.jsonValue["ManagerDiagnosticData"]; |
| 2139 | managerDiagnosticData["@odata.id"] = boost::urls::format( |
| 2140 | "/redfish/v1/Managers/{}/ManagerDiagnosticData", |
| 2141 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2142 | |
| 2143 | if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2144 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2145 | auto pids = std::make_shared<GetPIDValues>(asyncResp); |
| 2146 | pids->run(); |
| 2147 | } |
| 2148 | |
| 2149 | getMainChassisId(asyncResp, [](const std::string& chassisId, |
| 2150 | const std::shared_ptr< |
| 2151 | bmcweb::AsyncResp>& aRsp) { |
| 2152 | aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = |
| 2153 | 1; |
| 2154 | nlohmann::json::array_t managerForChassis; |
| 2155 | nlohmann::json::object_t managerObj; |
| 2156 | boost::urls::url chassiUrl = |
| 2157 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
| 2158 | managerObj["@odata.id"] = chassiUrl; |
| 2159 | managerForChassis.emplace_back(std::move(managerObj)); |
| 2160 | aRsp->res.jsonValue["Links"]["ManagerForChassis"] = |
| 2161 | std::move(managerForChassis); |
| 2162 | aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = |
| 2163 | chassiUrl; |
| 2164 | }); |
| 2165 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2166 | dbus::utility::getProperty<double>( |
| 2167 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 2168 | "org.freedesktop.systemd1.Manager", "Progress", |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2169 | [asyncResp](const boost::system::error_code& ec, double val) { |
| 2170 | if (ec) |
| 2171 | { |
| 2172 | BMCWEB_LOG_ERROR("Error while getting progress"); |
| 2173 | messages::internalError(asyncResp->res); |
| 2174 | return; |
| 2175 | } |
| 2176 | if (val < 1.0) |
| 2177 | { |
| 2178 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 2179 | resource::Health::OK; |
| 2180 | asyncResp->res.jsonValue["Status"]["State"] = |
| 2181 | resource::State::Starting; |
| 2182 | return; |
| 2183 | } |
| 2184 | checkForQuiesced(asyncResp); |
| 2185 | }); |
| 2186 | |
| 2187 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2188 | "xyz.openbmc_project.Inventory.Item.Bmc"}; |
| 2189 | dbus::utility::getSubTree( |
| 2190 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 2191 | [asyncResp]( |
| 2192 | const boost::system::error_code& ec, |
| 2193 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 2194 | if (ec) |
| 2195 | { |
| 2196 | BMCWEB_LOG_DEBUG( |
| 2197 | "D-Bus response error on GetSubTree {}", ec); |
| 2198 | return; |
| 2199 | } |
| 2200 | if (subtree.empty()) |
| 2201 | { |
| 2202 | BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); |
| 2203 | return; |
| 2204 | } |
| 2205 | // Assume only 1 bmc D-Bus object |
| 2206 | // Throw an error if there is more than 1 |
| 2207 | if (subtree.size() > 1) |
| 2208 | { |
| 2209 | BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); |
| 2210 | messages::internalError(asyncResp->res); |
| 2211 | return; |
| 2212 | } |
| 2213 | |
| 2214 | if (subtree[0].first.empty() || |
| 2215 | subtree[0].second.size() != 1) |
| 2216 | { |
| 2217 | BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); |
| 2218 | messages::internalError(asyncResp->res); |
| 2219 | return; |
| 2220 | } |
| 2221 | |
| 2222 | const std::string& path = subtree[0].first; |
| 2223 | const std::string& connectionName = |
| 2224 | subtree[0].second[0].first; |
| 2225 | |
| 2226 | for (const auto& interfaceName : |
| 2227 | subtree[0].second[0].second) |
| 2228 | { |
| 2229 | if (interfaceName == |
| 2230 | "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 2231 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2232 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2233 | *crow::connections::systemBus, connectionName, |
| 2234 | path, |
| 2235 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 2236 | [asyncResp]( |
| 2237 | const boost::system::error_code& ec2, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2238 | const dbus::utility::DBusPropertiesMap& |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2239 | propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2240 | if (ec2) |
| 2241 | { |
| 2242 | BMCWEB_LOG_DEBUG( |
| 2243 | "Can't get bmc asset!"); |
| 2244 | return; |
| 2245 | } |
| 2246 | |
| 2247 | const std::string* partNumber = nullptr; |
| 2248 | const std::string* serialNumber = nullptr; |
| 2249 | const std::string* manufacturer = nullptr; |
| 2250 | const std::string* model = nullptr; |
| 2251 | const std::string* sparePartNumber = |
| 2252 | nullptr; |
| 2253 | |
| 2254 | const bool success = |
| 2255 | sdbusplus::unpackPropertiesNoThrow( |
| 2256 | dbus_utils::UnpackErrorPrinter(), |
| 2257 | propertiesList, "PartNumber", |
| 2258 | partNumber, "SerialNumber", |
| 2259 | serialNumber, "Manufacturer", |
| 2260 | manufacturer, "Model", model, |
| 2261 | "SparePartNumber", sparePartNumber); |
| 2262 | |
| 2263 | if (!success) |
| 2264 | { |
| 2265 | messages::internalError(asyncResp->res); |
| 2266 | return; |
| 2267 | } |
| 2268 | |
| 2269 | if (partNumber != nullptr) |
| 2270 | { |
| 2271 | asyncResp->res.jsonValue["PartNumber"] = |
| 2272 | *partNumber; |
| 2273 | } |
| 2274 | |
| 2275 | if (serialNumber != nullptr) |
| 2276 | { |
| 2277 | asyncResp->res |
| 2278 | .jsonValue["SerialNumber"] = |
| 2279 | *serialNumber; |
| 2280 | } |
| 2281 | |
| 2282 | if (manufacturer != nullptr) |
| 2283 | { |
| 2284 | asyncResp->res |
| 2285 | .jsonValue["Manufacturer"] = |
| 2286 | *manufacturer; |
| 2287 | } |
| 2288 | |
| 2289 | if (model != nullptr) |
| 2290 | { |
| 2291 | asyncResp->res.jsonValue["Model"] = |
| 2292 | *model; |
| 2293 | } |
| 2294 | |
| 2295 | if (sparePartNumber != nullptr) |
| 2296 | { |
| 2297 | asyncResp->res |
| 2298 | .jsonValue["SparePartNumber"] = |
| 2299 | *sparePartNumber; |
| 2300 | } |
| 2301 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2302 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2303 | else if ( |
| 2304 | interfaceName == |
| 2305 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 2306 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2307 | getLocation(asyncResp, connectionName, path); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2308 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2309 | } |
| 2310 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2311 | }); |
| 2312 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2313 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2314 | .privileges(redfish::privileges::patchManager) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2315 | .methods(boost::beast::http::verb::patch)( |
| 2316 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2317 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2318 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2319 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2320 | { |
| 2321 | return; |
| 2322 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2323 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2324 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 2325 | { |
| 2326 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 2327 | managerId); |
| 2328 | return; |
| 2329 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2330 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2331 | std::optional<std::string> activeSoftwareImageOdataId; |
| 2332 | std::optional<std::string> datetime; |
| 2333 | std::optional<nlohmann::json::object_t> pidControllers; |
| 2334 | std::optional<nlohmann::json::object_t> fanControllers; |
| 2335 | std::optional<nlohmann::json::object_t> fanZones; |
| 2336 | std::optional<nlohmann::json::object_t> stepwiseControllers; |
| 2337 | std::optional<std::string> profile; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2338 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 2339 | if (!json_util::readJsonPatch( // |
| 2340 | req, asyncResp->res, // |
| 2341 | "DateTime", datetime, // |
| 2342 | "Links/ActiveSoftwareImage/@odata.id", |
| 2343 | activeSoftwareImageOdataId, // |
| 2344 | "Oem/OpenBmc/Fan/FanControllers", fanControllers, // |
| 2345 | "Oem/OpenBmc/Fan/FanZones", fanZones, // |
| 2346 | "Oem/OpenBmc/Fan/PidControllers", pidControllers, // |
| 2347 | "Oem/OpenBmc/Fan/Profile", profile, // |
| 2348 | "Oem/OpenBmc/Fan/StepwiseControllers", |
| 2349 | stepwiseControllers // |
| 2350 | )) |
| 2351 | { |
| 2352 | return; |
| 2353 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2354 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2355 | if (pidControllers || fanControllers || fanZones || |
| 2356 | stepwiseControllers || profile) |
| 2357 | { |
| 2358 | if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) |
| 2359 | { |
| 2360 | std::vector< |
| 2361 | std::pair<std::string, |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2362 | std::optional<nlohmann::json::object_t>>> |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2363 | configuration; |
| 2364 | if (pidControllers) |
| 2365 | { |
| 2366 | configuration.emplace_back( |
| 2367 | "PidControllers", std::move(pidControllers)); |
| 2368 | } |
| 2369 | if (fanControllers) |
| 2370 | { |
| 2371 | configuration.emplace_back( |
| 2372 | "FanControllers", std::move(fanControllers)); |
| 2373 | } |
| 2374 | if (fanZones) |
| 2375 | { |
| 2376 | configuration.emplace_back("FanZones", |
| 2377 | std::move(fanZones)); |
| 2378 | } |
| 2379 | if (stepwiseControllers) |
| 2380 | { |
| 2381 | configuration.emplace_back( |
| 2382 | "StepwiseControllers", |
| 2383 | std::move(stepwiseControllers)); |
| 2384 | } |
| 2385 | auto pid = std::make_shared<SetPIDValues>( |
| 2386 | asyncResp, std::move(configuration), profile); |
| 2387 | pid->run(); |
| 2388 | } |
| 2389 | else |
| 2390 | { |
| 2391 | messages::propertyUnknown(asyncResp->res, "Oem"); |
| 2392 | return; |
| 2393 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2394 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2395 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2396 | if (activeSoftwareImageOdataId) |
| 2397 | { |
| 2398 | setActiveFirmwareImage(asyncResp, |
| 2399 | *activeSoftwareImageOdataId); |
| 2400 | } |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 2401 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2402 | if (datetime) |
| 2403 | { |
| 2404 | setDateTime(asyncResp, *datetime); |
| 2405 | } |
| 2406 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | inline void requestRoutesManagerCollection(App& app) |
| 2410 | { |
| 2411 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 2412 | .privileges(redfish::privileges::getManagerCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2413 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 2414 | [&app](const crow::Request& req, |
| 2415 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2416 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2417 | { |
| 2418 | return; |
| 2419 | } |
| 2420 | // Collections don't include the static data added by SubRoute |
| 2421 | // because it has a duplicate entry for members |
| 2422 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; |
| 2423 | asyncResp->res.jsonValue["@odata.type"] = |
| 2424 | "#ManagerCollection.ManagerCollection"; |
| 2425 | asyncResp->res.jsonValue["Name"] = "Manager Collection"; |
| 2426 | asyncResp->res.jsonValue["Members@odata.count"] = 1; |
| 2427 | nlohmann::json::array_t members; |
| 2428 | nlohmann::json& bmc = members.emplace_back(); |
| 2429 | bmc["@odata.id"] = boost::urls::format( |
| 2430 | "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 2431 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 2432 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2433 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2434 | } // namespace redfish |