Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 8 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "async_resp.hpp" |
| 10 | #include "dbus_singleton.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 11 | #include "dbus_utility.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "error_messages.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 13 | #include "generated/enums/action_info.hpp" |
| 14 | #include "generated/enums/manager.hpp" |
| 15 | #include "generated/enums/resource.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 16 | #include "http_request.hpp" |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 17 | #include "led.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 18 | #include "logging.hpp" |
| 19 | #include "persistent_data.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 20 | #include "query.hpp" |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 21 | #include "redfish.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 22 | #include "redfish_util.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 23 | #include "registries/privilege_registry.hpp" |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 24 | #include "utils/dbus_utils.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 25 | #include "utils/json_utils.hpp" |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 26 | #include "utils/manager_utils.hpp" |
Sui Chen | a51fc2d | 2022-07-14 17:21:53 -0700 | [diff] [blame] | 27 | #include "utils/sw_utils.hpp" |
| 28 | #include "utils/systemd_utils.hpp" |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 29 | #include "utils/time_utils.hpp" |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 30 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 31 | #include <systemd/sd-bus.h> |
| 32 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 33 | #include <boost/beast/http/status.hpp> |
| 34 | #include <boost/beast/http/verb.hpp> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 35 | #include <boost/system/error_code.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 36 | #include <boost/url/format.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 37 | #include <boost/url/url.hpp> |
| 38 | #include <nlohmann/json.hpp> |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 39 | #include <sdbusplus/asio/property.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 40 | #include <sdbusplus/message.hpp> |
| 41 | #include <sdbusplus/message/native_types.hpp> |
Krzysztof Grobelny | fac6e53 | 2022-08-04 12:42:45 +0200 | [diff] [blame] | 42 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 43 | |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 44 | #include <array> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 45 | #include <cstddef> |
Gunnar Mills | 4bfefa7 | 2020-07-30 13:54:29 -0500 | [diff] [blame] | 46 | #include <cstdint> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 47 | #include <format> |
| 48 | #include <functional> |
| 49 | #include <map> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 50 | #include <memory> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 51 | #include <optional> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 52 | #include <ranges> |
Konstantin Aladyshev | 9970e93 | 2024-02-20 09:51:29 +0300 | [diff] [blame] | 53 | #include <string> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 54 | #include <string_view> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 55 | #include <utility> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 56 | #include <vector> |
James Feist | 5b4aa86 | 2018-08-16 14:07:01 -0700 | [diff] [blame] | 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | namespace redfish |
| 59 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 60 | |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 61 | inline void handleSetLocationIndicatorActive( |
| 62 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 63 | bool locationIndicatorActive, const std::string& managerId, |
| 64 | const boost::system::error_code& ec, |
| 65 | const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths) |
| 66 | { |
| 67 | if (ec) |
| 68 | { |
| 69 | if (ec == boost::system::errc::io_error) |
| 70 | { |
| 71 | // Not found |
| 72 | BMCWEB_LOG_WARNING("Manager {} not found", managerId); |
| 73 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 74 | return; |
| 75 | } |
| 76 | BMCWEB_LOG_ERROR("D-Bus response error {}", ec.value()); |
| 77 | messages::internalError(asyncResp->res); |
| 78 | return; |
| 79 | } |
| 80 | if (subtreePaths.empty()) |
| 81 | { |
| 82 | BMCWEB_LOG_WARNING("Manager {} not found", managerId); |
| 83 | messages::resourceNotFound(asyncResp->res, "Manager", managerId); |
| 84 | return; |
| 85 | } |
| 86 | // Assume only 1 bmc D-Bus object |
| 87 | // Throw an error if there is more than 1 |
| 88 | if (subtreePaths.size() != 1) |
| 89 | { |
| 90 | BMCWEB_LOG_ERROR("Found {} Bmc D-Bus paths", subtreePaths.size()); |
| 91 | messages::internalError(asyncResp->res); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | setLocationIndicatorActive(asyncResp, subtreePaths[0], |
| 96 | locationIndicatorActive); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Set the locationIndicatorActive. |
| 101 | * |
| 102 | * @param[in,out] asyncResp Async HTTP response. |
| 103 | * @param[in] locationIndicatorActive Value of the property |
| 104 | */ |
| 105 | inline void setLocationIndicatorActiveState( |
| 106 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 107 | bool locationIndicatorActive, const std::string& managerId) |
| 108 | { |
| 109 | // GetSubTree on all interfaces which provide info about a Manager |
| 110 | constexpr std::array<std::string_view, 1> interfaces = { |
| 111 | "xyz.openbmc_project.Inventory.Item.Bmc"}; |
| 112 | dbus::utility::getSubTreePaths( |
| 113 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 114 | std::bind_front(handleSetLocationIndicatorActive, asyncResp, |
| 115 | locationIndicatorActive, managerId)); |
| 116 | } |
| 117 | |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 118 | inline std::string getBMCUpdateServiceName() |
| 119 | { |
| 120 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 121 | { |
| 122 | return "xyz.openbmc_project.Software.Manager"; |
| 123 | } |
| 124 | return "xyz.openbmc_project.Software.BMC.Updater"; |
| 125 | } |
| 126 | |
| 127 | inline std::string getBMCUpdateServicePath() |
| 128 | { |
| 129 | if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) |
| 130 | { |
| 131 | return "/xyz/openbmc_project/software/bmc"; |
| 132 | } |
| 133 | return "/xyz/openbmc_project/software"; |
| 134 | } |
| 135 | |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 136 | /** |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 137 | * Function reboots the BMC. |
| 138 | * |
| 139 | * @param[in] asyncResp - Shared pointer for completing asynchronous calls |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 140 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 141 | inline void doBMCGracefulRestart( |
| 142 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 143 | { |
| 144 | const char* processName = "xyz.openbmc_project.State.BMC"; |
| 145 | const char* objectPath = "/xyz/openbmc_project/state/bmc0"; |
| 146 | const char* interfaceName = "xyz.openbmc_project.State.BMC"; |
| 147 | const std::string& propertyValue = |
| 148 | "xyz.openbmc_project.State.BMC.Transition.Reboot"; |
| 149 | const char* destProperty = "RequestedBMCTransition"; |
| 150 | |
| 151 | // Create the D-Bus variant for D-Bus call. |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 152 | sdbusplus::asio::setProperty( |
| 153 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 154 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 155 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 156 | // Use "Set" method to set the property value. |
| 157 | if (ec) |
| 158 | { |
| 159 | BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); |
| 160 | messages::internalError(asyncResp->res); |
| 161 | return; |
| 162 | } |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 163 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 164 | messages::success(asyncResp->res); |
| 165 | }); |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 166 | } |
| 167 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 168 | inline void doBMCForceRestart( |
| 169 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 170 | { |
| 171 | const char* processName = "xyz.openbmc_project.State.BMC"; |
| 172 | const char* objectPath = "/xyz/openbmc_project/state/bmc0"; |
| 173 | const char* interfaceName = "xyz.openbmc_project.State.BMC"; |
| 174 | const std::string& propertyValue = |
| 175 | "xyz.openbmc_project.State.BMC.Transition.HardReboot"; |
| 176 | const char* destProperty = "RequestedBMCTransition"; |
| 177 | |
| 178 | // Create the D-Bus variant for D-Bus call. |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 179 | sdbusplus::asio::setProperty( |
| 180 | *crow::connections::systemBus, processName, objectPath, interfaceName, |
| 181 | destProperty, propertyValue, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 182 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 183 | // Use "Set" method to set the property value. |
| 184 | if (ec) |
| 185 | { |
| 186 | BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); |
| 187 | messages::internalError(asyncResp->res); |
| 188 | return; |
| 189 | } |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 190 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 191 | messages::success(asyncResp->res); |
| 192 | }); |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 195 | /** |
| 196 | * ManagerResetAction class supports the POST method for the Reset (reboot) |
| 197 | * action. |
| 198 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 199 | inline void requestRoutesManagerResetAction(App& app) |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 200 | { |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 201 | /** |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 202 | * Function handles POST method request. |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 203 | * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. |
Jayaprakash Mutyala | f92af38 | 2020-06-16 23:29:41 +0000 | [diff] [blame] | 204 | * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 205 | */ |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 206 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 207 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 208 | .privileges(redfish::privileges::postManager) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 209 | .methods(boost::beast::http::verb::post)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 210 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 211 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 212 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 213 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 214 | { |
| 215 | return; |
| 216 | } |
| 217 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 218 | { |
| 219 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 220 | managerId); |
| 221 | return; |
| 222 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 223 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 224 | BMCWEB_LOG_DEBUG("Post Manager Reset."); |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 225 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 226 | std::string resetType; |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 227 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 228 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", |
| 229 | resetType)) |
| 230 | { |
| 231 | return; |
| 232 | } |
Gunnar Mills | 2a5c440 | 2020-05-19 09:07:24 -0500 | [diff] [blame] | 233 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 234 | if (resetType == "GracefulRestart") |
| 235 | { |
| 236 | BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); |
| 237 | doBMCGracefulRestart(asyncResp); |
| 238 | return; |
| 239 | } |
| 240 | if (resetType == "ForceRestart") |
| 241 | { |
| 242 | BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); |
| 243 | doBMCForceRestart(asyncResp); |
| 244 | return; |
| 245 | } |
| 246 | BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", |
| 247 | resetType); |
| 248 | messages::actionParameterNotSupported(asyncResp->res, resetType, |
| 249 | "ResetType"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 250 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 251 | return; |
| 252 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 253 | } |
Jennifer Lee | ed5befb | 2018-08-10 11:29:45 -0700 | [diff] [blame] | 254 | |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 255 | /** |
| 256 | * ManagerResetToDefaultsAction class supports POST method for factory reset |
| 257 | * action. |
| 258 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 259 | inline void requestRoutesManagerResetToDefaultsAction(App& app) |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 260 | { |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 261 | /** |
| 262 | * Function handles ResetToDefaults POST method request. |
| 263 | * |
| 264 | * Analyzes POST body message and factory resets BMC by calling |
| 265 | * BMC code updater factory reset followed by a BMC reboot. |
| 266 | * |
| 267 | * BMC code updater factory reset wipes the whole BMC read-write |
| 268 | * filesystem which includes things like the network settings. |
| 269 | * |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 270 | * OpenBMC only supports ResetType "ResetAll". |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 271 | */ |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 272 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 273 | BMCWEB_ROUTE(app, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 274 | "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 275 | .privileges(redfish::privileges::postManager) |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 276 | .methods(boost::beast::http::verb::post)( |
| 277 | [&app](const crow::Request& req, |
| 278 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 279 | const std::string& managerId) { |
| 280 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 281 | { |
| 282 | return; |
| 283 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 284 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 285 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 286 | { |
| 287 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 288 | managerId); |
| 289 | return; |
| 290 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 291 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 292 | BMCWEB_LOG_DEBUG("Post ResetToDefaults."); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 293 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 294 | std::optional<std::string> resetType; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 295 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 296 | if (!json_util::readJsonAction( // |
| 297 | req, asyncResp->res, // |
| 298 | "ResetType", resetType // |
| 299 | )) |
| 300 | { |
| 301 | BMCWEB_LOG_DEBUG("Missing property ResetType."); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 302 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 303 | messages::actionParameterMissing( |
| 304 | asyncResp->res, "ResetToDefaults", "ResetType"); |
| 305 | return; |
| 306 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 307 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 308 | if (resetType != "ResetAll") |
| 309 | { |
| 310 | BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", |
| 311 | *resetType); |
| 312 | messages::actionParameterNotSupported( |
| 313 | asyncResp->res, *resetType, "ResetType"); |
| 314 | return; |
| 315 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 316 | |
Gunnar Mills | 18bf4bf | 2025-05-09 08:22:38 -0500 | [diff] [blame] | 317 | crow::connections::systemBus->async_method_call( |
| 318 | [asyncResp](const boost::system::error_code& ec) { |
| 319 | if (ec) |
| 320 | { |
| 321 | BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", |
| 322 | ec); |
| 323 | messages::internalError(asyncResp->res); |
| 324 | return; |
| 325 | } |
| 326 | // Factory Reset doesn't actually happen until a reboot |
| 327 | // Can't erase what the BMC is running on |
| 328 | doBMCGracefulRestart(asyncResp); |
| 329 | }, |
| 330 | getBMCUpdateServiceName(), getBMCUpdateServicePath(), |
| 331 | "xyz.openbmc_project.Common.FactoryReset", "Reset"); |
| 332 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 333 | } |
Gunnar Mills | 3e40fc7 | 2020-05-19 19:18:17 -0500 | [diff] [blame] | 334 | |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 335 | /** |
| 336 | * ManagerResetActionInfo derived class for delivering Manager |
| 337 | * ResetType AllowableValues using ResetInfo schema. |
| 338 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 339 | inline void requestRoutesManagerResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 340 | { |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 341 | /** |
| 342 | * Functions triggers appropriate requests on DBus |
| 343 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 344 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 345 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 346 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 347 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 348 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 349 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 350 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 351 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 352 | { |
| 353 | return; |
| 354 | } |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 355 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 356 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 357 | { |
| 358 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 359 | managerId); |
| 360 | return; |
| 361 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 362 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 363 | asyncResp->res.jsonValue["@odata.type"] = |
| 364 | "#ActionInfo.v1_1_2.ActionInfo"; |
| 365 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 366 | "/redfish/v1/Managers/{}/ResetActionInfo", |
| 367 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 368 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
| 369 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 370 | nlohmann::json::object_t parameter; |
| 371 | parameter["Name"] = "ResetType"; |
| 372 | parameter["Required"] = true; |
| 373 | parameter["DataType"] = action_info::ParameterTypes::String; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 374 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 375 | nlohmann::json::array_t allowableValues; |
| 376 | allowableValues.emplace_back("GracefulRestart"); |
| 377 | allowableValues.emplace_back("ForceRestart"); |
| 378 | parameter["AllowableValues"] = std::move(allowableValues); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 379 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 380 | nlohmann::json::array_t parameters; |
| 381 | parameters.emplace_back(std::move(parameter)); |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 382 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 383 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
| 384 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 385 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 386 | |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 387 | /** |
| 388 | * @brief Retrieves BMC manager location data over DBus |
| 389 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 390 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 391 | * @param[in] connectionName - service name |
| 392 | * @param[in] path - object path |
| 393 | * @return none |
| 394 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 395 | inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 396 | const std::string& connectionName, |
| 397 | const std::string& path) |
| 398 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 399 | BMCWEB_LOG_DEBUG("Get BMC manager Location data."); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 400 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 401 | dbus::utility::getProperty<std::string>( |
| 402 | connectionName, path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 403 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 404 | [asyncResp](const boost::system::error_code& ec, |
| 405 | const std::string& property) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 406 | if (ec) |
| 407 | { |
| 408 | BMCWEB_LOG_DEBUG("DBUS response error for " |
| 409 | "Location"); |
| 410 | messages::internalError(asyncResp->res); |
| 411 | return; |
| 412 | } |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 413 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 414 | asyncResp->res |
| 415 | .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = |
| 416 | property; |
| 417 | }); |
SunnySrivastava1984 | 071d8fd | 2020-10-28 02:20:30 -0500 | [diff] [blame] | 418 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 419 | // avoid name collision systems.hpp |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 420 | inline void managerGetLastResetTime( |
| 421 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 422 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 423 | BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 424 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 425 | dbus::utility::getProperty<uint64_t>( |
| 426 | "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", |
| 427 | "xyz.openbmc_project.State.BMC", "LastRebootTime", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 428 | [asyncResp](const boost::system::error_code& ec, |
| 429 | const uint64_t lastResetTime) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 430 | if (ec) |
| 431 | { |
| 432 | BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); |
| 433 | return; |
| 434 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 435 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 436 | // LastRebootTime is epoch time, in milliseconds |
| 437 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 |
| 438 | uint64_t lastResetTimeStamp = lastResetTime / 1000; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 439 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 440 | // Convert to ISO 8601 standard |
| 441 | asyncResp->res.jsonValue["LastResetTime"] = |
| 442 | redfish::time_utils::getDateTimeUint(lastResetTimeStamp); |
| 443 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * @brief Set the running firmware image |
| 448 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 449 | * @param[i,o] asyncResp - Async response object |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 450 | * @param[i] runningFirmwareTarget - Image to make the running image |
| 451 | * |
| 452 | * @return void |
| 453 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 454 | inline void setActiveFirmwareImage( |
| 455 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 456 | const std::string& runningFirmwareTarget) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 457 | { |
| 458 | // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> |
| 459 | std::string::size_type idPos = runningFirmwareTarget.rfind('/'); |
| 460 | if (idPos == std::string::npos) |
| 461 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 462 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 463 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 464 | BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 465 | return; |
| 466 | } |
| 467 | idPos++; |
| 468 | if (idPos >= runningFirmwareTarget.size()) |
| 469 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 470 | messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 471 | "@odata.id"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 472 | BMCWEB_LOG_DEBUG("Invalid firmware ID."); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | std::string firmwareId = runningFirmwareTarget.substr(idPos); |
| 476 | |
| 477 | // Make sure the image is valid before setting priority |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 478 | sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); |
| 479 | dbus::utility::getManagedObjects( |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 480 | getBMCUpdateServiceName(), objPath, |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 481 | [asyncResp, firmwareId, runningFirmwareTarget]( |
| 482 | const boost::system::error_code& ec, |
| 483 | const dbus::utility::ManagedObjectType& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 484 | if (ec) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 485 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 486 | BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 487 | messages::internalError(asyncResp->res); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 488 | return; |
| 489 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 490 | |
| 491 | if (subtree.empty()) |
| 492 | { |
| 493 | BMCWEB_LOG_DEBUG("Can't find image!"); |
| 494 | messages::internalError(asyncResp->res); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | bool foundImage = false; |
| 499 | for (const auto& object : subtree) |
| 500 | { |
| 501 | const std::string& path = |
| 502 | static_cast<const std::string&>(object.first); |
| 503 | std::size_t idPos2 = path.rfind('/'); |
| 504 | |
| 505 | if (idPos2 == std::string::npos) |
| 506 | { |
| 507 | continue; |
| 508 | } |
| 509 | |
| 510 | idPos2++; |
| 511 | if (idPos2 >= path.size()) |
| 512 | { |
| 513 | continue; |
| 514 | } |
| 515 | |
| 516 | if (path.substr(idPos2) == firmwareId) |
| 517 | { |
| 518 | foundImage = true; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (!foundImage) |
| 524 | { |
| 525 | messages::propertyValueNotInList( |
| 526 | asyncResp->res, runningFirmwareTarget, "@odata.id"); |
| 527 | BMCWEB_LOG_DEBUG("Invalid firmware ID."); |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", |
| 532 | firmwareId); |
| 533 | |
| 534 | // Only support Immediate |
| 535 | // An addition could be a Redfish Setting like |
| 536 | // ActiveSoftwareImageApplyTime and support OnReset |
| 537 | sdbusplus::asio::setProperty( |
Jagpal Singh Gill | d27c31e | 2024-10-15 15:10:19 -0700 | [diff] [blame] | 538 | *crow::connections::systemBus, getBMCUpdateServiceName(), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 539 | "/xyz/openbmc_project/software/" + firmwareId, |
| 540 | "xyz.openbmc_project.Software.RedundancyPriority", "Priority", |
| 541 | static_cast<uint8_t>(0), |
| 542 | [asyncResp](const boost::system::error_code& ec2) { |
| 543 | if (ec2) |
| 544 | { |
| 545 | BMCWEB_LOG_DEBUG("D-Bus response error setting."); |
| 546 | messages::internalError(asyncResp->res); |
| 547 | return; |
| 548 | } |
| 549 | doBMCGracefulRestart(asyncResp); |
| 550 | }); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 551 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 552 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 553 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 554 | inline void afterSetDateTime( |
| 555 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 556 | const boost::system::error_code& ec, const sdbusplus::message_t& msg) |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 557 | { |
| 558 | if (ec) |
| 559 | { |
| 560 | BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", |
| 561 | ec); |
| 562 | const sd_bus_error* dbusError = msg.get_error(); |
| 563 | if (dbusError != nullptr) |
| 564 | { |
| 565 | std::string_view errorName(dbusError->name); |
| 566 | if (errorName == |
| 567 | "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") |
| 568 | { |
| 569 | BMCWEB_LOG_DEBUG("Setting conflict"); |
| 570 | messages::propertyValueConflict( |
| 571 | asyncResp->res, "DateTime", |
| 572 | "Managers/NetworkProtocol/NTPProcotolEnabled"); |
| 573 | return; |
| 574 | } |
| 575 | } |
| 576 | messages::internalError(asyncResp->res); |
| 577 | return; |
| 578 | } |
| 579 | asyncResp->res.result(boost::beast::http::status::no_content); |
| 580 | } |
| 581 | |
| 582 | inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 583 | const std::string& datetime) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 584 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 585 | BMCWEB_LOG_DEBUG("Set date time: {}", datetime); |
Borawski.Lukasz | 9c310685 | 2018-02-09 15:24:22 +0100 | [diff] [blame] | 586 | |
Ed Tanous | c2e3200 | 2023-01-07 22:05:08 -0800 | [diff] [blame] | 587 | std::optional<redfish::time_utils::usSinceEpoch> us = |
| 588 | redfish::time_utils::dateStringToEpoch(datetime); |
| 589 | if (!us) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 590 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 591 | messages::propertyValueFormatError(asyncResp->res, datetime, |
| 592 | "DateTime"); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 593 | return; |
| 594 | } |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 595 | // Set the absolute datetime |
| 596 | bool relative = false; |
| 597 | bool interactive = false; |
| 598 | crow::connections::systemBus->async_method_call( |
| 599 | [asyncResp](const boost::system::error_code& ec, |
| 600 | const sdbusplus::message_t& msg) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 601 | afterSetDateTime(asyncResp, ec, msg); |
| 602 | }, |
Ed Tanous | c51afd5 | 2024-03-07 10:13:14 -0800 | [diff] [blame] | 603 | "org.freedesktop.timedate1", "/org/freedesktop/timedate1", |
| 604 | "org.freedesktop.timedate1", "SetTime", us->count(), relative, |
| 605 | interactive); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 608 | inline void checkForQuiesced( |
| 609 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 610 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 611 | dbus::utility::getProperty<std::string>( |
| 612 | "org.freedesktop.systemd1", |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 613 | "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", |
| 614 | "org.freedesktop.systemd1.Unit", "ActiveState", |
| 615 | [asyncResp](const boost::system::error_code& ec, |
| 616 | const std::string& val) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 617 | if (!ec) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 618 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 619 | if (val == "active") |
| 620 | { |
| 621 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 622 | resource::Health::Critical; |
| 623 | asyncResp->res.jsonValue["Status"]["State"] = |
| 624 | resource::State::Quiesced; |
| 625 | return; |
| 626 | } |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 627 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 628 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
| 629 | asyncResp->res.jsonValue["Status"]["State"] = |
| 630 | resource::State::Enabled; |
| 631 | }); |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Janet Adkins | e2cdf06 | 2025-06-18 11:17:35 -0500 | [diff] [blame] | 634 | inline void getPhysicalAssets( |
| 635 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 636 | const boost::system::error_code& ec, |
| 637 | const dbus::utility::DBusPropertiesMap& propertiesList) |
| 638 | { |
| 639 | if (ec) |
| 640 | { |
| 641 | BMCWEB_LOG_DEBUG("Can't get bmc asset!"); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | const std::string* partNumber = nullptr; |
| 646 | const std::string* serialNumber = nullptr; |
| 647 | const std::string* manufacturer = nullptr; |
| 648 | const std::string* model = nullptr; |
| 649 | const std::string* sparePartNumber = nullptr; |
| 650 | |
| 651 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 652 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 653 | partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, |
| 654 | "Model", model, "SparePartNumber", sparePartNumber); |
| 655 | |
| 656 | if (!success) |
| 657 | { |
| 658 | messages::internalError(asyncResp->res); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | if (partNumber != nullptr) |
| 663 | { |
| 664 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 665 | } |
| 666 | |
| 667 | if (serialNumber != nullptr) |
| 668 | { |
| 669 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 670 | } |
| 671 | |
| 672 | if (manufacturer != nullptr) |
| 673 | { |
| 674 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 675 | } |
| 676 | |
| 677 | if (model != nullptr) |
| 678 | { |
| 679 | asyncResp->res.jsonValue["Model"] = *model; |
| 680 | } |
| 681 | |
| 682 | if (sparePartNumber != nullptr) |
| 683 | { |
| 684 | asyncResp->res.jsonValue["SparePartNumber"] = *sparePartNumber; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | inline void getManagerData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 689 | const std::string& managerPath, |
| 690 | const dbus::utility::MapperServiceMap& serviceMap) |
| 691 | { |
| 692 | if (managerPath.empty() || serviceMap.size() != 1) |
| 693 | { |
| 694 | BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); |
| 695 | messages::internalError(asyncResp->res); |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | for (const auto& [connectionName, interfaces] : serviceMap) |
| 700 | { |
| 701 | for (const auto& interfaceName : interfaces) |
| 702 | { |
| 703 | if (interfaceName == |
| 704 | "xyz.openbmc_project.Inventory.Decorator.Asset") |
| 705 | { |
| 706 | dbus::utility::getAllProperties( |
| 707 | *crow::connections::systemBus, connectionName, managerPath, |
| 708 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 709 | std::bind_front(getPhysicalAssets, asyncResp)); |
| 710 | } |
| 711 | else if (interfaceName == |
| 712 | "xyz.openbmc_project.Inventory.Decorator.LocationCode") |
| 713 | { |
| 714 | getLocation(asyncResp, connectionName, managerPath); |
| 715 | } |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 716 | else if (interfaceName == |
| 717 | "xyz.openbmc_project.Association.Definitions") |
| 718 | { |
| 719 | getLocationIndicatorActive(asyncResp, managerPath); |
| 720 | } |
Janet Adkins | e2cdf06 | 2025-06-18 11:17:35 -0500 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | inline void afterGetManagerObject( |
| 726 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 727 | const boost::system::error_code& ec, |
| 728 | const dbus::utility::MapperGetSubTreeResponse& subtree, |
| 729 | const std::function< |
| 730 | void(const std::string& managerPath, |
| 731 | const dbus::utility::MapperServiceMap& serviceMap)>& callback) |
| 732 | { |
| 733 | if (ec) |
| 734 | { |
| 735 | BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); |
| 736 | return; |
| 737 | } |
| 738 | if (subtree.empty()) |
| 739 | { |
| 740 | BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); |
| 741 | return; |
| 742 | } |
| 743 | // Assume only 1 bmc D-Bus object |
| 744 | // Throw an error if there is more than 1 |
| 745 | if (subtree.size() > 1) |
| 746 | { |
| 747 | BMCWEB_LOG_ERROR("Found more than 1 bmc D-Bus object!"); |
| 748 | messages::internalError(asyncResp->res); |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | callback(subtree[0].first, subtree[0].second); |
| 753 | } |
| 754 | |
| 755 | inline void getManagerObject( |
| 756 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 757 | const std::string& /* managerId */, |
| 758 | std::function<void(const std::string& managerPath, |
| 759 | const dbus::utility::MapperServiceMap& serviceMap)>&& |
| 760 | callback) |
| 761 | { |
| 762 | constexpr std::array<std::string_view, 1> interfaces = { |
| 763 | "xyz.openbmc_project.Inventory.Item.Bmc"}; |
| 764 | dbus::utility::getSubTree( |
| 765 | "/xyz/openbmc_project/inventory", 0, interfaces, |
| 766 | [asyncResp, callback{std::move(callback)}]( |
| 767 | const boost::system::error_code& ec, |
| 768 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
| 769 | afterGetManagerObject(asyncResp, ec, subtree, callback); |
| 770 | }); |
| 771 | } |
| 772 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 773 | inline void requestRoutesManager(App& app) |
| 774 | { |
| 775 | std::string uuid = persistent_data::getConfig().systemUuid; |
| 776 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 777 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 778 | .privileges(redfish::privileges::getManager) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 779 | .methods( |
| 780 | boost::beast::http::verb:: |
| 781 | get)([&app, |
| 782 | uuid](const crow::Request& req, |
| 783 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 784 | const std::string& managerId) { |
| 785 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 786 | { |
| 787 | return; |
| 788 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 789 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 790 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 791 | { |
| 792 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 793 | managerId); |
| 794 | return; |
| 795 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 796 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 797 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 798 | "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 799 | asyncResp->res.jsonValue["@odata.type"] = |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 800 | "#Manager.v1_15_0.Manager"; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 801 | asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME; |
| 802 | asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; |
| 803 | asyncResp->res.jsonValue["Description"] = |
| 804 | "Baseboard Management Controller"; |
| 805 | asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 806 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 807 | asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC; |
| 808 | asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); |
| 809 | asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; |
| 810 | asyncResp->res.jsonValue["Model"] = |
| 811 | "OpenBmc"; // TODO(ed), get model |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 812 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 813 | asyncResp->res.jsonValue["LogServices"]["@odata.id"] = |
| 814 | boost::urls::format("/redfish/v1/Managers/{}/LogServices", |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 815 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 816 | asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = |
| 817 | boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol", |
| 818 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 819 | asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = |
| 820 | boost::urls::format( |
| 821 | "/redfish/v1/Managers/{}/EthernetInterfaces", |
| 822 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 823 | |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 824 | manager_utils::getServiceIdentification(asyncResp, false); |
| 825 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 826 | if constexpr (BMCWEB_VM_NBDPROXY) |
Ed Tanous | 75815e5 | 2022-10-05 17:21:13 -0700 | [diff] [blame] | 827 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 828 | asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = |
| 829 | boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", |
| 830 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 833 | // Manager.Reset (an action) can be many values, OpenBMC only |
| 834 | // supports BMC reboot. |
| 835 | nlohmann::json& managerReset = |
| 836 | asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; |
| 837 | managerReset["target"] = boost::urls::format( |
| 838 | "/redfish/v1/Managers/{}/Actions/Manager.Reset", |
| 839 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 840 | managerReset["@Redfish.ActionInfo"] = |
| 841 | boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", |
| 842 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 843 | |
| 844 | // ResetToDefaults (Factory Reset) has values like |
| 845 | // PreserveNetworkAndUsers and PreserveNetwork that aren't supported |
| 846 | // on OpenBMC |
| 847 | nlohmann::json& resetToDefaults = |
| 848 | asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; |
| 849 | resetToDefaults["target"] = boost::urls::format( |
| 850 | "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", |
| 851 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 852 | resetToDefaults["ResetType@Redfish.AllowableValues"] = |
| 853 | nlohmann::json::array_t({"ResetAll"}); |
| 854 | |
| 855 | std::pair<std::string, std::string> redfishDateTimeOffset = |
| 856 | redfish::time_utils::getDateTimeOffsetNow(); |
| 857 | |
| 858 | asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; |
| 859 | asyncResp->res.jsonValue["DateTimeLocalOffset"] = |
| 860 | redfishDateTimeOffset.second; |
| 861 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 862 | if constexpr (BMCWEB_KVM) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 863 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 864 | // Fill in GraphicalConsole info |
| 865 | asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = |
| 866 | true; |
| 867 | asyncResp->res |
| 868 | .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; |
| 869 | asyncResp->res |
| 870 | .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = |
| 871 | nlohmann::json::array_t({"KVMIP"}); |
| 872 | } |
| 873 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 874 | { |
| 875 | asyncResp->res |
| 876 | .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; |
| 877 | |
| 878 | nlohmann::json::array_t managerForServers; |
| 879 | nlohmann::json::object_t manager; |
| 880 | manager["@odata.id"] = std::format( |
| 881 | "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); |
| 882 | managerForServers.emplace_back(std::move(manager)); |
| 883 | |
| 884 | asyncResp->res.jsonValue["Links"]["ManagerForServers"] = |
| 885 | std::move(managerForServers); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 886 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 887 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 888 | sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, |
| 889 | "FirmwareVersion", true); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 890 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 891 | managerGetLastResetTime(asyncResp); |
| 892 | |
| 893 | // ManagerDiagnosticData is added for all BMCs. |
| 894 | nlohmann::json& managerDiagnosticData = |
| 895 | asyncResp->res.jsonValue["ManagerDiagnosticData"]; |
| 896 | managerDiagnosticData["@odata.id"] = boost::urls::format( |
| 897 | "/redfish/v1/Managers/{}/ManagerDiagnosticData", |
| 898 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 899 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 900 | getMainChassisId(asyncResp, [](const std::string& chassisId, |
| 901 | const std::shared_ptr< |
| 902 | bmcweb::AsyncResp>& aRsp) { |
| 903 | aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = |
| 904 | 1; |
| 905 | nlohmann::json::array_t managerForChassis; |
| 906 | nlohmann::json::object_t managerObj; |
| 907 | boost::urls::url chassiUrl = |
| 908 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
| 909 | managerObj["@odata.id"] = chassiUrl; |
| 910 | managerForChassis.emplace_back(std::move(managerObj)); |
| 911 | aRsp->res.jsonValue["Links"]["ManagerForChassis"] = |
| 912 | std::move(managerForChassis); |
| 913 | aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = |
| 914 | chassiUrl; |
| 915 | }); |
| 916 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 917 | dbus::utility::getProperty<double>( |
| 918 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 919 | "org.freedesktop.systemd1.Manager", "Progress", |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 920 | [asyncResp](const boost::system::error_code& ec, double val) { |
| 921 | if (ec) |
| 922 | { |
| 923 | BMCWEB_LOG_ERROR("Error while getting progress"); |
| 924 | messages::internalError(asyncResp->res); |
| 925 | return; |
| 926 | } |
| 927 | if (val < 1.0) |
| 928 | { |
| 929 | asyncResp->res.jsonValue["Status"]["Health"] = |
| 930 | resource::Health::OK; |
| 931 | asyncResp->res.jsonValue["Status"]["State"] = |
| 932 | resource::State::Starting; |
| 933 | return; |
| 934 | } |
| 935 | checkForQuiesced(asyncResp); |
| 936 | }); |
| 937 | |
Janet Adkins | e2cdf06 | 2025-06-18 11:17:35 -0500 | [diff] [blame] | 938 | getManagerObject(asyncResp, managerId, |
| 939 | std::bind_front(getManagerData, asyncResp)); |
rohitpai | c1a75eb | 2025-01-03 19:13:36 +0530 | [diff] [blame] | 940 | |
| 941 | RedfishService::getInstance(app).handleSubRoute(req, asyncResp); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 942 | }); |
| 943 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 944 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 945 | .privileges(redfish::privileges::patchManager) |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 946 | .methods(boost::beast::http::verb::patch)( |
| 947 | [&app](const crow::Request& req, |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 948 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 949 | const std::string& managerId) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 950 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 951 | { |
| 952 | return; |
| 953 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 954 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 955 | if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) |
| 956 | { |
| 957 | messages::resourceNotFound(asyncResp->res, "Manager", |
| 958 | managerId); |
| 959 | return; |
| 960 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 961 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 962 | std::optional<std::string> activeSoftwareImageOdataId; |
| 963 | std::optional<std::string> datetime; |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 964 | std::optional<bool> locationIndicatorActive; |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 965 | std::optional<nlohmann::json::object_t> pidControllers; |
| 966 | std::optional<nlohmann::json::object_t> fanControllers; |
| 967 | std::optional<nlohmann::json::object_t> fanZones; |
| 968 | std::optional<nlohmann::json::object_t> stepwiseControllers; |
| 969 | std::optional<std::string> profile; |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 970 | std::optional<std::string> serviceIdentification; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 971 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 972 | if (!json_util::readJsonPatch( // |
| 973 | req, asyncResp->res, // |
| 974 | "DateTime", datetime, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 975 | "Links/ActiveSoftwareImage/@odata.id", |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 976 | activeSoftwareImageOdataId, // |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 977 | "LocationIndicatorActive", |
| 978 | locationIndicatorActive, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 979 | "Oem/OpenBmc/Fan/FanControllers", fanControllers, // |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 980 | "Oem/OpenBmc/Fan/FanZones", fanZones, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 981 | "Oem/OpenBmc/Fan/PidControllers", pidControllers, // |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 982 | "Oem/OpenBmc/Fan/Profile", profile, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 983 | "Oem/OpenBmc/Fan/StepwiseControllers", |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 984 | stepwiseControllers, // |
| 985 | "ServiceIdentification", serviceIdentification // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 986 | )) |
| 987 | { |
| 988 | return; |
| 989 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 990 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 991 | if (activeSoftwareImageOdataId) |
| 992 | { |
| 993 | setActiveFirmwareImage(asyncResp, |
| 994 | *activeSoftwareImageOdataId); |
| 995 | } |
Ed Tanous | 9e9b604 | 2024-03-06 14:18:28 -0800 | [diff] [blame] | 996 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 997 | if (datetime) |
| 998 | { |
| 999 | setDateTime(asyncResp, *datetime); |
| 1000 | } |
rohitpai | 84aad24 | 2025-01-28 09:23:53 +0530 | [diff] [blame] | 1001 | |
George Liu | 79f3b6a | 2021-05-13 18:08:44 +0800 | [diff] [blame] | 1002 | if (locationIndicatorActive) |
| 1003 | { |
| 1004 | setLocationIndicatorActiveState( |
| 1005 | asyncResp, *locationIndicatorActive, managerId); |
| 1006 | } |
| 1007 | |
Corey Ethington | e30d334 | 2025-06-24 11:25:11 -0400 | [diff] [blame^] | 1008 | if (serviceIdentification) |
| 1009 | { |
| 1010 | manager_utils::setServiceIdentification( |
| 1011 | asyncResp, serviceIdentification.value()); |
| 1012 | } |
| 1013 | |
rohitpai | 84aad24 | 2025-01-28 09:23:53 +0530 | [diff] [blame] | 1014 | RedfishService::getInstance(app).handleSubRoute(req, asyncResp); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1015 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | inline void requestRoutesManagerCollection(App& app) |
| 1019 | { |
| 1020 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 1021 | .privileges(redfish::privileges::getManagerCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1022 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 1023 | [&app](const crow::Request& req, |
| 1024 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1025 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 1026 | { |
| 1027 | return; |
| 1028 | } |
| 1029 | // Collections don't include the static data added by SubRoute |
| 1030 | // because it has a duplicate entry for members |
| 1031 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; |
| 1032 | asyncResp->res.jsonValue["@odata.type"] = |
| 1033 | "#ManagerCollection.ManagerCollection"; |
| 1034 | asyncResp->res.jsonValue["Name"] = "Manager Collection"; |
| 1035 | asyncResp->res.jsonValue["Members@odata.count"] = 1; |
| 1036 | nlohmann::json::array_t members; |
| 1037 | nlohmann::json& bmc = members.emplace_back(); |
| 1038 | bmc["@odata.id"] = boost::urls::format( |
| 1039 | "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); |
| 1040 | asyncResp->res.jsonValue["Members"] = std::move(members); |
| 1041 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 1042 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1043 | } // namespace redfish |