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