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