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