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