Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "account_service.hpp" |
| 19 | #include "app.hpp" |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 20 | #include "async_resp.hpp" |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 21 | #include "credential_pipe.hpp" |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 22 | #include "dbus_utility.hpp" |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 23 | #include "generated/enums/virtual_media.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 24 | #include "query.hpp" |
| 25 | #include "registries/privilege_registry.hpp" |
| 26 | #include "utils/json_utils.hpp" |
| 27 | |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 28 | #include <boost/process/async_pipe.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 29 | #include <boost/url/format.hpp> |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 30 | #include <boost/url/url_view.hpp> |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 31 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 32 | #include <array> |
Ed Tanous | 3544d2a | 2023-08-06 18:12:20 -0700 | [diff] [blame] | 33 | #include <ranges> |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 34 | #include <string_view> |
| 35 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 36 | namespace redfish |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 37 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 38 | |
| 39 | enum class VmMode |
| 40 | { |
| 41 | Invalid, |
| 42 | Legacy, |
| 43 | Proxy |
| 44 | }; |
| 45 | |
| 46 | inline VmMode |
| 47 | parseObjectPathAndGetMode(const sdbusplus::message::object_path& itemPath, |
| 48 | const std::string& resName) |
| 49 | { |
| 50 | std::string thisPath = itemPath.filename(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 51 | BMCWEB_LOG_DEBUG("Filename: {}, ThisPath: {}", itemPath.str, thisPath); |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 52 | |
| 53 | if (thisPath.empty()) |
| 54 | { |
| 55 | return VmMode::Invalid; |
| 56 | } |
| 57 | |
| 58 | if (thisPath != resName) |
| 59 | { |
| 60 | return VmMode::Invalid; |
| 61 | } |
| 62 | |
| 63 | auto mode = itemPath.parent_path(); |
| 64 | auto type = mode.parent_path(); |
| 65 | |
| 66 | if (mode.filename().empty() || type.filename().empty()) |
| 67 | { |
| 68 | return VmMode::Invalid; |
| 69 | } |
| 70 | |
| 71 | if (type.filename() != "VirtualMedia") |
| 72 | { |
| 73 | return VmMode::Invalid; |
| 74 | } |
| 75 | std::string modeStr = mode.filename(); |
| 76 | if (modeStr == "Legacy") |
| 77 | { |
| 78 | return VmMode::Legacy; |
| 79 | } |
| 80 | if (modeStr == "Proxy") |
| 81 | { |
| 82 | return VmMode::Proxy; |
| 83 | } |
| 84 | return VmMode::Invalid; |
| 85 | } |
| 86 | |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 87 | using CheckItemHandler = |
| 88 | std::function<void(const std::string& service, const std::string& resName, |
| 89 | const std::shared_ptr<bmcweb::AsyncResp>&, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 90 | const std::pair<sdbusplus::message::object_path, |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 91 | dbus::utility::DBusInterfacesMap>&)>; |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 92 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 93 | inline void |
| 94 | findAndParseObject(const std::string& service, const std::string& resName, |
| 95 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 96 | CheckItemHandler&& handler) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 97 | { |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 98 | sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia"); |
| 99 | dbus::utility::getManagedObjects( |
| 100 | service, path, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 101 | [service, resName, asyncResp, |
Lakshmi Yadlapati | 746c5b8 | 2023-03-06 16:07:28 -0600 | [diff] [blame] | 102 | handler](const boost::system::error_code& ec, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 103 | const dbus::utility::ManagedObjectType& subtree) { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 104 | if (ec) |
| 105 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 106 | BMCWEB_LOG_DEBUG("DBUS response error"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 107 | |
| 108 | return; |
| 109 | } |
| 110 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 111 | for (const auto& item : subtree) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 112 | { |
| 113 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 114 | if (mode != VmMode::Invalid) |
| 115 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 116 | handler(service, resName, asyncResp, item); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 117 | return; |
| 118 | } |
| 119 | } |
| 120 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 121 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 122 | asyncResp->res.result(boost::beast::http::status::not_found); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 123 | }); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 126 | /** |
| 127 | * @brief Function extracts transfer protocol name from URI. |
| 128 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 129 | inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri) |
| 130 | { |
| 131 | boost::urls::result<boost::urls::url_view> url = |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 132 | boost::urls::parse_uri(imageUri); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 133 | if (!url) |
| 134 | { |
| 135 | return "None"; |
| 136 | } |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 137 | std::string_view scheme = url->scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 138 | if (scheme == "smb") |
| 139 | { |
| 140 | return "CIFS"; |
| 141 | } |
| 142 | if (scheme == "https") |
| 143 | { |
| 144 | return "HTTPS"; |
| 145 | } |
| 146 | |
| 147 | return "None"; |
| 148 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * @brief Read all known properties from VM object interfaces |
| 152 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 153 | inline void |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 154 | vmParseInterfaceObject(const dbus::utility::DBusInterfacesMap& interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 155 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 156 | { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 157 | for (const auto& [interface, values] : interfaces) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 158 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 159 | if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 160 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 161 | for (const auto& [property, value] : values) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 162 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 163 | if (property == "EndpointId") |
| 164 | { |
| 165 | const std::string* endpointIdValue = |
| 166 | std::get_if<std::string>(&value); |
| 167 | if (endpointIdValue == nullptr) |
| 168 | { |
| 169 | continue; |
| 170 | } |
| 171 | if (!endpointIdValue->empty()) |
| 172 | { |
| 173 | // Proxy mode |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 174 | asyncResp->res |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 175 | .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] = |
| 176 | *endpointIdValue; |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 177 | asyncResp->res.jsonValue["TransferProtocolType"] = |
| 178 | "OEM"; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | if (property == "ImageURL") |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 182 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 183 | const std::string* imageUrlValue = |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 184 | std::get_if<std::string>(&value); |
Ed Tanous | 26f6976 | 2022-01-25 09:49:11 -0800 | [diff] [blame] | 185 | if (imageUrlValue != nullptr && !imageUrlValue->empty()) |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 186 | { |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 187 | std::filesystem::path filePath = *imageUrlValue; |
| 188 | if (!filePath.has_filename()) |
| 189 | { |
| 190 | // this will handle https share, which not |
| 191 | // necessarily has to have filename given. |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 192 | asyncResp->res.jsonValue["ImageName"] = ""; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 193 | } |
| 194 | else |
| 195 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 196 | asyncResp->res.jsonValue["ImageName"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 197 | filePath.filename(); |
| 198 | } |
Przemyslaw Czarnowski | da4784d | 2020-11-06 09:58:25 +0100 | [diff] [blame] | 199 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 200 | asyncResp->res.jsonValue["Image"] = *imageUrlValue; |
| 201 | asyncResp->res.jsonValue["TransferProtocolType"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 202 | getTransferProtocolTypeFromUri(*imageUrlValue); |
| 203 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 204 | asyncResp->res.jsonValue["ConnectedVia"] = |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 205 | virtual_media::ConnectedVia::URI; |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 206 | } |
| 207 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 208 | if (property == "WriteProtected") |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 209 | { |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 210 | const bool* writeProtectedValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 211 | if (writeProtectedValue != nullptr) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 212 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 213 | asyncResp->res.jsonValue["WriteProtected"] = |
Anna Platash | 9e319cf | 2020-11-17 10:18:31 +0100 | [diff] [blame] | 214 | *writeProtectedValue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
| 218 | } |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 219 | if (interface == "xyz.openbmc_project.VirtualMedia.Process") |
| 220 | { |
| 221 | for (const auto& [property, value] : values) |
| 222 | { |
| 223 | if (property == "Active") |
| 224 | { |
| 225 | const bool* activeValue = std::get_if<bool>(&value); |
Ed Tanous | e662eae | 2022-01-25 10:39:19 -0800 | [diff] [blame] | 226 | if (activeValue == nullptr) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 227 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 228 | BMCWEB_LOG_DEBUG("Value Active not found"); |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 229 | return; |
| 230 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 231 | asyncResp->res.jsonValue["Inserted"] = *activeValue; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 232 | |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 233 | if (*activeValue) |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 234 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 235 | asyncResp->res.jsonValue["ConnectedVia"] = |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 236 | virtual_media::ConnectedVia::Applet; |
Ed Tanous | 711ac7a | 2021-12-20 09:34:41 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | } |
| 240 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @brief Fill template for Virtual Media Item. |
| 246 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 247 | inline nlohmann::json vmItemTemplate(const std::string& name, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 248 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 249 | { |
| 250 | nlohmann::json item; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 251 | item["@odata.id"] = boost::urls::format( |
| 252 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, resName); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 253 | |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 254 | item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia"; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 255 | item["Name"] = "Virtual Removable Media"; |
| 256 | item["Id"] = resName; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 257 | item["WriteProtected"] = true; |
Ed Tanous | 739b87e | 2023-02-24 13:13:33 -0800 | [diff] [blame] | 258 | item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected; |
Ed Tanous | 613dabe | 2022-07-09 11:17:36 -0700 | [diff] [blame] | 259 | item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"}); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 260 | item["TransferMethod"] = "Stream"; |
Przemyslaw Czarnowski | d04ba32 | 2020-01-21 12:41:56 +0100 | [diff] [blame] | 261 | item["Oem"]["OpenBMC"]["@odata.type"] = |
| 262 | "#OemVirtualMedia.v1_0_0.VirtualMedia"; |
V-Sanjana | 15b8972 | 2023-05-11 16:27:03 +0530 | [diff] [blame] | 263 | item["Oem"]["OpenBMC"]["@odata.id"] = boost::urls::format( |
| 264 | "/redfish/v1/Managers/{}/VirtualMedia/{}#/Oem/OpenBMC", name, resName); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 265 | |
| 266 | return item; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * @brief Fills collection data |
| 271 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 272 | inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 273 | const std::string& service, |
| 274 | const std::string& name) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 275 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 276 | BMCWEB_LOG_DEBUG("Get available Virtual Media resources."); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 277 | sdbusplus::message::object_path objPath( |
| 278 | "/xyz/openbmc_project/VirtualMedia"); |
| 279 | dbus::utility::getManagedObjects( |
| 280 | service, objPath, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 281 | [name, asyncResp{std::move(asyncResp)}]( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 282 | const boost::system::error_code& ec, |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 283 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 284 | if (ec) |
| 285 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 286 | BMCWEB_LOG_DEBUG("DBUS response error"); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 287 | return; |
| 288 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 289 | nlohmann::json& members = asyncResp->res.jsonValue["Members"]; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 290 | members = nlohmann::json::array(); |
| 291 | |
| 292 | for (const auto& object : subtree) |
| 293 | { |
| 294 | nlohmann::json item; |
| 295 | std::string path = object.first.filename(); |
| 296 | if (path.empty()) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 297 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 298 | continue; |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 299 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 300 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 301 | item["@odata.id"] = boost::urls::format( |
| 302 | "/redfish/v1/Managers/{}/VirtualMedia/{}", name, path); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 303 | members.emplace_back(std::move(item)); |
| 304 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 305 | asyncResp->res.jsonValue["Members@odata.count"] = members.size(); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 306 | }); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 307 | } |
| 308 | |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 309 | inline void |
| 310 | afterGetVmData(const std::string& name, const std::string& /*service*/, |
| 311 | const std::string& resName, |
| 312 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 313 | const std::pair<sdbusplus::message::object_path, |
Michael Shen | 80f79a4 | 2023-08-24 13:41:53 +0000 | [diff] [blame] | 314 | dbus::utility::DBusInterfacesMap>& item) |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 315 | { |
| 316 | VmMode mode = parseObjectPathAndGetMode(item.first, resName); |
| 317 | if (mode == VmMode::Invalid) |
| 318 | { |
| 319 | return; |
| 320 | } |
| 321 | |
| 322 | asyncResp->res.jsonValue = vmItemTemplate(name, resName); |
| 323 | |
| 324 | // Check if dbus path is Legacy type |
| 325 | if (mode == VmMode::Legacy) |
| 326 | { |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 327 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"] |
| 328 | ["target"] = boost::urls::format( |
| 329 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.InsertMedia", |
| 330 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | vmParseInterfaceObject(item.second, asyncResp); |
| 334 | |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 335 | asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"] |
| 336 | ["target"] = boost::urls::format( |
| 337 | "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.EjectMedia", |
| 338 | name, resName); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 341 | /** |
| 342 | * @brief Fills data for specific resource |
| 343 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 344 | inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 345 | const std::string& service, const std::string& name, |
| 346 | const std::string& resName) |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 347 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 348 | BMCWEB_LOG_DEBUG("Get Virtual Media resource data."); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 349 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 350 | findAndParseObject(service, resName, asyncResp, |
George Liu | 70cbdf5 | 2023-03-04 12:07:25 +0800 | [diff] [blame] | 351 | std::bind_front(afterGetVmData, name)); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 352 | } |
| 353 | |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 354 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 355 | * @brief Transfer protocols supported for InsertMedia action. |
| 356 | * |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 357 | */ |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 358 | enum class TransferProtocol |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 359 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 360 | https, |
| 361 | smb, |
| 362 | invalid |
| 363 | }; |
| 364 | |
| 365 | /** |
| 366 | * @brief Function extracts transfer protocol type from URI. |
| 367 | * |
| 368 | */ |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 369 | inline std::optional<TransferProtocol> |
Ed Tanous | d9f466b | 2023-03-06 15:04:25 -0800 | [diff] [blame] | 370 | getTransferProtocolFromUri(boost::urls::url_view imageUri) |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 371 | { |
Ed Tanous | 079360a | 2022-06-29 10:05:19 -0700 | [diff] [blame] | 372 | std::string_view scheme = imageUri.scheme(); |
Ed Tanous | 67df073 | 2021-10-26 11:23:56 -0700 | [diff] [blame] | 373 | if (scheme == "smb") |
| 374 | { |
| 375 | return TransferProtocol::smb; |
| 376 | } |
| 377 | if (scheme == "https") |
| 378 | { |
| 379 | return TransferProtocol::https; |
| 380 | } |
| 381 | if (!scheme.empty()) |
| 382 | { |
| 383 | return TransferProtocol::invalid; |
| 384 | } |
| 385 | |
| 386 | return {}; |
| 387 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * @brief Function convert transfer protocol from string param. |
| 391 | * |
| 392 | */ |
| 393 | inline std::optional<TransferProtocol> getTransferProtocolFromParam( |
| 394 | const std::optional<std::string>& transferProtocolType) |
| 395 | { |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 396 | if (!transferProtocolType) |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 397 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 398 | return {}; |
Agata Olender | c6f4e01 | 2020-03-11 15:19:07 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 401 | if (*transferProtocolType == "CIFS") |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 402 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 403 | return TransferProtocol::smb; |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 406 | if (*transferProtocolType == "HTTPS") |
| 407 | { |
| 408 | return TransferProtocol::https; |
| 409 | } |
| 410 | |
| 411 | return TransferProtocol::invalid; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * @brief Function extends URI with transfer protocol type. |
| 416 | * |
| 417 | */ |
| 418 | inline std::string |
| 419 | getUriWithTransferProtocol(const std::string& imageUri, |
| 420 | const TransferProtocol& transferProtocol) |
| 421 | { |
| 422 | if (transferProtocol == TransferProtocol::smb) |
| 423 | { |
| 424 | return "smb://" + imageUri; |
| 425 | } |
| 426 | |
| 427 | if (transferProtocol == TransferProtocol::https) |
| 428 | { |
| 429 | return "https://" + imageUri; |
| 430 | } |
| 431 | |
| 432 | return imageUri; |
| 433 | } |
| 434 | |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 435 | struct InsertMediaActionParams |
| 436 | { |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 437 | std::optional<std::string> imageUrl; |
Przemyslaw Czarnowski | 1f2a40c | 2022-06-24 13:47:08 +0200 | [diff] [blame] | 438 | std::optional<std::string> userName; |
| 439 | std::optional<std::string> password; |
| 440 | std::optional<std::string> transferMethod; |
| 441 | std::optional<std::string> transferProtocolType; |
| 442 | std::optional<bool> writeProtected = true; |
| 443 | std::optional<bool> inserted; |
| 444 | }; |
| 445 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 446 | /** |
| 447 | * @brief Function transceives data with dbus directly. |
| 448 | * |
| 449 | * All BMC state properties will be retrieved before sending reset request. |
| 450 | */ |
| 451 | inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 452 | const std::string& service, const std::string& name, |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 453 | const std::string& imageUrl, bool rw, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 454 | std::string&& userName, std::string&& password) |
| 455 | { |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 456 | int fd = -1; |
| 457 | std::shared_ptr<CredentialsPipe> secretPipe; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 458 | if (!userName.empty() || !password.empty()) |
| 459 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 460 | // Payload must contain data + NULL delimiters |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 461 | constexpr const size_t secretLimit = 1024; |
| 462 | if (userName.size() + password.size() + 2 > secretLimit) |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 463 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 464 | BMCWEB_LOG_ERROR("Credentials too long to handle"); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 465 | messages::unrecognizedRequestBody(asyncResp->res); |
| 466 | return; |
| 467 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 468 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 469 | // Open pipe |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 470 | secretPipe = std::make_shared<CredentialsPipe>( |
| 471 | crow::connections::systemBus->get_io_context()); |
| 472 | fd = secretPipe->fd(); |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 473 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 474 | // Pass secret over pipe |
| 475 | secretPipe->asyncWrite( |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 476 | std::move(userName), std::move(password), |
| 477 | [asyncResp, secretPipe](const boost::system::error_code& ec, |
| 478 | std::size_t) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 479 | if (ec) |
| 480 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 481 | BMCWEB_LOG_ERROR("Failed to pass secret: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 482 | messages::internalError(asyncResp->res); |
| 483 | } |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 484 | }); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 485 | } |
Adrian Ambrożewicz | 988fb7b | 2020-01-13 18:52:46 +0100 | [diff] [blame] | 486 | |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 487 | dbus::utility::DbusVariantType unixFd( |
| 488 | std::in_place_type<sdbusplus::message::unix_fd>, fd); |
| 489 | |
| 490 | sdbusplus::message::object_path path( |
| 491 | "/xyz/openbmc_project/VirtualMedia/Legacy"); |
| 492 | path /= name; |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 493 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 494 | [asyncResp, secretPipe](const boost::system::error_code& ec, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 495 | bool success) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 496 | if (ec) |
| 497 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 498 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 499 | messages::internalError(asyncResp->res); |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 500 | return; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 501 | } |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 502 | if (!success) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 503 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 504 | BMCWEB_LOG_ERROR("Service responded with error"); |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 505 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 506 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 507 | }, |
Ed Tanous | 11e8f60 | 2023-08-24 14:25:18 -0700 | [diff] [blame^] | 508 | service, path.str, "xyz.openbmc_project.VirtualMedia.Legacy", "Mount", |
| 509 | imageUrl, rw, unixFd); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 513 | * @brief Function validate parameters of insert media request. |
| 514 | * |
| 515 | */ |
| 516 | inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 517 | const std::string& service, |
| 518 | const std::string& resName, |
| 519 | InsertMediaActionParams& actionParams) |
| 520 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 521 | BMCWEB_LOG_DEBUG("Validation started"); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 522 | // required param imageUrl must not be empty |
| 523 | if (!actionParams.imageUrl) |
| 524 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 525 | BMCWEB_LOG_ERROR("Request action parameter Image is empty."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 526 | |
| 527 | messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image"); |
| 528 | |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | // optional param inserted must be true |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 533 | if (actionParams.inserted && !*actionParams.inserted) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 534 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 535 | BMCWEB_LOG_ERROR( |
| 536 | "Request action optional parameter Inserted must be true."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 537 | |
| 538 | messages::actionParameterNotSupported(asyncResp->res, "Inserted", |
| 539 | "InsertMedia"); |
| 540 | |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | // optional param transferMethod must be stream |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 545 | if (actionParams.transferMethod && |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 546 | (*actionParams.transferMethod != "Stream")) |
| 547 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 548 | BMCWEB_LOG_ERROR("Request action optional parameter " |
| 549 | "TransferMethod must be Stream."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 550 | |
| 551 | messages::actionParameterNotSupported(asyncResp->res, "TransferMethod", |
| 552 | "InsertMedia"); |
| 553 | |
| 554 | return; |
| 555 | } |
| 556 | boost::urls::result<boost::urls::url_view> url = |
| 557 | boost::urls::parse_uri(*actionParams.imageUrl); |
| 558 | if (!url) |
| 559 | { |
| 560 | messages::actionParameterValueFormatError( |
| 561 | asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia"); |
| 562 | return; |
| 563 | } |
| 564 | std::optional<TransferProtocol> uriTransferProtocolType = |
| 565 | getTransferProtocolFromUri(*url); |
| 566 | |
| 567 | std::optional<TransferProtocol> paramTransferProtocolType = |
| 568 | getTransferProtocolFromParam(actionParams.transferProtocolType); |
| 569 | |
| 570 | // ImageUrl does not contain valid protocol type |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 571 | if (uriTransferProtocolType && |
| 572 | *uriTransferProtocolType == TransferProtocol::invalid) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 573 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 574 | BMCWEB_LOG_ERROR("Request action parameter ImageUrl must " |
| 575 | "contain specified protocol type from list: " |
| 576 | "(smb, https)."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 577 | |
| 578 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 579 | |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | // transferProtocolType should contain value from list |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 584 | if (paramTransferProtocolType && |
| 585 | *paramTransferProtocolType == TransferProtocol::invalid) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 586 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 587 | BMCWEB_LOG_ERROR("Request action parameter TransferProtocolType " |
| 588 | "must be provided with value from list: " |
| 589 | "(CIFS, HTTPS)."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 590 | |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 591 | messages::propertyValueNotInList( |
| 592 | asyncResp->res, actionParams.transferProtocolType.value_or(""), |
| 593 | "TransferProtocolType"); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | |
| 597 | // valid transfer protocol not provided either with URI nor param |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 598 | if (!uriTransferProtocolType && !paramTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 599 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 600 | BMCWEB_LOG_ERROR("Request action parameter ImageUrl must " |
| 601 | "contain specified protocol type or param " |
| 602 | "TransferProtocolType must be provided."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 603 | |
| 604 | messages::resourceAtUriInUnknownFormat(asyncResp->res, *url); |
| 605 | |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | // valid transfer protocol provided both with URI and param |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 610 | if (paramTransferProtocolType && uriTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 611 | { |
| 612 | // check if protocol is the same for URI and param |
| 613 | if (*paramTransferProtocolType != *uriTransferProtocolType) |
| 614 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 615 | BMCWEB_LOG_ERROR("Request action parameter " |
| 616 | "TransferProtocolType must contain the " |
| 617 | "same protocol type as protocol type " |
| 618 | "provided with param imageUrl."); |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 619 | |
| 620 | messages::actionParameterValueTypeError( |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 621 | asyncResp->res, actionParams.transferProtocolType.value_or(""), |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 622 | "TransferProtocolType", "InsertMedia"); |
| 623 | |
| 624 | return; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // validation passed, add protocol to URI if needed |
Boleslaw Ogonczyk Makowski | 7ead48e | 2023-09-01 15:57:10 +0200 | [diff] [blame] | 629 | if (!uriTransferProtocolType && paramTransferProtocolType) |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 630 | { |
| 631 | actionParams.imageUrl = getUriWithTransferProtocol( |
| 632 | *actionParams.imageUrl, *paramTransferProtocolType); |
| 633 | } |
| 634 | |
Jayaprakash Mutyala | 452bd8d | 2023-04-18 12:28:38 +0000 | [diff] [blame] | 635 | if (!actionParams.userName) |
| 636 | { |
| 637 | actionParams.userName = ""; |
| 638 | } |
| 639 | |
| 640 | if (!actionParams.password) |
| 641 | { |
| 642 | actionParams.password = ""; |
| 643 | } |
| 644 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 645 | doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl, |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 646 | !(actionParams.writeProtected.value_or(false)), |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 647 | std::move(*actionParams.userName), |
| 648 | std::move(*actionParams.password)); |
| 649 | } |
| 650 | |
| 651 | /** |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 652 | * @brief Function transceives data with dbus directly. |
| 653 | * |
| 654 | * All BMC state properties will be retrieved before sending reset request. |
| 655 | */ |
Ed Tanous | 24e740a | 2023-02-24 12:08:58 -0800 | [diff] [blame] | 656 | inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 657 | const std::string& service, const std::string& name, |
| 658 | bool legacy) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 659 | { |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 660 | // Legacy mount requires parameter with image |
| 661 | if (legacy) |
| 662 | { |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 663 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 664 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 665 | if (ec) |
| 666 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 667 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 668 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 669 | messages::internalError(asyncResp->res); |
| 670 | return; |
| 671 | } |
Adrian Ambrożewicz | d6da5be | 2020-01-13 18:31:01 +0100 | [diff] [blame] | 672 | }, |
| 673 | service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name, |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 674 | "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount"); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 675 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 676 | else // proxy |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 677 | { |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 678 | crow::connections::systemBus->async_method_call( |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 679 | [asyncResp](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 680 | if (ec) |
| 681 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 682 | BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 683 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 684 | messages::internalError(asyncResp->res); |
| 685 | return; |
| 686 | } |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 687 | }, |
| 688 | service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name, |
| 689 | "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount"); |
| 690 | } |
| 691 | } |
| 692 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 693 | inline void handleManagersVirtualMediaActionInsertPost( |
| 694 | crow::App& app, const crow::Request& req, |
| 695 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 696 | const std::string& name, const std::string& resName) |
| 697 | { |
| 698 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 699 | { |
| 700 | return; |
| 701 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 702 | |
| 703 | constexpr std::string_view action = "VirtualMedia.InsertMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 704 | if (name != "bmc") |
| 705 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 706 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 707 | |
| 708 | return; |
| 709 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 710 | InsertMediaActionParams actionParams; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 711 | |
Przemyslaw Czarnowski | 120fa86 | 2022-06-24 15:10:48 +0200 | [diff] [blame] | 712 | // Read obligatory parameters (url of image) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 713 | if (!json_util::readJsonAction( |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 714 | req, asyncResp->res, "Image", actionParams.imageUrl, |
| 715 | "WriteProtected", actionParams.writeProtected, "UserName", |
| 716 | actionParams.userName, "Password", actionParams.password, |
| 717 | "Inserted", actionParams.inserted, "TransferMethod", |
| 718 | actionParams.transferMethod, "TransferProtocolType", |
| 719 | actionParams.transferProtocolType)) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 720 | { |
| 721 | return; |
| 722 | } |
| 723 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 724 | dbus::utility::getDbusObject( |
| 725 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 726 | [asyncResp, action, actionParams, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 727 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 728 | const dbus::utility::MapperGetObject& getObjectType) mutable { |
| 729 | if (ec) |
| 730 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 731 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 732 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 733 | |
| 734 | return; |
| 735 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 736 | |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 737 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 738 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 739 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 740 | sdbusplus::message::object_path path( |
| 741 | "/xyz/openbmc_project/VirtualMedia"); |
| 742 | dbus::utility::getManagedObjects( |
| 743 | service, path, |
| 744 | [service, resName, action, actionParams, asyncResp]( |
| 745 | const boost::system::error_code& ec2, |
| 746 | const dbus::utility::ManagedObjectType& subtree) mutable { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 747 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 748 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 749 | // Not possible in proxy mode |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 750 | BMCWEB_LOG_DEBUG("InsertMedia not " |
| 751 | "allowed in proxy mode"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 752 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 753 | |
| 754 | return; |
| 755 | } |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 756 | for (const auto& object : subtree) |
| 757 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 758 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 759 | if (mode == VmMode::Legacy) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 760 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 761 | validateParams(asyncResp, service, resName, actionParams); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 762 | |
| 763 | return; |
| 764 | } |
| 765 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 766 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 767 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 768 | }); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 769 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | inline void handleManagersVirtualMediaActionEject( |
| 773 | crow::App& app, const crow::Request& req, |
| 774 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 775 | const std::string& managerName, const std::string& resName) |
| 776 | { |
| 777 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 778 | { |
| 779 | return; |
| 780 | } |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 781 | |
| 782 | constexpr std::string_view action = "VirtualMedia.EjectMedia"; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 783 | if (managerName != "bmc") |
| 784 | { |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 785 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 786 | |
| 787 | return; |
| 788 | } |
| 789 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 790 | dbus::utility::getDbusObject( |
| 791 | "/xyz/openbmc_project/VirtualMedia", {}, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 792 | [asyncResp, action, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 793 | resName](const boost::system::error_code& ec2, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 794 | const dbus::utility::MapperGetObject& getObjectType) { |
Ed Tanous | 8a59281 | 2022-06-04 09:06:59 -0700 | [diff] [blame] | 795 | if (ec2) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 796 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 797 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec2); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 798 | messages::internalError(asyncResp->res); |
| 799 | |
| 800 | return; |
| 801 | } |
| 802 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 803 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 804 | |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 805 | sdbusplus::message::object_path path( |
| 806 | "/xyz/openbmc_project/VirtualMedia"); |
| 807 | dbus::utility::getManagedObjects( |
| 808 | service, path, |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 809 | [resName, service, action, |
| 810 | asyncResp](const boost::system::error_code& ec, |
| 811 | const dbus::utility::ManagedObjectType& subtree) { |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 812 | if (ec) |
| 813 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 814 | BMCWEB_LOG_ERROR("ObjectMapper : No Service found"); |
Przemyslaw Czarnowski | 79fdf63 | 2022-06-28 18:11:59 +0200 | [diff] [blame] | 815 | messages::resourceNotFound(asyncResp->res, action, resName); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
| 819 | for (const auto& object : subtree) |
| 820 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 821 | VmMode mode = parseObjectPathAndGetMode(object.first, resName); |
| 822 | if (mode != VmMode::Invalid) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 823 | { |
Ed Tanous | 365a73f | 2023-02-24 12:16:49 -0800 | [diff] [blame] | 824 | doEjectAction(asyncResp, service, resName, |
| 825 | mode == VmMode::Legacy); |
Boleslaw Ogonczyk Makowski | 5880f0c | 2023-04-14 15:32:40 +0200 | [diff] [blame] | 826 | return; |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 829 | BMCWEB_LOG_DEBUG("Parent item not found"); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 830 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
George Liu | 5eb468d | 2023-06-20 17:03:24 +0800 | [diff] [blame] | 831 | }); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 832 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | inline void handleManagersVirtualMediaCollectionGet( |
| 836 | crow::App& app, const crow::Request& req, |
| 837 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 838 | const std::string& name) |
| 839 | { |
| 840 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 841 | { |
| 842 | return; |
| 843 | } |
| 844 | if (name != "bmc") |
| 845 | { |
| 846 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", name); |
| 847 | |
| 848 | return; |
| 849 | } |
| 850 | |
| 851 | asyncResp->res.jsonValue["@odata.type"] = |
| 852 | "#VirtualMediaCollection.VirtualMediaCollection"; |
| 853 | asyncResp->res.jsonValue["Name"] = "Virtual Media Services"; |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 854 | asyncResp->res.jsonValue["@odata.id"] = |
| 855 | boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", name); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 856 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 857 | dbus::utility::getDbusObject( |
| 858 | "/xyz/openbmc_project/VirtualMedia", {}, |
| 859 | [asyncResp, name](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 860 | const dbus::utility::MapperGetObject& getObjectType) { |
| 861 | if (ec) |
| 862 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 863 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 864 | messages::internalError(asyncResp->res); |
| 865 | |
| 866 | return; |
| 867 | } |
| 868 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 869 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 870 | |
| 871 | getVmResourceList(asyncResp, service, name); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 872 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | inline void |
| 876 | handleVirtualMediaGet(crow::App& app, const crow::Request& req, |
| 877 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 878 | const std::string& name, const std::string& resName) |
| 879 | { |
| 880 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 881 | { |
| 882 | return; |
| 883 | } |
| 884 | if (name != "bmc") |
| 885 | { |
| 886 | messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName); |
| 887 | |
| 888 | return; |
| 889 | } |
| 890 | |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 891 | dbus::utility::getDbusObject( |
| 892 | "/xyz/openbmc_project/VirtualMedia", {}, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 893 | [asyncResp, name, |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 894 | resName](const boost::system::error_code& ec, |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 895 | const dbus::utility::MapperGetObject& getObjectType) { |
| 896 | if (ec) |
| 897 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 898 | BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 899 | messages::internalError(asyncResp->res); |
| 900 | |
| 901 | return; |
| 902 | } |
| 903 | std::string service = getObjectType.begin()->first; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 904 | BMCWEB_LOG_DEBUG("GetObjectType: {}", service); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 905 | |
| 906 | getVmData(asyncResp, service, name, resName); |
George Liu | 2b73119 | 2023-01-11 16:27:13 +0800 | [diff] [blame] | 907 | }); |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 910 | inline void requestNBDVirtualMediaRoutes(App& app) |
| 911 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 912 | BMCWEB_ROUTE( |
| 913 | app, |
| 914 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 915 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 916 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 917 | handleManagersVirtualMediaActionInsertPost, std::ref(app))); |
Przemyslaw Czarnowski | e13c276 | 2019-09-02 17:32:43 +0200 | [diff] [blame] | 918 | |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 919 | BMCWEB_ROUTE( |
| 920 | app, |
| 921 | "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 922 | .privileges(redfish::privileges::postVirtualMedia) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 923 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 924 | handleManagersVirtualMediaActionEject, std::ref(app))); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 925 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 926 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 927 | .privileges(redfish::privileges::getVirtualMediaCollection) |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 928 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 929 | handleManagersVirtualMediaCollectionGet, std::ref(app))); |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 930 | |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 931 | BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 932 | .privileges(redfish::privileges::getVirtualMedia) |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 933 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 96825be | 2022-06-03 09:43:38 -0700 | [diff] [blame] | 934 | std::bind_front(handleVirtualMediaGet, std::ref(app))); |
Ed Tanous | 22db172 | 2021-06-09 10:53:51 -0700 | [diff] [blame] | 935 | } |
Przemyslaw Czarnowski | 107077d | 2019-07-11 10:16:43 +0200 | [diff] [blame] | 936 | |
| 937 | } // namespace redfish |