blob: a18f1d03ca4c1dc4e760738cffa722a86038a6d5 [file] [log] [blame]
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +02001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2018 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020015*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "account_service.hpp"
19#include "app.hpp"
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +020020#include "async_resp.hpp"
Ed Tanous11e8f602023-08-24 14:25:18 -070021#include "credential_pipe.hpp"
George Liu2b731192023-01-11 16:27:13 +080022#include "dbus_utility.hpp"
Ed Tanous739b87e2023-02-24 13:13:33 -080023#include "generated/enums/virtual_media.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080024#include "query.hpp"
25#include "registries/privilege_registry.hpp"
26#include "utils/json_utils.hpp"
27
Ed Tanousef4c65b2023-04-24 15:28:50 -070028#include <boost/url/format.hpp>
Anna Platash9e319cf2020-11-17 10:18:31 +010029#include <boost/url/url_view.hpp>
Ed Tanous4a7fbef2024-04-06 16:03:49 -070030#include <boost/url/url_view_base.hpp>
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020031
George Liu2b731192023-01-11 16:27:13 +080032#include <array>
Ed Tanous3544d2a2023-08-06 18:12:20 -070033#include <ranges>
George Liu2b731192023-01-11 16:27:13 +080034#include <string_view>
35
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020036namespace redfish
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +020037{
Ed Tanous365a73f2023-02-24 12:16:49 -080038
39enum class VmMode
40{
41 Invalid,
42 Legacy,
43 Proxy
44};
45
Patrick Williamsbd79bce2024-08-16 15:22:20 -040046inline VmMode parseObjectPathAndGetMode(
47 const sdbusplus::message::object_path& itemPath, const std::string& resName)
Ed Tanous365a73f2023-02-24 12:16:49 -080048{
49 std::string thisPath = itemPath.filename();
Ed Tanous62598e32023-07-17 17:06:25 -070050 BMCWEB_LOG_DEBUG("Filename: {}, ThisPath: {}", itemPath.str, thisPath);
Ed Tanous365a73f2023-02-24 12:16:49 -080051
52 if (thisPath.empty())
53 {
54 return VmMode::Invalid;
55 }
56
57 if (thisPath != resName)
58 {
59 return VmMode::Invalid;
60 }
61
62 auto mode = itemPath.parent_path();
63 auto type = mode.parent_path();
64
65 if (mode.filename().empty() || type.filename().empty())
66 {
67 return VmMode::Invalid;
68 }
69
70 if (type.filename() != "VirtualMedia")
71 {
72 return VmMode::Invalid;
73 }
74 std::string modeStr = mode.filename();
75 if (modeStr == "Legacy")
76 {
77 return VmMode::Legacy;
78 }
79 if (modeStr == "Proxy")
80 {
81 return VmMode::Proxy;
82 }
83 return VmMode::Invalid;
84}
85
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +020086using CheckItemHandler =
87 std::function<void(const std::string& service, const std::string& resName,
88 const std::shared_ptr<bmcweb::AsyncResp>&,
George Liu70cbdf52023-03-04 12:07:25 +080089 const std::pair<sdbusplus::message::object_path,
Michael Shen80f79a42023-08-24 13:41:53 +000090 dbus::utility::DBusInterfacesMap>&)>;
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +020091
Ed Tanousac106bf2023-06-07 09:24:59 -070092inline void
93 findAndParseObject(const std::string& service, const std::string& resName,
94 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
95 CheckItemHandler&& handler)
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +020096{
George Liu5eb468d2023-06-20 17:03:24 +080097 sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia");
98 dbus::utility::getManagedObjects(
99 service, path,
Ed Tanous8cb2c022024-03-27 16:31:46 -0700100 [service, resName, asyncResp, handler = std::move(handler)](
101 const boost::system::error_code& ec,
102 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400103 if (ec)
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200104 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400105 BMCWEB_LOG_DEBUG("DBUS response error");
106
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200107 return;
108 }
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200109
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400110 for (const auto& item : subtree)
111 {
112 VmMode mode = parseObjectPathAndGetMode(item.first, resName);
113 if (mode != VmMode::Invalid)
114 {
115 handler(service, resName, asyncResp, item);
116 return;
117 }
118 }
119
120 BMCWEB_LOG_DEBUG("Parent item not found");
121 asyncResp->res.result(boost::beast::http::status::not_found);
122 });
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200123}
124
Anna Platash9e319cf2020-11-17 10:18:31 +0100125/**
126 * @brief Function extracts transfer protocol name from URI.
127 */
Ed Tanous67df0732021-10-26 11:23:56 -0700128inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri)
129{
Ed Tanous6fd29552023-10-04 09:40:14 -0700130 boost::system::result<boost::urls::url_view> url =
Ed Tanous079360a2022-06-29 10:05:19 -0700131 boost::urls::parse_uri(imageUri);
Ed Tanous67df0732021-10-26 11:23:56 -0700132 if (!url)
133 {
134 return "None";
135 }
Ed Tanous079360a2022-06-29 10:05:19 -0700136 std::string_view scheme = url->scheme();
Ed Tanous67df0732021-10-26 11:23:56 -0700137 if (scheme == "smb")
138 {
139 return "CIFS";
140 }
141 if (scheme == "https")
142 {
143 return "HTTPS";
144 }
145
146 return "None";
147}
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200148
149/**
150 * @brief Read all known properties from VM object interfaces
151 */
Ed Tanous22db1722021-06-09 10:53:51 -0700152inline void
Michael Shen80f79a42023-08-24 13:41:53 +0000153 vmParseInterfaceObject(const dbus::utility::DBusInterfacesMap& interfaces,
Ed Tanousac106bf2023-06-07 09:24:59 -0700154 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200155{
Ed Tanous8a592812022-06-04 09:06:59 -0700156 for (const auto& [interface, values] : interfaces)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200157 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800158 if (interface == "xyz.openbmc_project.VirtualMedia.MountPoint")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200159 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800160 for (const auto& [property, value] : values)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200161 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800162 if (property == "EndpointId")
163 {
164 const std::string* endpointIdValue =
165 std::get_if<std::string>(&value);
166 if (endpointIdValue == nullptr)
167 {
168 continue;
169 }
170 if (!endpointIdValue->empty())
171 {
172 // Proxy mode
Ed Tanousac106bf2023-06-07 09:24:59 -0700173 asyncResp->res
Ed Tanous711ac7a2021-12-20 09:34:41 -0800174 .jsonValue["Oem"]["OpenBMC"]["WebSocketEndpoint"] =
175 *endpointIdValue;
Ed Tanousac106bf2023-06-07 09:24:59 -0700176 asyncResp->res.jsonValue["TransferProtocolType"] =
177 "OEM";
Ed Tanous711ac7a2021-12-20 09:34:41 -0800178 }
179 }
180 if (property == "ImageURL")
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200181 {
Anna Platash9e319cf2020-11-17 10:18:31 +0100182 const std::string* imageUrlValue =
Ed Tanous711ac7a2021-12-20 09:34:41 -0800183 std::get_if<std::string>(&value);
Ed Tanous26f69762022-01-25 09:49:11 -0800184 if (imageUrlValue != nullptr && !imageUrlValue->empty())
Przemyslaw Czarnowskida4784d2020-11-06 09:58:25 +0100185 {
Anna Platash9e319cf2020-11-17 10:18:31 +0100186 std::filesystem::path filePath = *imageUrlValue;
187 if (!filePath.has_filename())
188 {
189 // this will handle https share, which not
190 // necessarily has to have filename given.
Ed Tanousac106bf2023-06-07 09:24:59 -0700191 asyncResp->res.jsonValue["ImageName"] = "";
Anna Platash9e319cf2020-11-17 10:18:31 +0100192 }
193 else
194 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700195 asyncResp->res.jsonValue["ImageName"] =
Anna Platash9e319cf2020-11-17 10:18:31 +0100196 filePath.filename();
197 }
Przemyslaw Czarnowskida4784d2020-11-06 09:58:25 +0100198
Ed Tanousac106bf2023-06-07 09:24:59 -0700199 asyncResp->res.jsonValue["Image"] = *imageUrlValue;
200 asyncResp->res.jsonValue["TransferProtocolType"] =
Anna Platash9e319cf2020-11-17 10:18:31 +0100201 getTransferProtocolTypeFromUri(*imageUrlValue);
202
Ed Tanousac106bf2023-06-07 09:24:59 -0700203 asyncResp->res.jsonValue["ConnectedVia"] =
Ed Tanous739b87e2023-02-24 13:13:33 -0800204 virtual_media::ConnectedVia::URI;
Anna Platash9e319cf2020-11-17 10:18:31 +0100205 }
206 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800207 if (property == "WriteProtected")
Anna Platash9e319cf2020-11-17 10:18:31 +0100208 {
Ed Tanous711ac7a2021-12-20 09:34:41 -0800209 const bool* writeProtectedValue = std::get_if<bool>(&value);
Ed Tanouse662eae2022-01-25 10:39:19 -0800210 if (writeProtectedValue != nullptr)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200211 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700212 asyncResp->res.jsonValue["WriteProtected"] =
Anna Platash9e319cf2020-11-17 10:18:31 +0100213 *writeProtectedValue;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200214 }
215 }
216 }
217 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800218 if (interface == "xyz.openbmc_project.VirtualMedia.Process")
219 {
220 for (const auto& [property, value] : values)
221 {
222 if (property == "Active")
223 {
224 const bool* activeValue = std::get_if<bool>(&value);
Ed Tanouse662eae2022-01-25 10:39:19 -0800225 if (activeValue == nullptr)
Ed Tanous711ac7a2021-12-20 09:34:41 -0800226 {
Ed Tanous62598e32023-07-17 17:06:25 -0700227 BMCWEB_LOG_DEBUG("Value Active not found");
Ed Tanous711ac7a2021-12-20 09:34:41 -0800228 return;
229 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700230 asyncResp->res.jsonValue["Inserted"] = *activeValue;
Ed Tanous711ac7a2021-12-20 09:34:41 -0800231
Ed Tanouse05aec52022-01-25 10:28:56 -0800232 if (*activeValue)
Ed Tanous711ac7a2021-12-20 09:34:41 -0800233 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700234 asyncResp->res.jsonValue["ConnectedVia"] =
Ed Tanous739b87e2023-02-24 13:13:33 -0800235 virtual_media::ConnectedVia::Applet;
Ed Tanous711ac7a2021-12-20 09:34:41 -0800236 }
237 }
238 }
239 }
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200240 }
241}
242
243/**
244 * @brief Fill template for Virtual Media Item.
245 */
Ed Tanous22db1722021-06-09 10:53:51 -0700246inline nlohmann::json vmItemTemplate(const std::string& name,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500247 const std::string& resName)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200248{
249 nlohmann::json item;
Ed Tanousef4c65b2023-04-24 15:28:50 -0700250 item["@odata.id"] = boost::urls::format(
251 "/redfish/v1/Managers/{}/VirtualMedia/{}", name, resName);
Ed Tanous22db1722021-06-09 10:53:51 -0700252
Przemyslaw Czarnowskid04ba322020-01-21 12:41:56 +0100253 item["@odata.type"] = "#VirtualMedia.v1_3_0.VirtualMedia";
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200254 item["Name"] = "Virtual Removable Media";
255 item["Id"] = resName;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200256 item["WriteProtected"] = true;
Ed Tanous739b87e2023-02-24 13:13:33 -0800257 item["ConnectedVia"] = virtual_media::ConnectedVia::NotConnected;
Ed Tanous613dabe2022-07-09 11:17:36 -0700258 item["MediaTypes"] = nlohmann::json::array_t({"CD", "USBStick"});
Ed Tanous539d8c62024-06-19 14:38:27 -0700259 item["TransferMethod"] = virtual_media::TransferMethod::Stream;
Przemyslaw Czarnowskid04ba322020-01-21 12:41:56 +0100260 item["Oem"]["OpenBMC"]["@odata.type"] =
Ed Tanousf958ed92024-07-12 11:16:59 -0700261 "#OpenBMCVirtualMedia.v1_0_0.VirtualMedia";
V-Sanjana15b89722023-05-11 16:27:03 +0530262 item["Oem"]["OpenBMC"]["@odata.id"] = boost::urls::format(
263 "/redfish/v1/Managers/{}/VirtualMedia/{}#/Oem/OpenBMC", name, resName);
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200264
265 return item;
266}
267
268/**
269 * @brief Fills collection data
270 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700271inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500272 const std::string& service,
273 const std::string& name)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200274{
Ed Tanous62598e32023-07-17 17:06:25 -0700275 BMCWEB_LOG_DEBUG("Get available Virtual Media resources.");
George Liu5eb468d2023-06-20 17:03:24 +0800276 sdbusplus::message::object_path objPath(
277 "/xyz/openbmc_project/VirtualMedia");
278 dbus::utility::getManagedObjects(
279 service, objPath,
Ed Tanousac106bf2023-06-07 09:24:59 -0700280 [name, asyncResp{std::move(asyncResp)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800281 const boost::system::error_code& ec,
Ed Tanous02cad962022-06-30 16:50:15 -0700282 const dbus::utility::ManagedObjectType& subtree) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400283 if (ec)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200284 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400285 BMCWEB_LOG_DEBUG("DBUS response error");
286 return;
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200287 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400288 nlohmann::json& members = asyncResp->res.jsonValue["Members"];
289 members = nlohmann::json::array();
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200290
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400291 for (const auto& object : subtree)
292 {
293 nlohmann::json item;
294 std::string path = object.first.filename();
295 if (path.empty())
296 {
297 continue;
298 }
299
300 item["@odata.id"] = boost::urls::format(
301 "/redfish/v1/Managers/{}/VirtualMedia/{}", name, path);
302 members.emplace_back(std::move(item));
303 }
304 asyncResp->res.jsonValue["Members@odata.count"] = members.size();
305 });
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200306}
307
George Liu70cbdf52023-03-04 12:07:25 +0800308inline void
309 afterGetVmData(const std::string& name, const std::string& /*service*/,
310 const std::string& resName,
311 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
312 const std::pair<sdbusplus::message::object_path,
Michael Shen80f79a42023-08-24 13:41:53 +0000313 dbus::utility::DBusInterfacesMap>& item)
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200314{
315 VmMode mode = parseObjectPathAndGetMode(item.first, resName);
316 if (mode == VmMode::Invalid)
317 {
318 return;
319 }
320
321 asyncResp->res.jsonValue = vmItemTemplate(name, resName);
322
323 // Check if dbus path is Legacy type
324 if (mode == VmMode::Legacy)
325 {
Ed Tanousef4c65b2023-04-24 15:28:50 -0700326 asyncResp->res.jsonValue["Actions"]["#VirtualMedia.InsertMedia"]
327 ["target"] = boost::urls::format(
328 "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.InsertMedia",
329 name, resName);
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200330 }
331
332 vmParseInterfaceObject(item.second, asyncResp);
333
Ed Tanousef4c65b2023-04-24 15:28:50 -0700334 asyncResp->res.jsonValue["Actions"]["#VirtualMedia.EjectMedia"]
335 ["target"] = boost::urls::format(
336 "/redfish/v1/Managers/{}/VirtualMedia/{}/Actions/VirtualMedia.EjectMedia",
337 name, resName);
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200338}
339
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200340/**
341 * @brief Fills data for specific resource
342 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700343inline void getVmData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500344 const std::string& service, const std::string& name,
345 const std::string& resName)
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200346{
Ed Tanous62598e32023-07-17 17:06:25 -0700347 BMCWEB_LOG_DEBUG("Get Virtual Media resource data.");
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200348
Ed Tanousac106bf2023-06-07 09:24:59 -0700349 findAndParseObject(service, resName, asyncResp,
George Liu70cbdf52023-03-04 12:07:25 +0800350 std::bind_front(afterGetVmData, name));
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200351}
352
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200353/**
Ed Tanous22db1722021-06-09 10:53:51 -0700354 * @brief Transfer protocols supported for InsertMedia action.
355 *
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200356 */
Ed Tanous22db1722021-06-09 10:53:51 -0700357enum class TransferProtocol
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200358{
Ed Tanous22db1722021-06-09 10:53:51 -0700359 https,
360 smb,
361 invalid
362};
363
364/**
365 * @brief Function extracts transfer protocol type from URI.
366 *
367 */
Ed Tanous67df0732021-10-26 11:23:56 -0700368inline std::optional<TransferProtocol>
Ed Tanous4a7fbef2024-04-06 16:03:49 -0700369 getTransferProtocolFromUri(const boost::urls::url_view_base& imageUri)
Ed Tanous67df0732021-10-26 11:23:56 -0700370{
Ed Tanous079360a2022-06-29 10:05:19 -0700371 std::string_view scheme = imageUri.scheme();
Ed Tanous67df0732021-10-26 11:23:56 -0700372 if (scheme == "smb")
373 {
374 return TransferProtocol::smb;
375 }
376 if (scheme == "https")
377 {
378 return TransferProtocol::https;
379 }
380 if (!scheme.empty())
381 {
382 return TransferProtocol::invalid;
383 }
384
385 return {};
386}
Ed Tanous22db1722021-06-09 10:53:51 -0700387
388/**
389 * @brief Function convert transfer protocol from string param.
390 *
391 */
392inline std::optional<TransferProtocol> getTransferProtocolFromParam(
393 const std::optional<std::string>& transferProtocolType)
394{
Ed Tanouse01d0c32023-06-30 13:21:32 -0700395 if (!transferProtocolType)
Agata Olenderc6f4e012020-03-11 15:19:07 +0100396 {
Ed Tanous22db1722021-06-09 10:53:51 -0700397 return {};
Agata Olenderc6f4e012020-03-11 15:19:07 +0100398 }
399
Ed Tanous22db1722021-06-09 10:53:51 -0700400 if (*transferProtocolType == "CIFS")
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200401 {
Ed Tanous22db1722021-06-09 10:53:51 -0700402 return TransferProtocol::smb;
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200403 }
404
Ed Tanous22db1722021-06-09 10:53:51 -0700405 if (*transferProtocolType == "HTTPS")
406 {
407 return TransferProtocol::https;
408 }
409
410 return TransferProtocol::invalid;
411}
412
413/**
414 * @brief Function extends URI with transfer protocol type.
415 *
416 */
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400417inline std::string getUriWithTransferProtocol(
418 const std::string& imageUri, const TransferProtocol& transferProtocol)
Ed Tanous22db1722021-06-09 10:53:51 -0700419{
420 if (transferProtocol == TransferProtocol::smb)
421 {
422 return "smb://" + imageUri;
423 }
424
425 if (transferProtocol == TransferProtocol::https)
426 {
427 return "https://" + imageUri;
428 }
429
430 return imageUri;
431}
432
Przemyslaw Czarnowski1f2a40c2022-06-24 13:47:08 +0200433struct InsertMediaActionParams
434{
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200435 std::optional<std::string> imageUrl;
Przemyslaw Czarnowski1f2a40c2022-06-24 13:47:08 +0200436 std::optional<std::string> userName;
437 std::optional<std::string> password;
438 std::optional<std::string> transferMethod;
439 std::optional<std::string> transferProtocolType;
440 std::optional<bool> writeProtected = true;
441 std::optional<bool> inserted;
442};
443
Ed Tanous22db1722021-06-09 10:53:51 -0700444/**
445 * @brief Function transceives data with dbus directly.
446 *
447 * All BMC state properties will be retrieved before sending reset request.
448 */
449inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
450 const std::string& service, const std::string& name,
Ed Tanous11e8f602023-08-24 14:25:18 -0700451 const std::string& imageUrl, bool rw,
Ed Tanous22db1722021-06-09 10:53:51 -0700452 std::string&& userName, std::string&& password)
453{
Ed Tanous11e8f602023-08-24 14:25:18 -0700454 int fd = -1;
455 std::shared_ptr<CredentialsPipe> secretPipe;
Ed Tanous22db1722021-06-09 10:53:51 -0700456 if (!userName.empty() || !password.empty())
457 {
Ed Tanous22db1722021-06-09 10:53:51 -0700458 // Payload must contain data + NULL delimiters
Ed Tanous11e8f602023-08-24 14:25:18 -0700459 constexpr const size_t secretLimit = 1024;
460 if (userName.size() + password.size() + 2 > secretLimit)
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100461 {
Ed Tanous62598e32023-07-17 17:06:25 -0700462 BMCWEB_LOG_ERROR("Credentials too long to handle");
Ed Tanous22db1722021-06-09 10:53:51 -0700463 messages::unrecognizedRequestBody(asyncResp->res);
464 return;
465 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100466
Ed Tanous22db1722021-06-09 10:53:51 -0700467 // Open pipe
Ed Tanous11e8f602023-08-24 14:25:18 -0700468 secretPipe = std::make_shared<CredentialsPipe>(
469 crow::connections::systemBus->get_io_context());
Ed Tanous3bfa3b22024-01-31 12:18:03 -0800470 fd = secretPipe->releaseFd();
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100471
Ed Tanous22db1722021-06-09 10:53:51 -0700472 // Pass secret over pipe
473 secretPipe->asyncWrite(
Ed Tanous11e8f602023-08-24 14:25:18 -0700474 std::move(userName), std::move(password),
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400475 [asyncResp,
476 secretPipe](const boost::system::error_code& ec, std::size_t) {
477 if (ec)
478 {
479 BMCWEB_LOG_ERROR("Failed to pass secret: {}", ec);
480 messages::internalError(asyncResp->res);
481 }
482 });
Ed Tanous22db1722021-06-09 10:53:51 -0700483 }
Adrian Ambrożewicz988fb7b2020-01-13 18:52:46 +0100484
Ed Tanous11e8f602023-08-24 14:25:18 -0700485 dbus::utility::DbusVariantType unixFd(
486 std::in_place_type<sdbusplus::message::unix_fd>, fd);
487
488 sdbusplus::message::object_path path(
489 "/xyz/openbmc_project/VirtualMedia/Legacy");
490 path /= name;
Ed Tanous22db1722021-06-09 10:53:51 -0700491 crow::connections::systemBus->async_method_call(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400492 [asyncResp,
493 secretPipe](const boost::system::error_code& ec, bool success) {
494 if (ec)
495 {
496 BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
497 messages::internalError(asyncResp->res);
498 return;
499 }
500 if (!success)
501 {
502 BMCWEB_LOG_ERROR("Service responded with error");
503 messages::internalError(asyncResp->res);
504 }
505 },
Ed Tanous11e8f602023-08-24 14:25:18 -0700506 service, path.str, "xyz.openbmc_project.VirtualMedia.Legacy", "Mount",
507 imageUrl, rw, unixFd);
Ed Tanous22db1722021-06-09 10:53:51 -0700508}
509
510/**
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200511 * @brief Function validate parameters of insert media request.
512 *
513 */
514inline void validateParams(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
515 const std::string& service,
516 const std::string& resName,
517 InsertMediaActionParams& actionParams)
518{
Ed Tanous62598e32023-07-17 17:06:25 -0700519 BMCWEB_LOG_DEBUG("Validation started");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200520 // required param imageUrl must not be empty
521 if (!actionParams.imageUrl)
522 {
Ed Tanous62598e32023-07-17 17:06:25 -0700523 BMCWEB_LOG_ERROR("Request action parameter Image is empty.");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200524
525 messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image");
526
527 return;
528 }
529
530 // optional param inserted must be true
Ed Tanouse01d0c32023-06-30 13:21:32 -0700531 if (actionParams.inserted && !*actionParams.inserted)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200532 {
Ed Tanous62598e32023-07-17 17:06:25 -0700533 BMCWEB_LOG_ERROR(
534 "Request action optional parameter Inserted must be true.");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200535
536 messages::actionParameterNotSupported(asyncResp->res, "Inserted",
537 "InsertMedia");
538
539 return;
540 }
541
542 // optional param transferMethod must be stream
Ed Tanouse01d0c32023-06-30 13:21:32 -0700543 if (actionParams.transferMethod &&
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200544 (*actionParams.transferMethod != "Stream"))
545 {
Ed Tanous62598e32023-07-17 17:06:25 -0700546 BMCWEB_LOG_ERROR("Request action optional parameter "
547 "TransferMethod must be Stream.");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200548
549 messages::actionParameterNotSupported(asyncResp->res, "TransferMethod",
550 "InsertMedia");
551
552 return;
553 }
Ed Tanous6fd29552023-10-04 09:40:14 -0700554 boost::system::result<boost::urls::url_view> url =
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200555 boost::urls::parse_uri(*actionParams.imageUrl);
556 if (!url)
557 {
558 messages::actionParameterValueFormatError(
559 asyncResp->res, *actionParams.imageUrl, "Image", "InsertMedia");
560 return;
561 }
562 std::optional<TransferProtocol> uriTransferProtocolType =
563 getTransferProtocolFromUri(*url);
564
565 std::optional<TransferProtocol> paramTransferProtocolType =
566 getTransferProtocolFromParam(actionParams.transferProtocolType);
567
568 // ImageUrl does not contain valid protocol type
Ed Tanouse01d0c32023-06-30 13:21:32 -0700569 if (uriTransferProtocolType &&
570 *uriTransferProtocolType == TransferProtocol::invalid)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200571 {
Ed Tanous62598e32023-07-17 17:06:25 -0700572 BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
573 "contain specified protocol type from list: "
574 "(smb, https).");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200575
576 messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
577
578 return;
579 }
580
581 // transferProtocolType should contain value from list
Ed Tanouse01d0c32023-06-30 13:21:32 -0700582 if (paramTransferProtocolType &&
583 *paramTransferProtocolType == TransferProtocol::invalid)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200584 {
Ed Tanous62598e32023-07-17 17:06:25 -0700585 BMCWEB_LOG_ERROR("Request action parameter TransferProtocolType "
586 "must be provided with value from list: "
587 "(CIFS, HTTPS).");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200588
Ed Tanouse01d0c32023-06-30 13:21:32 -0700589 messages::propertyValueNotInList(
590 asyncResp->res, actionParams.transferProtocolType.value_or(""),
591 "TransferProtocolType");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200592 return;
593 }
594
595 // valid transfer protocol not provided either with URI nor param
Ed Tanouse01d0c32023-06-30 13:21:32 -0700596 if (!uriTransferProtocolType && !paramTransferProtocolType)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200597 {
Ed Tanous62598e32023-07-17 17:06:25 -0700598 BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
599 "contain specified protocol type or param "
600 "TransferProtocolType must be provided.");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200601
602 messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
603
604 return;
605 }
606
607 // valid transfer protocol provided both with URI and param
Ed Tanouse01d0c32023-06-30 13:21:32 -0700608 if (paramTransferProtocolType && uriTransferProtocolType)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200609 {
610 // check if protocol is the same for URI and param
611 if (*paramTransferProtocolType != *uriTransferProtocolType)
612 {
Ed Tanous62598e32023-07-17 17:06:25 -0700613 BMCWEB_LOG_ERROR("Request action parameter "
614 "TransferProtocolType must contain the "
615 "same protocol type as protocol type "
616 "provided with param imageUrl.");
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200617
618 messages::actionParameterValueTypeError(
Ed Tanouse01d0c32023-06-30 13:21:32 -0700619 asyncResp->res, actionParams.transferProtocolType.value_or(""),
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200620 "TransferProtocolType", "InsertMedia");
621
622 return;
623 }
624 }
625
626 // validation passed, add protocol to URI if needed
Boleslaw Ogonczyk Makowski7ead48e2023-09-01 15:57:10 +0200627 if (!uriTransferProtocolType && paramTransferProtocolType)
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200628 {
629 actionParams.imageUrl = getUriWithTransferProtocol(
630 *actionParams.imageUrl, *paramTransferProtocolType);
631 }
632
Jayaprakash Mutyala452bd8d2023-04-18 12:28:38 +0000633 if (!actionParams.userName)
634 {
635 actionParams.userName = "";
636 }
637
638 if (!actionParams.password)
639 {
640 actionParams.password = "";
641 }
642
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200643 doMountVmLegacy(asyncResp, service, resName, *actionParams.imageUrl,
Ed Tanouse01d0c32023-06-30 13:21:32 -0700644 !(actionParams.writeProtected.value_or(false)),
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200645 std::move(*actionParams.userName),
646 std::move(*actionParams.password));
647}
648
649/**
Ed Tanous22db1722021-06-09 10:53:51 -0700650 * @brief Function transceives data with dbus directly.
651 *
652 * All BMC state properties will be retrieved before sending reset request.
653 */
Ed Tanous24e740a2023-02-24 12:08:58 -0800654inline void doEjectAction(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
655 const std::string& service, const std::string& name,
656 bool legacy)
Ed Tanous22db1722021-06-09 10:53:51 -0700657{
Ed Tanous22db1722021-06-09 10:53:51 -0700658 // Legacy mount requires parameter with image
659 if (legacy)
660 {
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100661 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800662 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400663 if (ec)
664 {
665 BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
Ed Tanous22db1722021-06-09 10:53:51 -0700666
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400667 messages::internalError(asyncResp->res);
668 return;
669 }
670 },
Adrian Ambrożewiczd6da5be2020-01-13 18:31:01 +0100671 service, "/xyz/openbmc_project/VirtualMedia/Legacy/" + name,
Ed Tanous22db1722021-06-09 10:53:51 -0700672 "xyz.openbmc_project.VirtualMedia.Legacy", "Unmount");
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200673 }
Ed Tanous22db1722021-06-09 10:53:51 -0700674 else // proxy
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200675 {
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200676 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800677 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400678 if (ec)
679 {
680 BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
Ed Tanous22db1722021-06-09 10:53:51 -0700681
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400682 messages::internalError(asyncResp->res);
683 return;
684 }
685 },
Ed Tanous22db1722021-06-09 10:53:51 -0700686 service, "/xyz/openbmc_project/VirtualMedia/Proxy/" + name,
687 "xyz.openbmc_project.VirtualMedia.Proxy", "Unmount");
688 }
689}
690
Ed Tanous96825be2022-06-03 09:43:38 -0700691inline void handleManagersVirtualMediaActionInsertPost(
692 crow::App& app, const crow::Request& req,
693 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
694 const std::string& name, const std::string& resName)
695{
696 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
697 {
698 return;
699 }
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200700
701 constexpr std::string_view action = "VirtualMedia.InsertMedia";
Ed Tanous96825be2022-06-03 09:43:38 -0700702 if (name != "bmc")
703 {
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200704 messages::resourceNotFound(asyncResp->res, action, resName);
Ed Tanous96825be2022-06-03 09:43:38 -0700705
706 return;
707 }
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200708 InsertMediaActionParams actionParams;
Ed Tanous96825be2022-06-03 09:43:38 -0700709
Przemyslaw Czarnowski120fa862022-06-24 15:10:48 +0200710 // Read obligatory parameters (url of image)
Ed Tanous96825be2022-06-03 09:43:38 -0700711 if (!json_util::readJsonAction(
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200712 req, asyncResp->res, "Image", actionParams.imageUrl,
713 "WriteProtected", actionParams.writeProtected, "UserName",
714 actionParams.userName, "Password", actionParams.password,
715 "Inserted", actionParams.inserted, "TransferMethod",
716 actionParams.transferMethod, "TransferProtocolType",
717 actionParams.transferProtocolType))
Ed Tanous96825be2022-06-03 09:43:38 -0700718 {
719 return;
720 }
721
George Liu2b731192023-01-11 16:27:13 +0800722 dbus::utility::getDbusObject(
723 "/xyz/openbmc_project/VirtualMedia", {},
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200724 [asyncResp, action, actionParams,
George Liu2b731192023-01-11 16:27:13 +0800725 resName](const boost::system::error_code& ec,
Ed Tanous96825be2022-06-03 09:43:38 -0700726 const dbus::utility::MapperGetObject& getObjectType) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400727 if (ec)
Ed Tanous96825be2022-06-03 09:43:38 -0700728 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400729 BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200730 messages::resourceNotFound(asyncResp->res, action, resName);
Ed Tanous96825be2022-06-03 09:43:38 -0700731
732 return;
733 }
Ed Tanous96825be2022-06-03 09:43:38 -0700734
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400735 std::string service = getObjectType.begin()->first;
736 BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
737
738 sdbusplus::message::object_path path(
739 "/xyz/openbmc_project/VirtualMedia");
740 dbus::utility::getManagedObjects(
741 service, path,
742 [service, resName, action, actionParams, asyncResp](
743 const boost::system::error_code& ec2,
744 const dbus::utility::ManagedObjectType& subtree) mutable {
745 if (ec2)
746 {
747 // Not possible in proxy mode
748 BMCWEB_LOG_DEBUG("InsertMedia not "
749 "allowed in proxy mode");
750 messages::resourceNotFound(asyncResp->res, action,
751 resName);
752
753 return;
754 }
755 for (const auto& object : subtree)
756 {
757 VmMode mode =
758 parseObjectPathAndGetMode(object.first, resName);
759 if (mode == VmMode::Legacy)
760 {
761 validateParams(asyncResp, service, resName,
762 actionParams);
763
764 return;
765 }
766 }
767 BMCWEB_LOG_DEBUG("Parent item not found");
768 messages::resourceNotFound(asyncResp->res, "VirtualMedia",
769 resName);
770 });
George Liu2b731192023-01-11 16:27:13 +0800771 });
Ed Tanous96825be2022-06-03 09:43:38 -0700772}
773
774inline void handleManagersVirtualMediaActionEject(
775 crow::App& app, const crow::Request& req,
776 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
777 const std::string& managerName, const std::string& resName)
778{
779 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
780 {
781 return;
782 }
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200783
784 constexpr std::string_view action = "VirtualMedia.EjectMedia";
Ed Tanous96825be2022-06-03 09:43:38 -0700785 if (managerName != "bmc")
786 {
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200787 messages::resourceNotFound(asyncResp->res, action, resName);
Ed Tanous96825be2022-06-03 09:43:38 -0700788
789 return;
790 }
791
George Liu2b731192023-01-11 16:27:13 +0800792 dbus::utility::getDbusObject(
793 "/xyz/openbmc_project/VirtualMedia", {},
Przemyslaw Czarnowski79fdf632022-06-28 18:11:59 +0200794 [asyncResp, action,
George Liu2b731192023-01-11 16:27:13 +0800795 resName](const boost::system::error_code& ec2,
Ed Tanous96825be2022-06-03 09:43:38 -0700796 const dbus::utility::MapperGetObject& getObjectType) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400797 if (ec2)
Ed Tanous96825be2022-06-03 09:43:38 -0700798 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400799 BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}",
800 ec2);
801 messages::internalError(asyncResp->res);
802
Ed Tanous96825be2022-06-03 09:43:38 -0700803 return;
804 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400805 std::string service = getObjectType.begin()->first;
806 BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
Ed Tanous96825be2022-06-03 09:43:38 -0700807
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400808 sdbusplus::message::object_path path(
809 "/xyz/openbmc_project/VirtualMedia");
810 dbus::utility::getManagedObjects(
811 service, path,
812 [resName, service, action,
813 asyncResp](const boost::system::error_code& ec,
814 const dbus::utility::ManagedObjectType& subtree) {
815 if (ec)
816 {
817 BMCWEB_LOG_ERROR("ObjectMapper : No Service found");
818 messages::resourceNotFound(asyncResp->res, action,
819 resName);
820 return;
821 }
822
823 for (const auto& object : subtree)
824 {
825 VmMode mode =
826 parseObjectPathAndGetMode(object.first, resName);
827 if (mode != VmMode::Invalid)
828 {
829 doEjectAction(asyncResp, service, resName,
830 mode == VmMode::Legacy);
831 return;
832 }
833 }
834 BMCWEB_LOG_DEBUG("Parent item not found");
835 messages::resourceNotFound(asyncResp->res, "VirtualMedia",
836 resName);
837 });
George Liu2b731192023-01-11 16:27:13 +0800838 });
Ed Tanous96825be2022-06-03 09:43:38 -0700839}
840
841inline void handleManagersVirtualMediaCollectionGet(
842 crow::App& app, const crow::Request& req,
843 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
844 const std::string& name)
845{
846 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
847 {
848 return;
849 }
850 if (name != "bmc")
851 {
852 messages::resourceNotFound(asyncResp->res, "VirtualMedia", name);
853
854 return;
855 }
856
857 asyncResp->res.jsonValue["@odata.type"] =
858 "#VirtualMediaCollection.VirtualMediaCollection";
859 asyncResp->res.jsonValue["Name"] = "Virtual Media Services";
Ed Tanousef4c65b2023-04-24 15:28:50 -0700860 asyncResp->res.jsonValue["@odata.id"] =
861 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", name);
Ed Tanous96825be2022-06-03 09:43:38 -0700862
George Liu2b731192023-01-11 16:27:13 +0800863 dbus::utility::getDbusObject(
864 "/xyz/openbmc_project/VirtualMedia", {},
865 [asyncResp, name](const boost::system::error_code& ec,
Ed Tanous96825be2022-06-03 09:43:38 -0700866 const dbus::utility::MapperGetObject& getObjectType) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400867 if (ec)
868 {
869 BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
870 messages::internalError(asyncResp->res);
Ed Tanous96825be2022-06-03 09:43:38 -0700871
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400872 return;
873 }
874 std::string service = getObjectType.begin()->first;
875 BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
Ed Tanous96825be2022-06-03 09:43:38 -0700876
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400877 getVmResourceList(asyncResp, service, name);
878 });
Ed Tanous96825be2022-06-03 09:43:38 -0700879}
880
881inline void
882 handleVirtualMediaGet(crow::App& app, const crow::Request& req,
883 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
884 const std::string& name, const std::string& resName)
885{
886 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
887 {
888 return;
889 }
890 if (name != "bmc")
891 {
892 messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
893
894 return;
895 }
896
George Liu2b731192023-01-11 16:27:13 +0800897 dbus::utility::getDbusObject(
898 "/xyz/openbmc_project/VirtualMedia", {},
Ed Tanous96825be2022-06-03 09:43:38 -0700899 [asyncResp, name,
George Liu2b731192023-01-11 16:27:13 +0800900 resName](const boost::system::error_code& ec,
Ed Tanous96825be2022-06-03 09:43:38 -0700901 const dbus::utility::MapperGetObject& getObjectType) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400902 if (ec)
903 {
904 BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
905 messages::internalError(asyncResp->res);
Ed Tanous96825be2022-06-03 09:43:38 -0700906
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400907 return;
908 }
909 std::string service = getObjectType.begin()->first;
910 BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
Ed Tanous96825be2022-06-03 09:43:38 -0700911
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400912 getVmData(asyncResp, service, name, resName);
913 });
Ed Tanous96825be2022-06-03 09:43:38 -0700914}
915
Ed Tanous22db1722021-06-09 10:53:51 -0700916inline void requestNBDVirtualMediaRoutes(App& app)
917{
George Liu0fda0f12021-11-16 10:06:17 +0800918 BMCWEB_ROUTE(
919 app,
920 "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.InsertMedia")
Ed Tanoused398212021-06-09 17:05:54 -0700921 .privileges(redfish::privileges::postVirtualMedia)
Ed Tanous96825be2022-06-03 09:43:38 -0700922 .methods(boost::beast::http::verb::post)(std::bind_front(
923 handleManagersVirtualMediaActionInsertPost, std::ref(app)));
Przemyslaw Czarnowskie13c2762019-09-02 17:32:43 +0200924
George Liu0fda0f12021-11-16 10:06:17 +0800925 BMCWEB_ROUTE(
926 app,
927 "/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
Ed Tanoused398212021-06-09 17:05:54 -0700928 .privileges(redfish::privileges::postVirtualMedia)
Ed Tanous96825be2022-06-03 09:43:38 -0700929 .methods(boost::beast::http::verb::post)(std::bind_front(
930 handleManagersVirtualMediaActionEject, std::ref(app)));
Ed Tanous002d39b2022-05-31 08:59:27 -0700931
Ed Tanous22db1722021-06-09 10:53:51 -0700932 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/")
Ed Tanoused398212021-06-09 17:05:54 -0700933 .privileges(redfish::privileges::getVirtualMediaCollection)
Ed Tanous96825be2022-06-03 09:43:38 -0700934 .methods(boost::beast::http::verb::get)(std::bind_front(
935 handleManagersVirtualMediaCollectionGet, std::ref(app)));
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200936
Ed Tanous22db1722021-06-09 10:53:51 -0700937 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/VirtualMedia/<str>/")
Ed Tanoused398212021-06-09 17:05:54 -0700938 .privileges(redfish::privileges::getVirtualMedia)
Ed Tanous22db1722021-06-09 10:53:51 -0700939 .methods(boost::beast::http::verb::get)(
Ed Tanous96825be2022-06-03 09:43:38 -0700940 std::bind_front(handleVirtualMediaGet, std::ref(app)));
Ed Tanous22db1722021-06-09 10:53:51 -0700941}
Przemyslaw Czarnowski107077d2019-07-11 10:16:43 +0200942
943} // namespace redfish