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