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