VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UICloudNetworkingStuff.cpp@ 102493

Last change on this file since 102493 was 100861, checked in by vboxsync, 13 months ago

FE/Qt: bugref:10500: Initial implementation for cloud VM clone functionality; This isn't working for now since ICloudMachine has only id, but not ocid property accessible.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.6 KB
Line 
1/* $Id: UICloudNetworkingStuff.cpp 100861 2023-08-11 15:38:01Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UICloudNetworkingStuff namespace implementation.
4 */
5
6/*
7 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* GUI includes: */
29#include "UICloudNetworkingStuff.h"
30#include "UICommon.h"
31#include "UIErrorString.h"
32#include "UIMessageCenter.h"
33
34/* COM includes: */
35#include "CAppliance.h"
36#include "CForm.h"
37#include "CProgress.h"
38#include "CStringArray.h"
39#include "CVirtualBox.h"
40#include "CVirtualBoxErrorInfo.h"
41#include "CVirtualSystemDescription.h"
42
43
44CCloudProviderManager UICloudNetworkingStuff::cloudProviderManager(UINotificationCenter *pParent /* = 0 */)
45{
46 /* Acquire VBox: */
47 const CVirtualBox comVBox = uiCommon().virtualBox();
48 if (comVBox.isNotNull())
49 {
50 /* Acquire cloud provider manager: */
51 CCloudProviderManager comProviderManager = comVBox.GetCloudProviderManager();
52 if (!comVBox.isOk())
53 UINotificationMessage::cannotAcquireVirtualBoxParameter(comVBox, pParent);
54 else
55 return comProviderManager;
56 }
57 /* Null by default: */
58 return CCloudProviderManager();
59}
60
61CCloudProviderManager UICloudNetworkingStuff::cloudProviderManager(QString &strErrorMessage)
62{
63 /* Acquire VBox: */
64 const CVirtualBox comVBox = uiCommon().virtualBox();
65 if (comVBox.isNotNull())
66 {
67 /* Acquire cloud provider manager: */
68 CCloudProviderManager comProviderManager = comVBox.GetCloudProviderManager();
69 if (!comVBox.isOk())
70 strErrorMessage = UIErrorString::formatErrorInfo(comVBox);
71 else
72 return comProviderManager;
73 }
74 /* Null by default: */
75 return CCloudProviderManager();
76}
77
78CCloudProvider UICloudNetworkingStuff::cloudProviderByShortName(const QString &strProviderShortName,
79 UINotificationCenter *pParent /* = 0 */)
80{
81 /* Acquire cloud provider manager: */
82 CCloudProviderManager comProviderManager = cloudProviderManager(pParent);
83 if (comProviderManager.isNotNull())
84 {
85 /* Acquire cloud provider: */
86 CCloudProvider comProvider = comProviderManager.GetProviderByShortName(strProviderShortName);
87 if (!comProviderManager.isOk())
88 UINotificationMessage::cannotAcquireCloudProviderManagerParameter(comProviderManager, pParent);
89 else
90 return comProvider;
91 }
92 /* Null by default: */
93 return CCloudProvider();
94}
95
96CCloudProvider UICloudNetworkingStuff::cloudProviderByShortName(const QString &strProviderShortName,
97 QString &strErrorMessage)
98{
99 /* Acquire cloud provider manager: */
100 CCloudProviderManager comProviderManager = cloudProviderManager(strErrorMessage);
101 if (comProviderManager.isNotNull())
102 {
103 /* Acquire cloud provider: */
104 CCloudProvider comProvider = comProviderManager.GetProviderByShortName(strProviderShortName);
105 if (!comProviderManager.isOk())
106 strErrorMessage = UIErrorString::formatErrorInfo(comProviderManager);
107 else
108 return comProvider;
109 }
110 /* Null by default: */
111 return CCloudProvider();
112}
113
114CCloudProfile UICloudNetworkingStuff::cloudProfileByName(const QString &strProviderShortName,
115 const QString &strProfileName,
116 UINotificationCenter *pParent /* = 0 */)
117{
118 /* Acquire cloud provider: */
119 CCloudProvider comProvider = cloudProviderByShortName(strProviderShortName, pParent);
120 if (comProvider.isNotNull())
121 {
122 /* Acquire cloud profile: */
123 CCloudProfile comProfile = comProvider.GetProfileByName(strProfileName);
124 if (!comProvider.isOk())
125 UINotificationMessage::cannotAcquireCloudProviderParameter(comProvider, pParent);
126 else
127 return comProfile;
128 }
129 /* Null by default: */
130 return CCloudProfile();
131}
132
133CCloudProfile UICloudNetworkingStuff::cloudProfileByName(const QString &strProviderShortName,
134 const QString &strProfileName,
135 QString &strErrorMessage)
136{
137 /* Acquire cloud provider: */
138 CCloudProvider comProvider = cloudProviderByShortName(strProviderShortName, strErrorMessage);
139 if (comProvider.isNotNull())
140 {
141 /* Acquire cloud profile: */
142 CCloudProfile comProfile = comProvider.GetProfileByName(strProfileName);
143 if (!comProvider.isOk())
144 strErrorMessage = UIErrorString::formatErrorInfo(comProvider);
145 else
146 return comProfile;
147 }
148 /* Null by default: */
149 return CCloudProfile();
150}
151
152CCloudClient UICloudNetworkingStuff::cloudClient(CCloudProfile comProfile,
153 UINotificationCenter *pParent /* = 0 */)
154{
155 /* Create cloud client: */
156 CCloudClient comClient = comProfile.CreateCloudClient();
157 if (!comProfile.isOk())
158 UINotificationMessage::cannotCreateCloudClient(comProfile, pParent);
159 else
160 return comClient;
161 /* Null by default: */
162 return CCloudClient();
163}
164
165CCloudClient UICloudNetworkingStuff::cloudClient(CCloudProfile comProfile,
166 QString &strErrorMessage)
167{
168 /* Create cloud client: */
169 CCloudClient comClient = comProfile.CreateCloudClient();
170 if (!comProfile.isOk())
171 strErrorMessage = UIErrorString::formatErrorInfo(comProfile);
172 else
173 return comClient;
174 /* Null by default: */
175 return CCloudClient();
176}
177
178CCloudClient UICloudNetworkingStuff::cloudClientByName(const QString &strProviderShortName,
179 const QString &strProfileName,
180 UINotificationCenter *pParent /* = 0 */)
181{
182 /* Acquire cloud profile: */
183 CCloudProfile comProfile = cloudProfileByName(strProviderShortName, strProfileName, pParent);
184 if (comProfile.isNotNull())
185 return cloudClient(comProfile, pParent);
186 /* Null by default: */
187 return CCloudClient();
188}
189
190CCloudClient UICloudNetworkingStuff::cloudClientByName(const QString &strProviderShortName,
191 const QString &strProfileName,
192 QString &strErrorMessage)
193{
194 /* Acquire cloud profile: */
195 CCloudProfile comProfile = cloudProfileByName(strProviderShortName, strProfileName, strErrorMessage);
196 if (comProfile.isNotNull())
197 return cloudClient(comProfile, strErrorMessage);
198 /* Null by default: */
199 return CCloudClient();
200}
201
202CVirtualSystemDescription UICloudNetworkingStuff::createVirtualSystemDescription(UINotificationCenter *pParent /* = 0 */)
203{
204 /* Acquire VBox: */
205 CVirtualBox comVBox = uiCommon().virtualBox();
206 if (comVBox.isNotNull())
207 {
208 /* Create appliance: */
209 CAppliance comAppliance = comVBox.CreateAppliance();
210 if (!comVBox.isOk())
211 UINotificationMessage::cannotCreateAppliance(comVBox, pParent);
212 else
213 {
214 /* Append it with one (1) description we need: */
215 comAppliance.CreateVirtualSystemDescriptions(1);
216 if (!comAppliance.isOk())
217 UINotificationMessage::cannotCreateVirtualSystemDescription(comAppliance, pParent);
218 else
219 {
220 /* Get received description: */
221 const QVector<CVirtualSystemDescription> descriptions = comAppliance.GetVirtualSystemDescriptions();
222 AssertReturn(!descriptions.isEmpty(), CVirtualSystemDescription());
223 return descriptions.at(0);
224 }
225 }
226 }
227 /* Null by default: */
228 return CVirtualSystemDescription();
229}
230
231QVector<CCloudProvider> UICloudNetworkingStuff::listCloudProviders(UINotificationCenter *pParent /* = 0 */)
232{
233 /* Acquire cloud provider manager: */
234 CCloudProviderManager comProviderManager = cloudProviderManager(pParent);
235 if (comProviderManager.isNotNull())
236 {
237 /* Acquire cloud providers: */
238 QVector<CCloudProvider> providers = comProviderManager.GetProviders();
239 if (!comProviderManager.isOk())
240 UINotificationMessage::cannotAcquireCloudProviderManagerParameter(comProviderManager, pParent);
241 else
242 return providers;
243 }
244 /* Return empty list by default: */
245 return QVector<CCloudProvider>();
246}
247
248bool UICloudNetworkingStuff::cloudProviderId(const CCloudProvider &comCloudProvider,
249 QUuid &uResult,
250 UINotificationCenter *pParent /* = 0 */)
251{
252 const QUuid uId = comCloudProvider.GetId();
253 if (!comCloudProvider.isOk())
254 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
255 else
256 {
257 uResult = uId;
258 return true;
259 }
260 return false;
261}
262
263bool UICloudNetworkingStuff::cloudProviderShortName(const CCloudProvider &comCloudProvider,
264 QString &strResult,
265 UINotificationCenter *pParent /* = 0 */)
266{
267 const QString strShortName = comCloudProvider.GetShortName();
268 if (!comCloudProvider.isOk())
269 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
270 else
271 {
272 strResult = strShortName;
273 return true;
274 }
275 return false;
276}
277
278bool UICloudNetworkingStuff::cloudProviderName(const CCloudProvider &comCloudProvider,
279 QString &strResult,
280 UINotificationCenter *pParent /* = 0 */)
281{
282 const QString strName = comCloudProvider.GetName();
283 if (!comCloudProvider.isOk())
284 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
285 else
286 {
287 strResult = strName;
288 return true;
289 }
290 return false;
291}
292
293QVector<CCloudProfile> UICloudNetworkingStuff::listCloudProfiles(const CCloudProvider &comCloudProvider,
294 UINotificationCenter *pParent /* = 0 */)
295{
296 /* Check cloud provider: */
297 if (comCloudProvider.isNotNull())
298 {
299 /* Acquire cloud providers: */
300 QVector<CCloudProfile> profiles = comCloudProvider.GetProfiles();
301 if (!comCloudProvider.isOk())
302 UINotificationMessage::cannotAcquireCloudProviderParameter(comCloudProvider, pParent);
303 else
304 return profiles;
305 }
306 /* Return empty list by default: */
307 return QVector<CCloudProfile>();
308}
309
310bool UICloudNetworkingStuff::cloudProfileName(const CCloudProfile &comCloudProfile,
311 QString &strResult,
312 UINotificationCenter *pParent /* = 0 */)
313{
314 const QString strName = comCloudProfile.GetName();
315 if (!comCloudProfile.isOk())
316 UINotificationMessage::cannotAcquireCloudProfileParameter(comCloudProfile, pParent);
317 else
318 {
319 strResult = strName;
320 return true;
321 }
322 return false;
323}
324
325bool UICloudNetworkingStuff::cloudProfileProperties(const CCloudProfile &comCloudProfile,
326 QVector<QString> &keys,
327 QVector<QString> &values,
328 UINotificationCenter *pParent /* = 0 */)
329{
330 QVector<QString> aKeys;
331 QVector<QString> aValues;
332 aValues = comCloudProfile.GetProperties(QString(), aKeys);
333 if (!comCloudProfile.isOk())
334 UINotificationMessage::cannotAcquireCloudProfileParameter(comCloudProfile, pParent);
335 else
336 {
337 aValues.resize(aKeys.size());
338 keys = aKeys;
339 values = aValues;
340 return true;
341 }
342 return false;
343}
344
345bool UICloudNetworkingStuff::listCloudImages(const CCloudClient &comCloudClient,
346 CStringArray &comNames,
347 CStringArray &comIDs,
348 UINotificationCenter *pParent)
349{
350 /* Currently we are interested in Available images only: */
351 const QVector<KCloudImageState> cloudImageStates = QVector<KCloudImageState>()
352 << KCloudImageState_Available;
353
354 /* List cloud images: */
355 UINotificationProgressCloudImageList *pNotification =
356 new UINotificationProgressCloudImageList(comCloudClient, cloudImageStates);
357 UINotificationReceiver receiver1;
358 UINotificationReceiver receiver2;
359 QObject::connect(pNotification, &UINotificationProgressCloudImageList::sigImageNamesReceived,
360 &receiver1, &UINotificationReceiver::setReceiverProperty);
361 QObject::connect(pNotification, &UINotificationProgressCloudImageList::sigImageIdsReceived,
362 &receiver2, &UINotificationReceiver::setReceiverProperty);
363 if (pParent->handleNow(pNotification))
364 {
365 comNames = receiver1.property("received_value").value<CStringArray>();
366 comIDs = receiver2.property("received_value").value<CStringArray>();
367 return true;
368 }
369
370 /* Return false by default: */
371 return false;
372}
373
374bool UICloudNetworkingStuff::listCloudSourceBootVolumes(const CCloudClient &comCloudClient,
375 CStringArray &comNames,
376 CStringArray &comIDs,
377 UINotificationCenter *pParent)
378{
379 /* List cloud source boot volumes: */
380 UINotificationProgressCloudSourceBootVolumeList *pNotification =
381 new UINotificationProgressCloudSourceBootVolumeList(comCloudClient);
382 UINotificationReceiver receiver1;
383 UINotificationReceiver receiver2;
384 QObject::connect(pNotification, &UINotificationProgressCloudSourceBootVolumeList::sigImageNamesReceived,
385 &receiver1, &UINotificationReceiver::setReceiverProperty);
386 QObject::connect(pNotification, &UINotificationProgressCloudSourceBootVolumeList::sigImageIdsReceived,
387 &receiver2, &UINotificationReceiver::setReceiverProperty);
388 if (pParent->handleNow(pNotification))
389 {
390 comNames = receiver1.property("received_value").value<CStringArray>();
391 comIDs = receiver2.property("received_value").value<CStringArray>();
392 return true;
393 }
394
395 /* Return false by default: */
396 return false;
397}
398
399bool UICloudNetworkingStuff::listCloudInstances(const CCloudClient &comCloudClient,
400 CStringArray &comNames,
401 CStringArray &comIDs,
402 UINotificationCenter *pParent)
403{
404 /* List cloud instances: */
405 UINotificationProgressCloudInstanceList *pNotification =
406 new UINotificationProgressCloudInstanceList(comCloudClient);
407 UINotificationReceiver receiver1;
408 UINotificationReceiver receiver2;
409 QObject::connect(pNotification, &UINotificationProgressCloudInstanceList::sigImageNamesReceived,
410 &receiver1, &UINotificationReceiver::setReceiverProperty);
411 QObject::connect(pNotification, &UINotificationProgressCloudInstanceList::sigImageIdsReceived,
412 &receiver2, &UINotificationReceiver::setReceiverProperty);
413 if (pParent->handleNow(pNotification))
414 {
415 comNames = receiver1.property("received_value").value<CStringArray>();
416 comIDs = receiver2.property("received_value").value<CStringArray>();
417 return true;
418 }
419
420 /* Return false by default: */
421 return false;
422}
423
424bool UICloudNetworkingStuff::listCloudSourceInstances(const CCloudClient &comCloudClient,
425 CStringArray &comNames,
426 CStringArray &comIDs,
427 UINotificationCenter *pParent)
428{
429 /* List cloud source instances: */
430 UINotificationProgressCloudSourceInstanceList *pNotification =
431 new UINotificationProgressCloudSourceInstanceList(comCloudClient);
432 UINotificationReceiver receiver1;
433 UINotificationReceiver receiver2;
434 QObject::connect(pNotification, &UINotificationProgressCloudSourceInstanceList::sigImageNamesReceived,
435 &receiver1, &UINotificationReceiver::setReceiverProperty);
436 QObject::connect(pNotification, &UINotificationProgressCloudSourceInstanceList::sigImageIdsReceived,
437 &receiver2, &UINotificationReceiver::setReceiverProperty);
438 if (pParent->handleNow(pNotification))
439 {
440 comNames = receiver1.property("received_value").value<CStringArray>();
441 comIDs = receiver2.property("received_value").value<CStringArray>();
442 return true;
443 }
444
445 /* Return false by default: */
446 return false;
447}
448
449bool UICloudNetworkingStuff::exportDescriptionForm(const CCloudClient &comCloudClient,
450 const CVirtualSystemDescription &comDescription,
451 CVirtualSystemDescriptionForm &comResult,
452 UINotificationCenter *pParent)
453{
454 /* Prepare export VSD form: */
455 UINotificationProgressExportVSDFormCreate *pNotification =
456 new UINotificationProgressExportVSDFormCreate(comCloudClient, comDescription);
457 UINotificationReceiver receiver;
458 QObject::connect(pNotification, &UINotificationProgressExportVSDFormCreate::sigVSDFormCreated,
459 &receiver, &UINotificationReceiver::setReceiverProperty);
460 if (pParent->handleNow(pNotification))
461 {
462 comResult = receiver.property("received_value").value<CVirtualSystemDescriptionForm>();
463 return true;
464 }
465
466 /* False by default: */
467 return false;
468}
469
470bool UICloudNetworkingStuff::importDescriptionForm(const CCloudClient &comCloudClient,
471 const CVirtualSystemDescription &comDescription,
472 CVirtualSystemDescriptionForm &comResult,
473 UINotificationCenter *pParent)
474{
475 /* Prepare import VSD form: */
476 UINotificationProgressImportVSDFormCreate *pNotification =
477 new UINotificationProgressImportVSDFormCreate(comCloudClient, comDescription);
478 UINotificationReceiver receiver;
479 QObject::connect(pNotification, &UINotificationProgressImportVSDFormCreate::sigVSDFormCreated,
480 &receiver, &UINotificationReceiver::setReceiverProperty);
481 if (pParent->handleNow(pNotification))
482 {
483 comResult = receiver.property("received_value").value<CVirtualSystemDescriptionForm>();
484 return true;
485 }
486
487 /* False by default: */
488 return false;
489}
490
491bool UICloudNetworkingStuff::cloudMachineId(const CCloudMachine &comCloudMachine,
492 QUuid &uResult,
493 UINotificationCenter *pParent /* = 0 */)
494{
495 const QUuid uId = comCloudMachine.GetId();
496 if (!comCloudMachine.isOk())
497 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
498 else
499 {
500 uResult = uId;
501 return true;
502 }
503 return false;
504}
505
506bool UICloudNetworkingStuff::cloudMachineName(const CCloudMachine &comCloudMachine,
507 QString &strResult,
508 UINotificationCenter *pParent /* = 0 */)
509{
510 const QString strName = comCloudMachine.GetName();
511 if (!comCloudMachine.isOk())
512 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
513 else
514 {
515 strResult = strName;
516 return true;
517 }
518 return false;
519}
520
521bool UICloudNetworkingStuff::cloudMachineConsoleConnectionFingerprint(const CCloudMachine &comCloudMachine,
522 QString &strResult,
523 UINotificationCenter *pParent /* = 0 */)
524{
525 const QString strConsoleConnectionFingerprint = comCloudMachine.GetConsoleConnectionFingerprint();
526 if (!comCloudMachine.isOk())
527 UINotificationMessage::cannotAcquireCloudMachineParameter(comCloudMachine, pParent);
528 else
529 {
530 strResult = strConsoleConnectionFingerprint;
531 return true;
532 }
533 return false;
534}
535
536bool UICloudNetworkingStuff::cloudMachineSettingsForm(const CCloudMachine &comCloudMachine,
537 CForm &comResult,
538 UINotificationCenter *pParent)
539{
540 /* Acquire machine name first: */
541 QString strMachineName;
542 if (!cloudMachineName(comCloudMachine, strMachineName))
543 return false;
544
545 /* Prepare VM settings form: */
546 UINotificationProgressCloudMachineSettingsFormCreate *pNotification =
547 new UINotificationProgressCloudMachineSettingsFormCreate(comCloudMachine, strMachineName);
548 UINotificationReceiver receiver;
549 QObject::connect(pNotification, &UINotificationProgressCloudMachineSettingsFormCreate::sigSettingsFormCreated,
550 &receiver, &UINotificationReceiver::setReceiverProperty);
551 if (pParent->handleNow(pNotification))
552 {
553 comResult = receiver.property("received_value").value<CForm>();
554 return true;
555 }
556
557 /* False by default: */
558 return false;
559}
560
561bool UICloudNetworkingStuff::cloudMachineSettingsForm(CCloudMachine comCloudMachine,
562 CForm &comResult,
563 QString &strErrorMessage)
564{
565 /* Prepare settings form: */
566 CForm comForm;
567
568 /* Now execute GetSettingsForm async method: */
569 CProgress comProgress = comCloudMachine.GetSettingsForm(comForm);
570 if (!comCloudMachine.isOk())
571 {
572 strErrorMessage = UIErrorString::formatErrorInfo(comCloudMachine);
573 return false;
574 }
575
576 /* Wait for "Get settings form" progress: */
577 comProgress.WaitForCompletion(-1);
578 if (comProgress.GetCanceled())
579 return false;
580 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
581 {
582 strErrorMessage = UIErrorString::formatErrorInfo(comProgress);
583 return false;
584 }
585
586 /* Return result: */
587 comResult = comForm;
588 return true;
589}
590
591bool UICloudNetworkingStuff::applyCloudMachineSettingsForm(const CCloudMachine &comCloudMachine,
592 const CForm &comForm,
593 UINotificationCenter *pParent)
594{
595 /* Acquire machine name first: */
596 QString strMachineName;
597 if (!cloudMachineName(comCloudMachine, strMachineName))
598 return false;
599
600 /* Apply VM settings form: */
601 UINotificationProgressCloudMachineSettingsFormApply *pNotification =
602 new UINotificationProgressCloudMachineSettingsFormApply(comForm, strMachineName);
603 return pParent->handleNow(pNotification);
604}
605
606void UICloudNetworkingStuff::createCloudMachineClone(const QString &strProviderShortName,
607 const QString &strProfileName,
608 const CCloudMachine &comCloudMachine,
609 const QString &strCloneName,
610 UINotificationCenter *pParent)
611{
612 /* Create cloud client: */
613 CCloudClient comCloudClient = cloudClientByName(strProviderShortName,
614 strProfileName,
615 pParent);
616 if (comCloudClient.isNotNull())
617 {
618 /* Clone specified cloud machine asynchronously: */
619 UINotificationProgressCloudMachineClone *pNotification =
620 new UINotificationProgressCloudMachineClone(comCloudClient, comCloudMachine, strCloneName);
621 pParent->append(pNotification);
622 }
623}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use