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