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