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