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