VirtualBox

source: vbox/trunk/src/VBox/Main/ApplianceImpl.cpp@ 21660

Last change on this file since 21660 was 21622, checked in by vboxsync, 15 years ago

Main: cleanup: merge VirtualBoxBase{WithTypedChildren}NEXT onto VirtualBoxBase{WithTypedChildren}, adjust Host and Snapshot implementations according to new parents (new locking scheme)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 182.8 KB
Line 
1/* $Id: ApplianceImpl.cpp 21622 2009-07-15 19:04:07Z vboxsync $ */
2/** @file
3 *
4 * IAppliance and IVirtualSystem COM class implementations.
5 */
6
7/*
8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#include <iprt/stream.h>
24#include <iprt/path.h>
25#include <iprt/dir.h>
26#include <iprt/file.h>
27#include <iprt/s3.h>
28
29#include "ovfreader.h"
30
31#include <VBox/param.h>
32#include <VBox/version.h>
33
34#include "ApplianceImpl.h"
35#include "VFSExplorerImpl.h"
36#include "VirtualBoxImpl.h"
37#include "GuestOSTypeImpl.h"
38#include "ProgressImpl.h"
39#include "MachineImpl.h"
40#include "HostNetworkInterfaceImpl.h"
41
42#include "Logging.h"
43
44using namespace std;
45
46////////////////////////////////////////////////////////////////////////////////
47//
48// Appliance data definition
49//
50////////////////////////////////////////////////////////////////////////////////
51
52/* Describe a location for the import/export. The location could be a file on a
53 * local hard disk or a remote target based on the supported inet protocols. */
54struct Appliance::LocationInfo
55{
56 LocationInfo()
57 : storageType(VFSType_File) {}
58 VFSType_T storageType; /* Which type of storage should be handled */
59 Utf8Str strPath; /* File path for the import/export */
60 Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
61 Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
62 Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
63};
64
65// opaque private instance data of Appliance class
66struct Appliance::Data
67{
68 Data()
69 : pReader(NULL) {}
70
71 ~Data()
72 {
73 if (pReader)
74 {
75 delete pReader;
76 pReader = NULL;
77 }
78 }
79
80 LocationInfo locInfo; /* The location info for the currently processed OVF */
81
82 OVFReader *pReader;
83
84 list< ComObjPtr<VirtualSystemDescription> > virtualSystemDescriptions;
85
86 list<Utf8Str> llWarnings;
87
88 ULONG ulWeightPerOperation;
89};
90
91struct VirtualSystemDescription::Data
92{
93 list<VirtualSystemDescriptionEntry> llDescriptions;
94};
95
96////////////////////////////////////////////////////////////////////////////////
97//
98// internal helpers
99//
100////////////////////////////////////////////////////////////////////////////////
101
102static const struct
103{
104 CIMOSType_T cim;
105 const char *pcszVbox;
106}
107g_osTypes[] =
108{
109 { CIMOSType_CIMOS_Unknown, SchemaDefs_OSTypeId_Other },
110 { CIMOSType_CIMOS_OS2, SchemaDefs_OSTypeId_OS2 },
111 { CIMOSType_CIMOS_MSDOS, SchemaDefs_OSTypeId_DOS },
112 { CIMOSType_CIMOS_WIN3x, SchemaDefs_OSTypeId_Windows31 },
113 { CIMOSType_CIMOS_WIN95, SchemaDefs_OSTypeId_Windows95 },
114 { CIMOSType_CIMOS_WIN98, SchemaDefs_OSTypeId_Windows98 },
115 { CIMOSType_CIMOS_WINNT, SchemaDefs_OSTypeId_WindowsNT4 },
116 { CIMOSType_CIMOS_NetWare, SchemaDefs_OSTypeId_Netware },
117 { CIMOSType_CIMOS_NovellOES, SchemaDefs_OSTypeId_Netware },
118 { CIMOSType_CIMOS_Solaris, SchemaDefs_OSTypeId_OpenSolaris },
119 { CIMOSType_CIMOS_SunOS, SchemaDefs_OSTypeId_OpenSolaris },
120 { CIMOSType_CIMOS_FreeBSD, SchemaDefs_OSTypeId_FreeBSD },
121 { CIMOSType_CIMOS_NetBSD, SchemaDefs_OSTypeId_NetBSD },
122 { CIMOSType_CIMOS_QNX, SchemaDefs_OSTypeId_QNX },
123 { CIMOSType_CIMOS_Windows2000, SchemaDefs_OSTypeId_Windows2000 },
124 { CIMOSType_CIMOS_WindowsMe, SchemaDefs_OSTypeId_WindowsMe },
125 { CIMOSType_CIMOS_OpenBSD, SchemaDefs_OSTypeId_OpenBSD },
126 { CIMOSType_CIMOS_WindowsXP, SchemaDefs_OSTypeId_WindowsXP },
127 { CIMOSType_CIMOS_WindowsXPEmbedded, SchemaDefs_OSTypeId_WindowsXP },
128 { CIMOSType_CIMOS_WindowsEmbeddedforPointofService, SchemaDefs_OSTypeId_WindowsXP },
129 { CIMOSType_CIMOS_MicrosoftWindowsServer2003, SchemaDefs_OSTypeId_Windows2003 },
130 { CIMOSType_CIMOS_MicrosoftWindowsServer2003_64, SchemaDefs_OSTypeId_Windows2003_64 },
131 { CIMOSType_CIMOS_WindowsXP_64, SchemaDefs_OSTypeId_WindowsXP_64 },
132 { CIMOSType_CIMOS_WindowsVista, SchemaDefs_OSTypeId_WindowsVista },
133 { CIMOSType_CIMOS_WindowsVista_64, SchemaDefs_OSTypeId_WindowsVista_64 },
134 { CIMOSType_CIMOS_MicrosoftWindowsServer2008, SchemaDefs_OSTypeId_Windows2008 },
135 { CIMOSType_CIMOS_MicrosoftWindowsServer2008_64, SchemaDefs_OSTypeId_Windows2008_64 },
136 { CIMOSType_CIMOS_FreeBSD_64, SchemaDefs_OSTypeId_FreeBSD_64 },
137 { CIMOSType_CIMOS_RedHatEnterpriseLinux, SchemaDefs_OSTypeId_RedHat },
138 { CIMOSType_CIMOS_RedHatEnterpriseLinux_64, SchemaDefs_OSTypeId_RedHat_64 },
139 { CIMOSType_CIMOS_Solaris_64, SchemaDefs_OSTypeId_OpenSolaris_64 },
140 { CIMOSType_CIMOS_SUSE, SchemaDefs_OSTypeId_OpenSUSE },
141 { CIMOSType_CIMOS_SLES, SchemaDefs_OSTypeId_OpenSUSE },
142 { CIMOSType_CIMOS_NovellLinuxDesktop, SchemaDefs_OSTypeId_OpenSUSE },
143 { CIMOSType_CIMOS_SUSE_64, SchemaDefs_OSTypeId_OpenSUSE_64 },
144 { CIMOSType_CIMOS_SLES_64, SchemaDefs_OSTypeId_OpenSUSE_64 },
145 { CIMOSType_CIMOS_LINUX, SchemaDefs_OSTypeId_Linux },
146 { CIMOSType_CIMOS_SunJavaDesktopSystem, SchemaDefs_OSTypeId_Linux },
147 { CIMOSType_CIMOS_TurboLinux, SchemaDefs_OSTypeId_Linux},
148
149 // { CIMOSType_CIMOS_TurboLinux_64, },
150
151 { CIMOSType_CIMOS_Mandriva, SchemaDefs_OSTypeId_Mandriva },
152 { CIMOSType_CIMOS_Mandriva_64, SchemaDefs_OSTypeId_Mandriva_64 },
153 { CIMOSType_CIMOS_Ubuntu, SchemaDefs_OSTypeId_Ubuntu },
154 { CIMOSType_CIMOS_Ubuntu_64, SchemaDefs_OSTypeId_Ubuntu_64 },
155 { CIMOSType_CIMOS_Debian, SchemaDefs_OSTypeId_Debian },
156 { CIMOSType_CIMOS_Debian_64, SchemaDefs_OSTypeId_Debian_64 },
157 { CIMOSType_CIMOS_Linux_2_4_x, SchemaDefs_OSTypeId_Linux24 },
158 { CIMOSType_CIMOS_Linux_2_4_x_64, SchemaDefs_OSTypeId_Linux24_64 },
159 { CIMOSType_CIMOS_Linux_2_6_x, SchemaDefs_OSTypeId_Linux26 },
160 { CIMOSType_CIMOS_Linux_2_6_x_64, SchemaDefs_OSTypeId_Linux26_64 },
161 { CIMOSType_CIMOS_Linux_64, SchemaDefs_OSTypeId_Linux26_64 }
162};
163
164/* Pattern structure for matching the OS type description field */
165struct osTypePattern
166{
167 const char *pcszPattern;
168 const char *pcszVbox;
169};
170
171/* These are the 32-Bit ones. They are sorted by priority. */
172static const osTypePattern g_osTypesPattern[] =
173{
174 {"Windows NT", SchemaDefs_OSTypeId_WindowsNT4},
175 {"Windows XP", SchemaDefs_OSTypeId_WindowsXP},
176 {"Windows 2000", SchemaDefs_OSTypeId_Windows2000},
177 {"Windows 2003", SchemaDefs_OSTypeId_Windows2003},
178 {"Windows Vista", SchemaDefs_OSTypeId_WindowsVista},
179 {"Windows 2008", SchemaDefs_OSTypeId_Windows2008},
180 {"SUSE", SchemaDefs_OSTypeId_OpenSUSE},
181 {"Novell", SchemaDefs_OSTypeId_OpenSUSE},
182 {"Red Hat", SchemaDefs_OSTypeId_RedHat},
183 {"Mandriva", SchemaDefs_OSTypeId_Mandriva},
184 {"Ubuntu", SchemaDefs_OSTypeId_Ubuntu},
185 {"Debian", SchemaDefs_OSTypeId_Debian},
186 {"QNX", SchemaDefs_OSTypeId_QNX},
187 {"Linux 2.4", SchemaDefs_OSTypeId_Linux24},
188 {"Linux 2.6", SchemaDefs_OSTypeId_Linux26},
189 {"Linux", SchemaDefs_OSTypeId_Linux},
190 {"OpenSolaris", SchemaDefs_OSTypeId_OpenSolaris},
191 {"Solaris", SchemaDefs_OSTypeId_OpenSolaris},
192 {"FreeBSD", SchemaDefs_OSTypeId_FreeBSD},
193 {"NetBSD", SchemaDefs_OSTypeId_NetBSD},
194 {"Windows 95", SchemaDefs_OSTypeId_Windows95},
195 {"Windows 98", SchemaDefs_OSTypeId_Windows98},
196 {"Windows Me", SchemaDefs_OSTypeId_WindowsMe},
197 {"Windows 3.", SchemaDefs_OSTypeId_Windows31},
198 {"DOS", SchemaDefs_OSTypeId_DOS},
199 {"OS2", SchemaDefs_OSTypeId_OS2}
200};
201
202/* These are the 64-Bit ones. They are sorted by priority. */
203static const osTypePattern g_osTypesPattern64[] =
204{
205 {"Windows XP", SchemaDefs_OSTypeId_WindowsXP_64},
206 {"Windows 2003", SchemaDefs_OSTypeId_Windows2003_64},
207 {"Windows Vista", SchemaDefs_OSTypeId_WindowsVista_64},
208 {"Windows 2008", SchemaDefs_OSTypeId_Windows2008_64},
209 {"SUSE", SchemaDefs_OSTypeId_OpenSUSE_64},
210 {"Novell", SchemaDefs_OSTypeId_OpenSUSE_64},
211 {"Red Hat", SchemaDefs_OSTypeId_RedHat_64},
212 {"Mandriva", SchemaDefs_OSTypeId_Mandriva_64},
213 {"Ubuntu", SchemaDefs_OSTypeId_Ubuntu_64},
214 {"Debian", SchemaDefs_OSTypeId_Debian_64},
215 {"Linux 2.4", SchemaDefs_OSTypeId_Linux24_64},
216 {"Linux 2.6", SchemaDefs_OSTypeId_Linux26_64},
217 {"Linux", SchemaDefs_OSTypeId_Linux26_64},
218 {"OpenSolaris", SchemaDefs_OSTypeId_OpenSolaris_64},
219 {"Solaris", SchemaDefs_OSTypeId_OpenSolaris_64},
220 {"FreeBSD", SchemaDefs_OSTypeId_FreeBSD_64},
221};
222
223/**
224 * Private helper func that suggests a VirtualBox guest OS type
225 * for the given OVF operating system type.
226 * @param osTypeVBox
227 * @param c
228 * @param cStr
229 */
230static void convertCIMOSType2VBoxOSType(Utf8Str &strType, CIMOSType_T c, const Utf8Str &cStr)
231{
232 /* First check if the type is other/other_64 */
233 if (c == CIMOSType_CIMOS_Other)
234 {
235 for (size_t i=0; i < RT_ELEMENTS(g_osTypesPattern); ++i)
236 if (cStr.contains (g_osTypesPattern[i].pcszPattern, Utf8Str::CaseInsensitive))
237 {
238 strType = g_osTypesPattern[i].pcszVbox;
239 return;
240 }
241 }
242 else if (c == CIMOSType_CIMOS_Other_64)
243 {
244 for (size_t i=0; i < RT_ELEMENTS(g_osTypesPattern64); ++i)
245 if (cStr.contains (g_osTypesPattern64[i].pcszPattern, Utf8Str::CaseInsensitive))
246 {
247 strType = g_osTypesPattern64[i].pcszVbox;
248 return;
249 }
250 }
251
252 for (size_t i = 0; i < RT_ELEMENTS(g_osTypes); ++i)
253 {
254 if (c == g_osTypes[i].cim)
255 {
256 strType = g_osTypes[i].pcszVbox;
257 return;
258 }
259 }
260
261 strType = SchemaDefs_OSTypeId_Other;
262}
263
264/**
265 * Private helper func that suggests a VirtualBox guest OS type
266 * for the given OVF operating system type.
267 * @param osTypeVBox
268 * @param c
269 */
270static CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVbox)
271{
272 for (size_t i = 0; i < RT_ELEMENTS(g_osTypes); ++i)
273 {
274 if (!RTStrICmp(pcszVbox, g_osTypes[i].pcszVbox))
275 return g_osTypes[i].cim;
276 }
277
278 return CIMOSType_CIMOS_Other;
279}
280
281////////////////////////////////////////////////////////////////////////////////
282//
283// IVirtualBox public methods
284//
285////////////////////////////////////////////////////////////////////////////////
286
287// This code is here so we won't have to include the appliance headers in the
288// IVirtualBox implementation.
289
290/**
291 * Implementation for IVirtualBox::createAppliance.
292 *
293 * @param anAppliance IAppliance object created if S_OK is returned.
294 * @return S_OK or error.
295 */
296STDMETHODIMP VirtualBox::CreateAppliance(IAppliance** anAppliance)
297{
298 HRESULT rc;
299
300 ComObjPtr<Appliance> appliance;
301 appliance.createObject();
302 rc = appliance->init(this);
303
304 if (SUCCEEDED(rc))
305 appliance.queryInterfaceTo(anAppliance);
306
307 return rc;
308}
309
310////////////////////////////////////////////////////////////////////////////////
311//
312// Appliance constructor / destructor
313//
314////////////////////////////////////////////////////////////////////////////////
315
316DEFINE_EMPTY_CTOR_DTOR(Appliance)
317
318/**
319 * Appliance COM initializer.
320 * @param
321 * @return
322 */
323HRESULT Appliance::init(VirtualBox *aVirtualBox)
324{
325 /* Enclose the state transition NotReady->InInit->Ready */
326 AutoInitSpan autoInitSpan(this);
327 AssertReturn(autoInitSpan.isOk(), E_FAIL);
328
329 /* Weak reference to a VirtualBox object */
330 unconst(mVirtualBox) = aVirtualBox;
331
332 // initialize data
333 m = new Data;
334
335 /* Confirm a successful initialization */
336 autoInitSpan.setSucceeded();
337
338 return S_OK;
339}
340
341/**
342 * Appliance COM uninitializer.
343 * @return
344 */
345void Appliance::uninit()
346{
347 /* Enclose the state transition Ready->InUninit->NotReady */
348 AutoUninitSpan autoUninitSpan (this);
349 if (autoUninitSpan.uninitDone())
350 return;
351
352 delete m;
353 m = NULL;
354}
355
356////////////////////////////////////////////////////////////////////////////////
357//
358// Appliance private methods
359//
360////////////////////////////////////////////////////////////////////////////////
361
362HRESULT Appliance::searchUniqueVMName(Utf8Str& aName) const
363{
364 IMachine *machine = NULL;
365 char *tmpName = RTStrDup(aName.c_str());
366 int i = 1;
367 /* @todo: Maybe too cost-intensive; try to find a lighter way */
368 while (mVirtualBox->FindMachine(Bstr(tmpName), &machine) != VBOX_E_OBJECT_NOT_FOUND)
369 {
370 RTStrFree(tmpName);
371 RTStrAPrintf(&tmpName, "%s_%d", aName.c_str(), i);
372 ++i;
373 }
374 aName = tmpName;
375 RTStrFree(tmpName);
376
377 return S_OK;
378}
379
380HRESULT Appliance::searchUniqueDiskImageFilePath(Utf8Str& aName) const
381{
382 IHardDisk *harddisk = NULL;
383 char *tmpName = RTStrDup(aName.c_str());
384 int i = 1;
385 /* Check if the file exists or if a file with this path is registered
386 * already */
387 /* @todo: Maybe too cost-intensive; try to find a lighter way */
388 while (RTPathExists(tmpName) ||
389 mVirtualBox->FindHardDisk(Bstr(tmpName), &harddisk) != VBOX_E_OBJECT_NOT_FOUND)
390 {
391 RTStrFree(tmpName);
392 char *tmpDir = RTStrDup(aName.c_str());
393 RTPathStripFilename(tmpDir);;
394 char *tmpFile = RTStrDup(RTPathFilename(aName.c_str()));
395 RTPathStripExt(tmpFile);
396 const char *tmpExt = RTPathExt(aName.c_str());
397 RTStrAPrintf(&tmpName, "%s%c%s_%d%s", tmpDir, RTPATH_DELIMITER, tmpFile, i, tmpExt);
398 RTStrFree(tmpFile);
399 RTStrFree(tmpDir);
400 ++i;
401 }
402 aName = tmpName;
403 RTStrFree(tmpName);
404
405 return S_OK;
406}
407
408/**
409 * Called from the import and export background threads to synchronize the second
410 * background disk thread's progress object with the current progress object so
411 * that the user interface sees progress correctly and that cancel signals are
412 * passed on to the second thread.
413 * @param pProgressThis Progress object of the current thread.
414 * @param pProgressAsync Progress object of asynchronous task running in background.
415 */
416void Appliance::waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis,
417 ComPtr<IProgress> &pProgressAsync)
418{
419 HRESULT rc;
420
421 // now loop until the asynchronous operation completes and then report its result
422 BOOL fCompleted;
423 BOOL fCanceled;
424 ULONG currentPercent;
425 while (SUCCEEDED(pProgressAsync->COMGETTER(Completed(&fCompleted))))
426 {
427 rc = pProgressThis->COMGETTER(Canceled)(&fCanceled);
428 if (FAILED(rc)) throw rc;
429 if (fCanceled)
430 {
431 pProgressAsync->Cancel();
432 break;
433 }
434
435 rc = pProgressAsync->COMGETTER(Percent(&currentPercent));
436 if (FAILED(rc)) throw rc;
437 if (!pProgressThis.isNull())
438 pProgressThis->setCurrentOperationProgress(currentPercent);
439 if (fCompleted)
440 break;
441
442 /* Make sure the loop is not too tight */
443 rc = pProgressAsync->WaitForCompletion(100);
444 if (FAILED(rc)) throw rc;
445 }
446 // report result of asynchronous operation
447 LONG iRc;
448 rc = pProgressAsync->COMGETTER(ResultCode)(&iRc);
449 if (FAILED(rc)) throw rc;
450
451
452 // if the thread of the progress object has an error, then
453 // retrieve the error info from there, or it'll be lost
454 if (FAILED(iRc))
455 {
456 ProgressErrorInfo info(pProgressAsync);
457 Utf8Str str(info.getText());
458 const char *pcsz = str.c_str();
459 HRESULT rc2 = setError(iRc, pcsz);
460 throw rc2;
461 }
462}
463
464void Appliance::addWarning(const char* aWarning, ...)
465{
466 va_list args;
467 va_start(args, aWarning);
468 Utf8StrFmtVA str(aWarning, args);
469 va_end(args);
470 m->llWarnings.push_back(str);
471}
472
473void Appliance::disksWeight(uint32_t &ulTotalMB, uint32_t &cDisks) const
474{
475 ulTotalMB = 0;
476 cDisks = 0;
477 /* Weigh the disk images according to their sizes */
478 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
479 for (it = m->virtualSystemDescriptions.begin();
480 it != m->virtualSystemDescriptions.end();
481 ++it)
482 {
483 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
484 /* One for every hard disk of the Virtual System */
485 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
486 std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
487 for (itH = avsdeHDs.begin();
488 itH != avsdeHDs.end();
489 ++itH)
490 {
491 const VirtualSystemDescriptionEntry *pHD = *itH;
492 ulTotalMB += pHD->ulSizeMB;
493 ++cDisks;
494 }
495 }
496
497}
498
499HRESULT Appliance::setUpProgressFS(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
500{
501 HRESULT rc;
502
503 /* Create the progress object */
504 pProgress.createObject();
505
506 /* Weigh the disk images according to their sizes */
507 uint32_t ulTotalMB;
508 uint32_t cDisks;
509 disksWeight(ulTotalMB, cDisks);
510
511 ULONG cOperations = 1 + cDisks; // one op per disk plus 1 for the XML
512
513 ULONG ulTotalOperationsWeight;
514 if (ulTotalMB)
515 {
516 m->ulWeightPerOperation = (ULONG)((double)ulTotalMB * 1 / 100); // use 1% of the progress for the XML
517 ulTotalOperationsWeight = ulTotalMB + m->ulWeightPerOperation;
518 }
519 else
520 {
521 // no disks to export:
522 ulTotalOperationsWeight = 1;
523 m->ulWeightPerOperation = 1;
524 }
525
526 Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
527 ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
528
529 rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
530 bstrDescription,
531 TRUE /* aCancelable */,
532 cOperations, // ULONG cOperations,
533 ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
534 bstrDescription, // CBSTR bstrFirstOperationDescription,
535 m->ulWeightPerOperation); // ULONG ulFirstOperationWeight,
536 return rc;
537}
538
539HRESULT Appliance::setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
540{
541 HRESULT rc;
542
543 /* Create the progress object */
544 pProgress.createObject();
545
546 /* Weigh the disk images according to their sizes */
547 uint32_t ulTotalMB;
548 uint32_t cDisks;
549 disksWeight(ulTotalMB, cDisks);
550
551 ULONG cOperations = 1 + 1 + cDisks; // one op per disk plus 1 for init & 1 plus for the import */
552
553 ULONG ulTotalOperationsWeight = ulTotalMB;
554 if (!ulTotalOperationsWeight)
555 // no disks to export:
556 ulTotalOperationsWeight = 1;
557
558 ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50 / 100); // use 50% for import
559 ulTotalOperationsWeight += ulImportWeight;
560
561 m->ulWeightPerOperation = ulImportWeight; /* save for using later */
562
563 ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1 / 100); // use 0.1% for init
564 ulTotalOperationsWeight += ulInitWeight;
565
566 Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
567 ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
568
569 rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
570 bstrDescription,
571 TRUE /* aCancelable */,
572 cOperations, // ULONG cOperations,
573 ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
574 Bstr(tr("Init")), // CBSTR bstrFirstOperationDescription,
575 ulInitWeight); // ULONG ulFirstOperationWeight,
576 return rc;
577}
578
579HRESULT Appliance::setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
580{
581 HRESULT rc;
582
583 /* Create the progress object */
584 pProgress.createObject();
585
586 /* Weigh the disk images according to their sizes */
587 uint32_t ulTotalMB;
588 uint32_t cDisks;
589 disksWeight(ulTotalMB, cDisks);
590
591 ULONG cOperations = 1 + 1 + cDisks; // one op per disk plus 1 for the OVF & 1 plus to the temporary creation */
592
593 ULONG ulTotalOperationsWeight;
594 if (ulTotalMB)
595 {
596 m->ulWeightPerOperation = (ULONG)((double)ulTotalMB * 1 / 100); // use 1% of the progress for OVF file upload (we didn't know the size at this point)
597 ulTotalOperationsWeight = ulTotalMB + m->ulWeightPerOperation;
598 }
599 else
600 {
601 // no disks to export:
602 ulTotalOperationsWeight = 1;
603 m->ulWeightPerOperation = 1;
604 }
605 ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
606 ulTotalOperationsWeight += ulOVFCreationWeight;
607
608 Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
609 ulTotalMB, cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightPerOperation));
610
611 rc = pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
612 bstrDescription,
613 TRUE /* aCancelable */,
614 cOperations, // ULONG cOperations,
615 ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
616 bstrDescription, // CBSTR bstrFirstOperationDescription,
617 ulOVFCreationWeight); // ULONG ulFirstOperationWeight,
618 return rc;
619}
620
621void Appliance::parseURI(Utf8Str strUri, LocationInfo &locInfo) const
622{
623 /* Check the URI for the protocol */
624 if (strUri.startsWith("file://", Utf8Str::CaseInsensitive)) /* File based */
625 {
626 locInfo.storageType = VFSType_File;
627 strUri = strUri.substr(sizeof("file://") - 1);
628 }
629 else if (strUri.startsWith("SunCloud://", Utf8Str::CaseInsensitive)) /* Sun Cloud service */
630 {
631 locInfo.storageType = VFSType_S3;
632 strUri = strUri.substr(sizeof("SunCloud://") - 1);
633 }
634 else if (strUri.startsWith("S3://", Utf8Str::CaseInsensitive)) /* S3 service */
635 {
636 locInfo.storageType = VFSType_S3;
637 strUri = strUri.substr(sizeof("S3://") - 1);
638 }
639 else if (strUri.startsWith("webdav://", Utf8Str::CaseInsensitive)) /* webdav service */
640 throw E_NOTIMPL;
641
642 /* Not necessary on a file based URI */
643 if (locInfo.storageType != VFSType_File)
644 {
645 size_t uppos = strUri.find("@"); /* username:password combo */
646 if (uppos != Utf8Str::npos)
647 {
648 locInfo.strUsername = strUri.substr(0, uppos);
649 strUri = strUri.substr(uppos + 1);
650 size_t upos = locInfo.strUsername.find(":");
651 if (upos != Utf8Str::npos)
652 {
653 locInfo.strPassword = locInfo.strUsername.substr(upos + 1);
654 locInfo.strUsername = locInfo.strUsername.substr(0, upos);
655 }
656 }
657 size_t hpos = strUri.find("/"); /* hostname part */
658 if (hpos != Utf8Str::npos)
659 {
660 locInfo.strHostname = strUri.substr(0, hpos);
661 strUri = strUri.substr(hpos);
662 }
663 }
664
665 locInfo.strPath = strUri;
666}
667
668void Appliance::parseBucket(Utf8Str &aPath, Utf8Str &aBucket) const
669{
670 /* Buckets are S3 specific. So parse the bucket out of the file path */
671 if (!aPath.startsWith("/"))
672 throw setError(E_INVALIDARG,
673 tr("The path '%s' must start with /"), aPath.c_str());
674 size_t bpos = aPath.find("/", 1);
675 if (bpos != Utf8Str::npos)
676 {
677 aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */
678 aPath = aPath.substr(bpos); /* The rest of the file path */
679 }
680 /* If there is no bucket name provided reject it */
681 if (aBucket.isEmpty())
682 throw setError(E_INVALIDARG,
683 tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str());
684}
685
686struct Appliance::TaskOVF
687{
688 TaskOVF(Appliance *aThat)
689 : pAppliance(aThat)
690 , rc(S_OK) {}
691
692 static int updateProgress(unsigned uPercent, void *pvUser);
693
694 LocationInfo locInfo;
695 Appliance *pAppliance;
696 ComObjPtr<Progress> progress;
697 HRESULT rc;
698};
699
700struct Appliance::TaskImportOVF: Appliance::TaskOVF
701{
702 enum TaskType
703 {
704 Read,
705 Import
706 };
707
708 TaskImportOVF(Appliance *aThat)
709 : TaskOVF(aThat)
710 , taskType(Read) {}
711
712 int startThread();
713
714 TaskType taskType;
715};
716
717struct Appliance::TaskExportOVF: Appliance::TaskOVF
718{
719 enum OVFFormat
720 {
721 unspecified,
722 OVF_0_9,
723 OVF_1_0
724 };
725 enum TaskType
726 {
727 Write
728 };
729
730 TaskExportOVF(Appliance *aThat)
731 : TaskOVF(aThat)
732 , taskType(Write) {}
733
734 int startThread();
735
736 TaskType taskType;
737 OVFFormat enFormat;
738};
739
740struct MyHardDiskAttachment
741{
742 Guid uuid;
743 ComPtr<IMachine> pMachine;
744 Bstr controllerType;
745 int32_t lChannel;
746 int32_t lDevice;
747};
748
749/* static */
750int Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)
751{
752 Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser;
753
754 if (pTask &&
755 !pTask->progress.isNull())
756 {
757 BOOL fCanceled;
758 pTask->progress->COMGETTER(Canceled)(&fCanceled);
759 if (fCanceled)
760 return -1;
761 pTask->progress->setCurrentOperationProgress(uPercent);
762 }
763 return VINF_SUCCESS;
764}
765
766HRESULT Appliance::readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
767{
768 /* Initialize our worker task */
769 std::auto_ptr<TaskImportOVF> task(new TaskImportOVF(this));
770 /* What should the task do */
771 task->taskType = TaskImportOVF::Read;
772 /* Copy the current location info to the task */
773 task->locInfo = aLocInfo;
774
775 BstrFmt bstrDesc = BstrFmt(tr("Read appliance '%s'"),
776 aLocInfo.strPath.c_str());
777 HRESULT rc;
778 /* Create the progress object */
779 aProgress.createObject();
780 if (task->locInfo.storageType == VFSType_File)
781 {
782 /* 1 operation only */
783 rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
784 bstrDesc,
785 TRUE /* aCancelable */);
786 }
787 else
788 {
789 /* 4/5 is downloading, 1/5 is reading */
790 rc = aProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
791 bstrDesc,
792 TRUE /* aCancelable */,
793 2, // ULONG cOperations,
794 5, // ULONG ulTotalOperationsWeight,
795 BstrFmt(tr("Download appliance '%s'"),
796 aLocInfo.strPath.c_str()), // CBSTR bstrFirstOperationDescription,
797 4); // ULONG ulFirstOperationWeight,
798 }
799 if (FAILED(rc)) throw rc;
800
801 task->progress = aProgress;
802
803 rc = task->startThread();
804 CheckComRCThrowRC(rc);
805
806 /* Don't destruct on success */
807 task.release();
808
809 return rc;
810}
811
812HRESULT Appliance::importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
813{
814 /* Initialize our worker task */
815 std::auto_ptr<TaskImportOVF> task(new TaskImportOVF(this));
816 /* What should the task do */
817 task->taskType = TaskImportOVF::Import;
818 /* Copy the current location info to the task */
819 task->locInfo = aLocInfo;
820
821 Bstr progressDesc = BstrFmt(tr("Import appliance '%s'"),
822 aLocInfo.strPath.c_str());
823
824 HRESULT rc = S_OK;
825
826 /* todo: This progress init stuff should be done a little bit more generic */
827 if (task->locInfo.storageType == VFSType_File)
828 rc = setUpProgressFS(aProgress, progressDesc);
829 else
830 rc = setUpProgressImportS3(aProgress, progressDesc);
831 if (FAILED(rc)) throw rc;
832
833 task->progress = aProgress;
834
835 rc = task->startThread();
836 CheckComRCThrowRC(rc);
837
838 /* Don't destruct on success */
839 task.release();
840
841 return rc;
842}
843
844/**
845 * Worker thread implementation for Read() (ovf reader).
846 * @param aThread
847 * @param pvUser
848 */
849/* static */
850DECLCALLBACK(int) Appliance::taskThreadImportOVF(RTTHREAD /* aThread */, void *pvUser)
851{
852 std::auto_ptr<TaskImportOVF> task(static_cast<TaskImportOVF*>(pvUser));
853 AssertReturn(task.get(), VERR_GENERAL_FAILURE);
854
855 Appliance *pAppliance = task->pAppliance;
856
857 LogFlowFuncEnter();
858 LogFlowFunc(("Appliance %p\n", pAppliance));
859
860 HRESULT rc = S_OK;
861
862 switch(task->taskType)
863 {
864 case TaskImportOVF::Read:
865 {
866 if (task->locInfo.storageType == VFSType_File)
867 rc = pAppliance->readFS(task.get());
868 else if (task->locInfo.storageType == VFSType_S3)
869 rc = pAppliance->readS3(task.get());
870 break;
871 }
872 case TaskImportOVF::Import:
873 {
874 if (task->locInfo.storageType == VFSType_File)
875 rc = pAppliance->importFS(task.get());
876 else if (task->locInfo.storageType == VFSType_S3)
877 rc = pAppliance->importS3(task.get());
878 break;
879 }
880 }
881
882 LogFlowFunc(("rc=%Rhrc\n", rc));
883 LogFlowFuncLeave();
884
885 return VINF_SUCCESS;
886}
887
888int Appliance::TaskImportOVF::startThread()
889{
890 int vrc = RTThreadCreate(NULL, Appliance::taskThreadImportOVF, this,
891 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
892 "Appliance::Task");
893
894 ComAssertMsgRCRet(vrc,
895 ("Could not create taskThreadImportOVF (%Rrc)\n", vrc), E_FAIL);
896
897 return S_OK;
898}
899
900int Appliance::readFS(TaskImportOVF *pTask)
901{
902 LogFlowFuncEnter();
903 LogFlowFunc(("Appliance %p\n", this));
904
905 AutoCaller autoCaller(this);
906 CheckComRCReturnRC(autoCaller.rc());
907
908 AutoWriteLock appLock(this);
909
910 HRESULT rc = S_OK;
911
912 try
913 {
914 m->pReader = new OVFReader(pTask->locInfo.strPath);
915 }
916 catch(xml::Error &x)
917 {
918 rc = setError(VBOX_E_FILE_ERROR,
919 x.what());
920 }
921
922 pTask->rc = rc;
923
924 if (!pTask->progress.isNull())
925 pTask->progress->notifyComplete(rc);
926
927 LogFlowFunc(("rc=%Rhrc\n", rc));
928 LogFlowFuncLeave();
929
930 return VINF_SUCCESS;
931}
932
933int Appliance::readS3(TaskImportOVF *pTask)
934{
935 LogFlowFuncEnter();
936 LogFlowFunc(("Appliance %p\n", this));
937
938 AutoCaller autoCaller(this);
939 CheckComRCReturnRC(autoCaller.rc());
940
941 AutoWriteLock appLock(this);
942
943 HRESULT rc = S_OK;
944 int vrc = VINF_SUCCESS;
945 RTS3 hS3 = NIL_RTS3;
946 char szOSTmpDir[RTPATH_MAX];
947 RTPathTemp(szOSTmpDir, sizeof(szOSTmpDir));
948 /* The template for the temporary directory created below */
949 char *pszTmpDir;
950 RTStrAPrintf(&pszTmpDir, "%s"RTPATH_SLASH_STR"vbox-ovf-XXXXXX", szOSTmpDir);
951 list< pair<Utf8Str, ULONG> > filesList;
952 Utf8Str strTmpOvf;
953
954 try
955 {
956 /* Extract the bucket */
957 Utf8Str tmpPath = pTask->locInfo.strPath;
958 Utf8Str bucket;
959 parseBucket(tmpPath, bucket);
960
961 /* We need a temporary directory which we can put the OVF file & all
962 * disk images in */
963 vrc = RTDirCreateTemp(pszTmpDir);
964 if (RT_FAILURE(rc))
965 throw setError(VBOX_E_FILE_ERROR,
966 tr("Cannot create temporary directory '%s'"), pszTmpDir);
967
968 /* The temporary name of the target OVF file */
969 strTmpOvf = Utf8StrFmt("%s/%s", pszTmpDir, RTPathFilename(tmpPath));
970
971 /* Next we have to download the OVF */
972 vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
973 if(RT_FAILURE(vrc))
974 throw setError(VBOX_E_IPRT_ERROR,
975 tr("Cannot create S3 service handler"));
976 RTS3SetProgressCallback(hS3, pTask->updateProgress, &pTask);
977
978 /* Get it */
979 char *pszFilename = RTPathFilename(strTmpOvf.c_str());
980 vrc = RTS3GetKey(hS3, bucket.c_str(), pszFilename, strTmpOvf.c_str());
981 if (RT_FAILURE(vrc))
982 {
983 if(vrc == VERR_S3_CANCELED)
984 throw S_OK; /* todo: !!!!!!!!!!!!! */
985 else if(vrc == VERR_S3_ACCESS_DENIED)
986 throw setError(E_ACCESSDENIED,
987 tr("Cannot download file '%s' from S3 storage server (Access denied)"), pszFilename);
988 else if(vrc == VERR_S3_NOT_FOUND)
989 throw setError(VBOX_E_FILE_ERROR,
990 tr("Cannot download file '%s' from S3 storage server (File not found)"), pszFilename);
991 else
992 throw setError(VBOX_E_IPRT_ERROR,
993 tr("Cannot download file '%s' from S3 storage server (%Rrc)"), pszFilename, vrc);
994 }
995
996 /* Close the connection early */
997 RTS3Destroy(hS3);
998 hS3 = NIL_RTS3;
999
1000 if (!pTask->progress.isNull())
1001 pTask->progress->setNextOperation(Bstr(tr("Reading")), 1);
1002
1003 /* Prepare the temporary reading of the OVF */
1004 ComObjPtr<Progress> progress;
1005 LocationInfo li;
1006 li.strPath = strTmpOvf;
1007 /* Start the reading from the fs */
1008 rc = readImpl(li, progress);
1009 if (FAILED(rc)) throw rc;
1010
1011 /* Unlock the appliance for the reading thread */
1012 appLock.unlock();
1013 /* Wait until the reading is done, but report the progress back to the
1014 caller */
1015 ComPtr<IProgress> progressInt(progress);
1016 waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
1017
1018 /* Again lock the appliance for the next steps */
1019 appLock.lock();
1020 }
1021 catch(HRESULT aRC)
1022 {
1023 rc = aRC;
1024 }
1025 /* Cleanup */
1026 RTS3Destroy(hS3);
1027 /* Delete all files which where temporary created */
1028 if (RTPathExists(strTmpOvf.c_str()))
1029 {
1030 vrc = RTFileDelete(strTmpOvf.c_str());
1031 if(RT_FAILURE(vrc))
1032 rc = setError(VBOX_E_FILE_ERROR,
1033 tr("Cannot delete file '%s' (%Rrc)"), strTmpOvf.c_str(), vrc);
1034 }
1035 /* Delete the temporary directory */
1036 if (RTPathExists(pszTmpDir))
1037 {
1038 vrc = RTDirRemove(pszTmpDir);
1039 if(RT_FAILURE(vrc))
1040 rc = setError(VBOX_E_FILE_ERROR,
1041 tr("Cannot delete temporary directory '%s' (%Rrc)"), pszTmpDir, vrc);
1042 }
1043 if (pszTmpDir)
1044 RTStrFree(pszTmpDir);
1045
1046 pTask->rc = rc;
1047
1048 if (!pTask->progress.isNull())
1049 pTask->progress->notifyComplete(rc);
1050
1051 LogFlowFunc(("rc=%Rhrc\n", rc));
1052 LogFlowFuncLeave();
1053
1054 return VINF_SUCCESS;
1055}
1056
1057int Appliance::importFS(TaskImportOVF *pTask)
1058{
1059 LogFlowFuncEnter();
1060 LogFlowFunc(("Appliance %p\n", this));
1061
1062 AutoCaller autoCaller(this);
1063 CheckComRCReturnRC(autoCaller.rc());
1064
1065 AutoWriteLock appLock(this);
1066
1067 HRESULT rc = S_OK;
1068
1069 // rollback for errors:
1070 // a list of images that we created/imported
1071 list<MyHardDiskAttachment> llHardDiskAttachments;
1072 list< ComPtr<IHardDisk> > llHardDisksCreated;
1073 list<Guid> llMachinesRegistered;
1074
1075 ComPtr<ISession> session;
1076 bool fSessionOpen = false;
1077 rc = session.createInprocObject(CLSID_Session);
1078 CheckComRCReturnRC(rc);
1079
1080 const OVFReader reader = *m->pReader;
1081 // this is safe to access because this thread only gets started
1082 // if pReader != NULL
1083
1084 list<VirtualSystem>::const_iterator it;
1085 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it1;
1086 /* Iterate through all virtual systems of that appliance */
1087 size_t i = 0;
1088 for (it = reader.m_llVirtualSystems.begin(),
1089 it1 = m->virtualSystemDescriptions.begin();
1090 it != reader.m_llVirtualSystems.end();
1091 ++it, ++it1, ++i)
1092 {
1093 const VirtualSystem &vsysThis = *it;
1094 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it1);
1095
1096 ComPtr<IMachine> pNewMachine;
1097
1098 /* Catch possible errors */
1099 try
1100 {
1101 /* Guest OS type */
1102 std::list<VirtualSystemDescriptionEntry*> vsdeOS;
1103 vsdeOS = vsdescThis->findByType(VirtualSystemDescriptionType_OS);
1104 if (vsdeOS.size() < 1)
1105 throw setError(VBOX_E_FILE_ERROR,
1106 tr("Missing guest OS type"));
1107 const Utf8Str &strOsTypeVBox = vsdeOS.front()->strVbox;
1108
1109 /* Now that we know the base system get our internal defaults based on that. */
1110 ComPtr<IGuestOSType> osType;
1111 rc = mVirtualBox->GetGuestOSType(Bstr(strOsTypeVBox), osType.asOutParam());
1112 if (FAILED(rc)) throw rc;
1113
1114 /* Create the machine */
1115 /* First get the name */
1116 std::list<VirtualSystemDescriptionEntry*> vsdeName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
1117 if (vsdeName.size() < 1)
1118 throw setError(VBOX_E_FILE_ERROR,
1119 tr("Missing VM name"));
1120 const Utf8Str &strNameVBox = vsdeName.front()->strVbox;
1121 rc = mVirtualBox->CreateMachine(Bstr(strNameVBox), Bstr(strOsTypeVBox),
1122 Bstr(), Bstr(),
1123 pNewMachine.asOutParam());
1124 if (FAILED(rc)) throw rc;
1125
1126 // and the description
1127 std::list<VirtualSystemDescriptionEntry*> vsdeDescription = vsdescThis->findByType(VirtualSystemDescriptionType_Description);
1128 if (vsdeDescription.size())
1129 {
1130 const Utf8Str &strDescription = vsdeDescription.front()->strVbox;
1131 rc = pNewMachine->COMSETTER(Description)(Bstr(strDescription));
1132 if (FAILED(rc)) throw rc;
1133 }
1134
1135 /* CPU count */
1136 std::list<VirtualSystemDescriptionEntry*> vsdeCPU = vsdescThis->findByType (VirtualSystemDescriptionType_CPU);
1137 ComAssertMsgThrow(vsdeCPU.size() == 1, ("CPU count missing"), E_FAIL);
1138 const Utf8Str &cpuVBox = vsdeCPU.front()->strVbox;
1139 ULONG tmpCount = (ULONG)RTStrToUInt64(cpuVBox.c_str());
1140 rc = pNewMachine->COMSETTER(CPUCount)(tmpCount);
1141 if (FAILED(rc)) throw rc;
1142 bool fEnableIOApic = false;
1143 /* We need HWVirt & IO-APIC if more than one CPU is requested */
1144 if (tmpCount > 1)
1145 {
1146 rc = pNewMachine->COMSETTER(HWVirtExEnabled)(TRUE);
1147 if (FAILED(rc)) throw rc;
1148
1149 fEnableIOApic = true;
1150 }
1151
1152 /* RAM */
1153 std::list<VirtualSystemDescriptionEntry*> vsdeRAM = vsdescThis->findByType(VirtualSystemDescriptionType_Memory);
1154 ComAssertMsgThrow(vsdeRAM.size() == 1, ("RAM size missing"), E_FAIL);
1155 const Utf8Str &memoryVBox = vsdeRAM.front()->strVbox;
1156 ULONG tt = (ULONG)RTStrToUInt64(memoryVBox.c_str());
1157 rc = pNewMachine->COMSETTER(MemorySize)(tt);
1158 if (FAILED(rc)) throw rc;
1159
1160 /* VRAM */
1161 /* Get the recommended VRAM for this guest OS type */
1162 ULONG vramVBox;
1163 rc = osType->COMGETTER(RecommendedVRAM)(&vramVBox);
1164 if (FAILED(rc)) throw rc;
1165
1166 /* Set the VRAM */
1167 rc = pNewMachine->COMSETTER(VRAMSize)(vramVBox);
1168 if (FAILED(rc)) throw rc;
1169
1170 /* I/O APIC: so far we have no setting for this. Enable it if we
1171 import a Windows VM because if if Windows was installed without IOAPIC,
1172 it will not mind finding an one later on, but if Windows was installed
1173 _with_ an IOAPIC, it will bluescreen if it's not found */
1174 Bstr bstrFamilyId;
1175 rc = osType->COMGETTER(FamilyId)(bstrFamilyId.asOutParam());
1176 if (FAILED(rc)) throw rc;
1177
1178 Utf8Str strFamilyId(bstrFamilyId);
1179 if (strFamilyId == "Windows")
1180 fEnableIOApic = true;
1181
1182 /* If IP-APIC should be enabled could be have different reasons.
1183 See CPU count & the Win test above. Here we enable it if it was
1184 previously requested. */
1185 if (fEnableIOApic)
1186 {
1187 ComPtr<IBIOSSettings> pBIOSSettings;
1188 rc = pNewMachine->COMGETTER(BIOSSettings)(pBIOSSettings.asOutParam());
1189 if (FAILED(rc)) throw rc;
1190
1191 rc = pBIOSSettings->COMSETTER(IOAPICEnabled)(TRUE);
1192 if (FAILED(rc)) throw rc;
1193 }
1194
1195 /* Audio Adapter */
1196 std::list<VirtualSystemDescriptionEntry*> vsdeAudioAdapter = vsdescThis->findByType(VirtualSystemDescriptionType_SoundCard);
1197 /* @todo: we support one audio adapter only */
1198 if (vsdeAudioAdapter.size() > 0)
1199 {
1200 const Utf8Str& audioAdapterVBox = vsdeAudioAdapter.front()->strVbox;
1201 if (audioAdapterVBox.compare("null", Utf8Str::CaseInsensitive) != 0)
1202 {
1203 uint32_t audio = RTStrToUInt32(audioAdapterVBox.c_str());
1204 ComPtr<IAudioAdapter> audioAdapter;
1205 rc = pNewMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1206 if (FAILED(rc)) throw rc;
1207 rc = audioAdapter->COMSETTER(Enabled)(true);
1208 if (FAILED(rc)) throw rc;
1209 rc = audioAdapter->COMSETTER(AudioController)(static_cast<AudioControllerType_T>(audio));
1210 if (FAILED(rc)) throw rc;
1211 }
1212 }
1213
1214#ifdef VBOX_WITH_USB
1215 /* USB Controller */
1216 std::list<VirtualSystemDescriptionEntry*> vsdeUSBController = vsdescThis->findByType(VirtualSystemDescriptionType_USBController);
1217 // USB support is enabled if there's at least one such entry; to disable USB support,
1218 // the type of the USB item would have been changed to "ignore"
1219 bool fUSBEnabled = vsdeUSBController.size() > 0;
1220
1221 ComPtr<IUSBController> usbController;
1222 rc = pNewMachine->COMGETTER(USBController)(usbController.asOutParam());
1223 if (FAILED(rc)) throw rc;
1224 rc = usbController->COMSETTER(Enabled)(fUSBEnabled);
1225 if (FAILED(rc)) throw rc;
1226#endif /* VBOX_WITH_USB */
1227
1228 /* Change the network adapters */
1229 std::list<VirtualSystemDescriptionEntry*> vsdeNW = vsdescThis->findByType(VirtualSystemDescriptionType_NetworkAdapter);
1230 if (vsdeNW.size() == 0)
1231 {
1232 /* No network adapters, so we have to disable our default one */
1233 ComPtr<INetworkAdapter> nwVBox;
1234 rc = pNewMachine->GetNetworkAdapter(0, nwVBox.asOutParam());
1235 if (FAILED(rc)) throw rc;
1236 rc = nwVBox->COMSETTER(Enabled)(false);
1237 if (FAILED(rc)) throw rc;
1238 }
1239 else
1240 {
1241 list<VirtualSystemDescriptionEntry*>::const_iterator nwIt;
1242 /* Iterate through all network cards. We support 8 network adapters
1243 * at the maximum. (@todo: warn if there are more!) */
1244 size_t a = 0;
1245 for (nwIt = vsdeNW.begin();
1246 (nwIt != vsdeNW.end() && a < SchemaDefs::NetworkAdapterCount);
1247 ++nwIt, ++a)
1248 {
1249 const VirtualSystemDescriptionEntry* pvsys = *nwIt;
1250
1251 const Utf8Str &nwTypeVBox = pvsys->strVbox;
1252 uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str());
1253 ComPtr<INetworkAdapter> pNetworkAdapter;
1254 rc = pNewMachine->GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam());
1255 if (FAILED(rc)) throw rc;
1256 /* Enable the network card & set the adapter type */
1257 rc = pNetworkAdapter->COMSETTER(Enabled)(true);
1258 if (FAILED(rc)) throw rc;
1259 rc = pNetworkAdapter->COMSETTER(AdapterType)(static_cast<NetworkAdapterType_T>(tt1));
1260 if (FAILED(rc)) throw rc;
1261
1262 // default is NAT; change to "bridged" if extra conf says so
1263 if (!pvsys->strExtraConfig.compare("type=Bridged", Utf8Str::CaseInsensitive))
1264 {
1265 /* Attach to the right interface */
1266 rc = pNetworkAdapter->AttachToBridgedInterface();
1267 if (FAILED(rc)) throw rc;
1268 ComPtr<IHost> host;
1269 rc = mVirtualBox->COMGETTER(Host)(host.asOutParam());
1270 if (FAILED(rc)) throw rc;
1271 com::SafeIfaceArray<IHostNetworkInterface> nwInterfaces;
1272 rc = host->COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(nwInterfaces));
1273 if (FAILED(rc)) throw rc;
1274 /* We search for the first host network interface which
1275 * is usable for bridged networking */
1276 for (size_t i=0; i < nwInterfaces.size(); ++i)
1277 {
1278 HostNetworkInterfaceType_T itype;
1279 rc = nwInterfaces[i]->COMGETTER(InterfaceType)(&itype);
1280 if (FAILED(rc)) throw rc;
1281 if (itype == HostNetworkInterfaceType_Bridged)
1282 {
1283 Bstr name;
1284 rc = nwInterfaces[i]->COMGETTER(Name)(name.asOutParam());
1285 if (FAILED(rc)) throw rc;
1286 /* Set the interface name to attach to */
1287 pNetworkAdapter->COMSETTER(HostInterface)(name);
1288 if (FAILED(rc)) throw rc;
1289 break;
1290 }
1291 }
1292 }
1293 /* Next test for host only interfaces */
1294 else if (!pvsys->strExtraConfig.compare("type=HostOnly", Utf8Str::CaseInsensitive))
1295 {
1296 /* Attach to the right interface */
1297 rc = pNetworkAdapter->AttachToHostOnlyInterface();
1298 if (FAILED(rc)) throw rc;
1299 ComPtr<IHost> host;
1300 rc = mVirtualBox->COMGETTER(Host)(host.asOutParam());
1301 if (FAILED(rc)) throw rc;
1302 com::SafeIfaceArray<IHostNetworkInterface> nwInterfaces;
1303 rc = host->COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(nwInterfaces));
1304 if (FAILED(rc)) throw rc;
1305 /* We search for the first host network interface which
1306 * is usable for host only networking */
1307 for (size_t i=0; i < nwInterfaces.size(); ++i)
1308 {
1309 HostNetworkInterfaceType_T itype;
1310 rc = nwInterfaces[i]->COMGETTER(InterfaceType)(&itype);
1311 if (FAILED(rc)) throw rc;
1312 if (itype == HostNetworkInterfaceType_HostOnly)
1313 {
1314 Bstr name;
1315 rc = nwInterfaces[i]->COMGETTER(Name)(name.asOutParam());
1316 if (FAILED(rc)) throw rc;
1317 /* Set the interface name to attach to */
1318 pNetworkAdapter->COMSETTER(HostInterface)(name);
1319 if (FAILED(rc)) throw rc;
1320 break;
1321 }
1322 }
1323 }
1324 }
1325 }
1326
1327 /* Floppy drive */
1328 std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);
1329 // Floppy support is enabled if there's at least one such entry; to disable floppy support,
1330 // the type of the floppy item would have been changed to "ignore"
1331 bool fFloppyEnabled = vsdeFloppy.size() > 0;
1332 ComPtr<IFloppyDrive> floppyDrive;
1333 rc = pNewMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
1334 if (FAILED(rc)) throw rc;
1335 rc = floppyDrive->COMSETTER(Enabled)(fFloppyEnabled);
1336 if (FAILED(rc)) throw rc;
1337
1338 /* CDROM drive */
1339 /* @todo: I can't disable the CDROM. So nothing to do for now */
1340 // std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsd->findByType(VirtualSystemDescriptionType_CDROM);
1341
1342 /* Hard disk controller IDE */
1343 std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerIDE);
1344 if (vsdeHDCIDE.size() > 1)
1345 throw setError(VBOX_E_FILE_ERROR,
1346 tr("Too many IDE controllers in OVF; VirtualBox only supports one"));
1347 if (vsdeHDCIDE.size() == 1)
1348 {
1349 ComPtr<IStorageController> pController;
1350 rc = pNewMachine->GetStorageControllerByName(Bstr("IDE"), pController.asOutParam());
1351 if (FAILED(rc)) throw rc;
1352
1353 const char *pcszIDEType = vsdeHDCIDE.front()->strVbox.c_str();
1354 if (!strcmp(pcszIDEType, "PIIX3"))
1355 rc = pController->COMSETTER(ControllerType)(StorageControllerType_PIIX3);
1356 else if (!strcmp(pcszIDEType, "PIIX4"))
1357 rc = pController->COMSETTER(ControllerType)(StorageControllerType_PIIX4);
1358 else if (!strcmp(pcszIDEType, "ICH6"))
1359 rc = pController->COMSETTER(ControllerType)(StorageControllerType_ICH6);
1360 else
1361 throw setError(VBOX_E_FILE_ERROR,
1362 tr("Invalid IDE controller type \"%s\""),
1363 pcszIDEType);
1364 if (FAILED(rc)) throw rc;
1365 }
1366#ifdef VBOX_WITH_AHCI
1367 /* Hard disk controller SATA */
1368 std::list<VirtualSystemDescriptionEntry*> vsdeHDCSATA = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSATA);
1369 if (vsdeHDCSATA.size() > 1)
1370 throw setError(VBOX_E_FILE_ERROR,
1371 tr("Too many SATA controllers in OVF; VirtualBox only supports one"));
1372 if (vsdeHDCSATA.size() > 0)
1373 {
1374 ComPtr<IStorageController> pController;
1375 const Utf8Str &hdcVBox = vsdeHDCSATA.front()->strVbox;
1376 if (hdcVBox == "AHCI")
1377 {
1378 rc = pNewMachine->AddStorageController(Bstr("SATA"), StorageBus_SATA, pController.asOutParam());
1379 if (FAILED(rc)) throw rc;
1380 }
1381 else
1382 throw setError(VBOX_E_FILE_ERROR,
1383 tr("Invalid SATA controller type \"%s\""),
1384 hdcVBox.c_str());
1385 }
1386#endif /* VBOX_WITH_AHCI */
1387
1388#ifdef VBOX_WITH_LSILOGIC
1389 /* Hard disk controller SCSI */
1390 std::list<VirtualSystemDescriptionEntry*> vsdeHDCSCSI = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
1391 if (vsdeHDCSCSI.size() > 1)
1392 throw setError(VBOX_E_FILE_ERROR,
1393 tr("Too many SCSI controllers in OVF; VirtualBox only supports one"));
1394 if (vsdeHDCSCSI.size() > 0)
1395 {
1396 ComPtr<IStorageController> pController;
1397 StorageControllerType_T controllerType;
1398 const Utf8Str &hdcVBox = vsdeHDCSCSI.front()->strVbox;
1399 if (hdcVBox == "LsiLogic")
1400 controllerType = StorageControllerType_LsiLogic;
1401 else if (hdcVBox == "BusLogic")
1402 controllerType = StorageControllerType_BusLogic;
1403 else
1404 throw setError(VBOX_E_FILE_ERROR,
1405 tr("Invalid SCSI controller type \"%s\""),
1406 hdcVBox.c_str());
1407
1408 rc = pNewMachine->AddStorageController(Bstr("SCSI"), StorageBus_SCSI, pController.asOutParam());
1409 if (FAILED(rc)) throw rc;
1410 rc = pController->COMSETTER(ControllerType)(controllerType);
1411 if (FAILED(rc)) throw rc;
1412 }
1413#endif /* VBOX_WITH_LSILOGIC */
1414
1415 /* Now its time to register the machine before we add any hard disks */
1416 rc = mVirtualBox->RegisterMachine(pNewMachine);
1417 if (FAILED(rc)) throw rc;
1418
1419 Bstr newMachineId_;
1420 rc = pNewMachine->COMGETTER(Id)(newMachineId_.asOutParam());
1421 if (FAILED(rc)) throw rc;
1422 Guid newMachineId(newMachineId_);
1423
1424 // store new machine for roll-back in case of errors
1425 llMachinesRegistered.push_back(newMachineId);
1426
1427 /* Create the hard disks & connect them to the appropriate controllers. */
1428 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
1429 if (avsdeHDs.size() > 0)
1430 {
1431 /* If in the next block an error occur we have to deregister
1432 the machine, so make an extra try/catch block. */
1433 ComPtr<IHardDisk> srcHdVBox;
1434 bool fSourceHdNeedsClosing = false;
1435
1436 try
1437 {
1438 /* In order to attach hard disks we need to open a session
1439 * for the new machine */
1440 rc = mVirtualBox->OpenSession(session, newMachineId_);
1441 if (FAILED(rc)) throw rc;
1442 fSessionOpen = true;
1443
1444 /* The disk image has to be on the same place as the OVF file. So
1445 * strip the filename out of the full file path. */
1446 Utf8Str strSrcDir(pTask->locInfo.strPath);
1447 strSrcDir.stripFilename();
1448
1449 /* Iterate over all given disk images */
1450 list<VirtualSystemDescriptionEntry*>::const_iterator itHD;
1451 for (itHD = avsdeHDs.begin();
1452 itHD != avsdeHDs.end();
1453 ++itHD)
1454 {
1455 VirtualSystemDescriptionEntry *vsdeHD = *itHD;
1456
1457 const char *pcszDstFilePath = vsdeHD->strVbox.c_str();
1458 /* Check if the destination file exists already or the
1459 * destination path is empty. */
1460 if ( !(*pcszDstFilePath)
1461 || RTPathExists(pcszDstFilePath)
1462 )
1463 /* This isn't allowed */
1464 throw setError(VBOX_E_FILE_ERROR,
1465 tr("Destination file '%s' exists",
1466 pcszDstFilePath));
1467
1468 /* Find the disk from the OVF's disk list */
1469 DiskImagesMap::const_iterator itDiskImage = reader.m_mapDisks.find(vsdeHD->strRef);
1470 /* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
1471 in the virtual system's disks map under that ID and also in the global images map. */
1472 VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
1473
1474 if ( itDiskImage == reader.m_mapDisks.end()
1475 || itVirtualDisk == vsysThis.mapVirtualDisks.end()
1476 )
1477 throw setError(E_FAIL,
1478 tr("Internal inconsistency looking up disk images."));
1479
1480 const DiskImage &di = itDiskImage->second;
1481 const VirtualDisk &vd = itVirtualDisk->second;
1482
1483 /* Make sure all target directories exists */
1484 rc = VirtualBox::ensureFilePathExists(pcszDstFilePath);
1485 if (FAILED(rc))
1486 throw rc;
1487
1488 // subprogress object for hard disk
1489 ComPtr<IProgress> pProgress2;
1490
1491 ComPtr<IHardDisk> dstHdVBox;
1492 /* If strHref is empty we have to create a new file */
1493 if (di.strHref.isEmpty())
1494 {
1495 /* Which format to use? */
1496 Bstr srcFormat = L"VDI";
1497 if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
1498 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive))
1499 srcFormat = L"VMDK";
1500 /* Create an empty hard disk */
1501 rc = mVirtualBox->CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam());
1502 if (FAILED(rc)) throw rc;
1503
1504 /* Create a dynamic growing disk image with the given capacity */
1505 rc = dstHdVBox->CreateBaseStorage(di.iCapacity / _1M, HardDiskVariant_Standard, pProgress2.asOutParam());
1506 if (FAILED(rc)) throw rc;
1507
1508 /* Advance to the next operation */
1509 if (!pTask->progress.isNull())
1510 pTask->progress->setNextOperation(BstrFmt(tr("Creating virtual disk image '%s'"), pcszDstFilePath),
1511 vsdeHD->ulSizeMB); // operation's weight, as set up with the IProgress originally
1512 }
1513 else
1514 {
1515 /* Construct the source file path */
1516 Utf8StrFmt strSrcFilePath("%s%c%s", strSrcDir.c_str(), RTPATH_DELIMITER, di.strHref.c_str());
1517 /* Check if the source file exists */
1518 if (!RTPathExists(strSrcFilePath.c_str()))
1519 /* This isn't allowed */
1520 throw setError(VBOX_E_FILE_ERROR,
1521 tr("Source virtual disk image file '%s' doesn't exist"),
1522 strSrcFilePath.c_str());
1523
1524 /* Clone the disk image (this is necessary cause the id has
1525 * to be recreated for the case the same hard disk is
1526 * attached already from a previous import) */
1527
1528 /* First open the existing disk image */
1529 rc = mVirtualBox->OpenHardDisk(Bstr(strSrcFilePath),
1530 AccessMode_ReadOnly,
1531 false, Bstr(""), false, Bstr(""),
1532 srcHdVBox.asOutParam());
1533 if (FAILED(rc)) throw rc;
1534 fSourceHdNeedsClosing = true;
1535
1536 /* We need the format description of the source disk image */
1537 Bstr srcFormat;
1538 rc = srcHdVBox->COMGETTER(Format)(srcFormat.asOutParam());
1539 if (FAILED(rc)) throw rc;
1540 /* Create a new hard disk interface for the destination disk image */
1541 rc = mVirtualBox->CreateHardDisk(srcFormat, Bstr(pcszDstFilePath), dstHdVBox.asOutParam());
1542 if (FAILED(rc)) throw rc;
1543 /* Clone the source disk image */
1544 rc = srcHdVBox->CloneTo(dstHdVBox, HardDiskVariant_Standard, NULL, pProgress2.asOutParam());
1545 if (FAILED(rc)) throw rc;
1546
1547 /* Advance to the next operation */
1548 if (!pTask->progress.isNull())
1549 pTask->progress->setNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()),
1550 vsdeHD->ulSizeMB); // operation's weight, as set up with the IProgress originally);
1551 }
1552
1553 // now wait for the background disk operation to complete; this throws HRESULTs on error
1554 waitForAsyncProgress(pTask->progress, pProgress2);
1555
1556 if (fSourceHdNeedsClosing)
1557 {
1558 rc = srcHdVBox->Close();
1559 if (FAILED(rc)) throw rc;
1560 fSourceHdNeedsClosing = false;
1561 }
1562
1563 llHardDisksCreated.push_back(dstHdVBox);
1564 /* Now use the new uuid to attach the disk image to our new machine */
1565 ComPtr<IMachine> sMachine;
1566 rc = session->COMGETTER(Machine)(sMachine.asOutParam());
1567 if (FAILED(rc)) throw rc;
1568 Bstr hdId;
1569 rc = dstHdVBox->COMGETTER(Id)(hdId.asOutParam());
1570 if (FAILED(rc)) throw rc;
1571
1572 /* For now we assume we have one controller of every type only */
1573 HardDiskController hdc = (*vsysThis.mapControllers.find(vd.idController)).second;
1574
1575 // this is for rollback later
1576 MyHardDiskAttachment mhda;
1577 mhda.uuid = newMachineId;
1578 mhda.pMachine = pNewMachine;
1579
1580 switch (hdc.system)
1581 {
1582 case HardDiskController::IDE:
1583 // For the IDE bus, the channel parameter can be either 0 or 1, to specify the primary
1584 // or secondary IDE controller, respectively. For the primary controller of the IDE bus,
1585 // the device number can be either 0 or 1, to specify the master or the slave device,
1586 // respectively. For the secondary IDE controller, the device number is always 1 because
1587 // the master device is reserved for the CD-ROM drive.
1588 mhda.controllerType = Bstr("IDE");
1589 switch (vd.ulAddressOnParent)
1590 {
1591 case 0: // interpret this as primary master
1592 mhda.lChannel = (long)0;
1593 mhda.lDevice = (long)0;
1594 break;
1595
1596 case 1: // interpret this as primary slave
1597 mhda.lChannel = (long)0;
1598 mhda.lDevice = (long)1;
1599 break;
1600
1601 case 2: // interpret this as secondary slave
1602 mhda.lChannel = (long)1;
1603 mhda.lDevice = (long)1;
1604 break;
1605
1606 default:
1607 throw setError(VBOX_E_NOT_SUPPORTED,
1608 tr("Invalid channel %RI16 specified; IDE controllers support only 0, 1 or 2"), vd.ulAddressOnParent);
1609 break;
1610 }
1611 break;
1612
1613 case HardDiskController::SATA:
1614 mhda.controllerType = Bstr("SATA");
1615 mhda.lChannel = (long)vd.ulAddressOnParent;
1616 mhda.lDevice = (long)0;
1617 break;
1618
1619 case HardDiskController::SCSI:
1620 mhda.controllerType = Bstr("SCSI");
1621 mhda.lChannel = (long)vd.ulAddressOnParent;
1622 mhda.lDevice = (long)0;
1623 break;
1624
1625 default: break;
1626 }
1627
1628 Log(("Attaching disk %s to channel %d on device %d\n", pcszDstFilePath, mhda.lChannel, mhda.lDevice));
1629
1630 rc = sMachine->AttachHardDisk(hdId,
1631 mhda.controllerType,
1632 mhda.lChannel,
1633 mhda.lDevice);
1634 if (FAILED(rc)) throw rc;
1635
1636 llHardDiskAttachments.push_back(mhda);
1637
1638 rc = sMachine->SaveSettings();
1639 if (FAILED(rc)) throw rc;
1640 } // end for (itHD = avsdeHDs.begin();
1641
1642 // only now that we're done with all disks, close the session
1643 rc = session->Close();
1644 if (FAILED(rc)) throw rc;
1645 fSessionOpen = false;
1646 }
1647 catch(HRESULT /* aRC */)
1648 {
1649 if (fSourceHdNeedsClosing)
1650 srcHdVBox->Close();
1651
1652 if (fSessionOpen)
1653 session->Close();
1654
1655 throw;
1656 }
1657 }
1658 }
1659 catch(HRESULT aRC)
1660 {
1661 rc = aRC;
1662 }
1663
1664 if (FAILED(rc))
1665 break;
1666
1667 } // for (it = pAppliance->m->llVirtualSystems.begin(),
1668
1669 if (FAILED(rc))
1670 {
1671 // with _whatever_ error we've had, do a complete roll-back of
1672 // machines and disks we've created; unfortunately this is
1673 // not so trivially done...
1674
1675 HRESULT rc2;
1676 // detach all hard disks from all machines we created
1677 list<MyHardDiskAttachment>::iterator itM;
1678 for (itM = llHardDiskAttachments.begin();
1679 itM != llHardDiskAttachments.end();
1680 ++itM)
1681 {
1682 const MyHardDiskAttachment &mhda = *itM;
1683 rc2 = mVirtualBox->OpenSession(session, Bstr(mhda.uuid));
1684 if (SUCCEEDED(rc2))
1685 {
1686 ComPtr<IMachine> sMachine;
1687 rc2 = session->COMGETTER(Machine)(sMachine.asOutParam());
1688 if (SUCCEEDED(rc2))
1689 {
1690 rc2 = sMachine->DetachHardDisk(Bstr(mhda.controllerType), mhda.lChannel, mhda.lDevice);
1691 rc2 = sMachine->SaveSettings();
1692 }
1693 session->Close();
1694 }
1695 }
1696
1697 // now clean up all hard disks we created
1698 list< ComPtr<IHardDisk> >::iterator itHD;
1699 for (itHD = llHardDisksCreated.begin();
1700 itHD != llHardDisksCreated.end();
1701 ++itHD)
1702 {
1703 ComPtr<IHardDisk> pDisk = *itHD;
1704 ComPtr<IProgress> pProgress;
1705 rc2 = pDisk->DeleteStorage(pProgress.asOutParam());
1706 rc2 = pProgress->WaitForCompletion(-1);
1707 }
1708
1709 // finally, deregister and remove all machines
1710 list<Guid>::iterator itID;
1711 for (itID = llMachinesRegistered.begin();
1712 itID != llMachinesRegistered.end();
1713 ++itID)
1714 {
1715 const Guid &guid = *itID;
1716 ComPtr<IMachine> failedMachine;
1717 rc2 = mVirtualBox->UnregisterMachine(guid.toUtf16(), failedMachine.asOutParam());
1718 if (SUCCEEDED(rc2))
1719 rc2 = failedMachine->DeleteSettings();
1720 }
1721 }
1722
1723 pTask->rc = rc;
1724
1725 if (!pTask->progress.isNull())
1726 pTask->progress->notifyComplete(rc);
1727
1728 LogFlowFunc(("rc=%Rhrc\n", rc));
1729 LogFlowFuncLeave();
1730
1731 return VINF_SUCCESS;
1732}
1733
1734int Appliance::importS3(TaskImportOVF *pTask)
1735{
1736 LogFlowFuncEnter();
1737 LogFlowFunc(("Appliance %p\n", this));
1738
1739 AutoCaller autoCaller(this);
1740 CheckComRCReturnRC(autoCaller.rc());
1741
1742 AutoWriteLock appLock(this);
1743
1744 int vrc = VINF_SUCCESS;
1745 RTS3 hS3 = NIL_RTS3;
1746 char szOSTmpDir[RTPATH_MAX];
1747 RTPathTemp(szOSTmpDir, sizeof(szOSTmpDir));
1748 /* The template for the temporary directory created below */
1749 char *pszTmpDir;
1750 RTStrAPrintf(&pszTmpDir, "%s"RTPATH_SLASH_STR"vbox-ovf-XXXXXX", szOSTmpDir);
1751 list< pair<Utf8Str, ULONG> > filesList;
1752
1753 HRESULT rc = S_OK;
1754 try
1755 {
1756 /* Extract the bucket */
1757 Utf8Str tmpPath = pTask->locInfo.strPath;
1758 Utf8Str bucket;
1759 parseBucket(tmpPath, bucket);
1760
1761 /* We need a temporary directory which we can put the all disk images
1762 * in */
1763 vrc = RTDirCreateTemp(pszTmpDir);
1764 if (RT_FAILURE(rc))
1765 throw setError(VBOX_E_FILE_ERROR,
1766 tr("Cannot create temporary directory '%s'"), pszTmpDir);
1767
1768 /* Add every disks of every virtual system to an internal list */
1769 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
1770 for (it = m->virtualSystemDescriptions.begin();
1771 it != m->virtualSystemDescriptions.end();
1772 ++it)
1773 {
1774 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
1775 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
1776 std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
1777 for (itH = avsdeHDs.begin();
1778 itH != avsdeHDs.end();
1779 ++itH)
1780 {
1781 const Utf8Str &strTargetFile = (*itH)->strOvf;
1782 if (!strTargetFile.isEmpty())
1783 {
1784 /* The temporary name of the target disk file */
1785 Utf8StrFmt strTmpDisk("%s/%s", pszTmpDir, RTPathFilename(strTargetFile));
1786 filesList.push_back(pair<Utf8Str, ULONG>(strTmpDisk, (*itH)->ulSizeMB));
1787 }
1788 }
1789 }
1790
1791 /* Next we have to download the disk images */
1792 vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
1793 if(RT_FAILURE(vrc))
1794 throw setError(VBOX_E_IPRT_ERROR,
1795 tr("Cannot create S3 service handler"));
1796 RTS3SetProgressCallback(hS3, pTask->updateProgress, &pTask);
1797
1798 /* Download all files */
1799 for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
1800 {
1801 const pair<Utf8Str, ULONG> &s = (*it1);
1802 const Utf8Str &strSrcFile = s.first;
1803 /* Construct the source file name */
1804 char *pszFilename = RTPathFilename(strSrcFile.c_str());
1805 /* Advance to the next operation */
1806 if (!pTask->progress.isNull())
1807 pTask->progress->setNextOperation(BstrFmt(tr("Downloading file '%s'"), pszFilename), s.second);
1808
1809 vrc = RTS3GetKey(hS3, bucket.c_str(), pszFilename, strSrcFile.c_str());
1810 if (RT_FAILURE(vrc))
1811 {
1812 if(vrc == VERR_S3_CANCELED)
1813 throw S_OK; /* todo: !!!!!!!!!!!!! */
1814 else if(vrc == VERR_S3_ACCESS_DENIED)
1815 throw setError(E_ACCESSDENIED,
1816 tr("Cannot download file '%s' from S3 storage server (Access denied)"), pszFilename);
1817 else if(vrc == VERR_S3_NOT_FOUND)
1818 throw setError(VBOX_E_FILE_ERROR,
1819 tr("Cannot download file '%s' from S3 storage server (File not found)"), pszFilename);
1820 else
1821 throw setError(VBOX_E_IPRT_ERROR,
1822 tr("Cannot download file '%s' from S3 storage server (%Rrc)"), pszFilename, vrc);
1823 }
1824 }
1825
1826 /* Close the connection early */
1827 RTS3Destroy(hS3);
1828 hS3 = NIL_RTS3;
1829
1830 if (!pTask->progress.isNull())
1831 pTask->progress->setNextOperation(BstrFmt(tr("Importing appliance")), m->ulWeightPerOperation);
1832
1833 ComObjPtr<Progress> progress;
1834 /* Import the whole temporary OVF & the disk images */
1835 LocationInfo li;
1836 /* Provide a OVF file (haven't to exist) so the import routine can
1837 * figure out where the disk images are located. */
1838 Utf8StrFmt strTmpOvf("%s/%s", pszTmpDir, RTPathFilename(tmpPath));
1839 li.strPath = strTmpOvf;
1840 rc = importImpl(li, progress);
1841 if (FAILED(rc)) throw rc;
1842
1843 /* Unlock the appliance for the fs import thread */
1844 appLock.unlock();
1845 /* Wait until the import is done, but report the progress back to the
1846 caller */
1847 ComPtr<IProgress> progressInt(progress);
1848 waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
1849
1850 /* Again lock the appliance for the next steps */
1851 appLock.lock();
1852 }
1853 catch(HRESULT aRC)
1854 {
1855 rc = aRC;
1856 }
1857 /* Cleanup */
1858 RTS3Destroy(hS3);
1859 /* Delete all files which where temporary created */
1860 for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
1861 {
1862 const char *pszFilePath = (*it1).first.c_str();
1863 if (RTPathExists(pszFilePath))
1864 {
1865 vrc = RTFileDelete(pszFilePath);
1866 if(RT_FAILURE(vrc))
1867 rc = setError(VBOX_E_FILE_ERROR,
1868 tr("Cannot delete file '%s' (%Rrc)"), pszFilePath, vrc);
1869 }
1870 }
1871 /* Delete the temporary directory */
1872 if (RTPathExists(pszTmpDir))
1873 {
1874 vrc = RTDirRemove(pszTmpDir);
1875 if(RT_FAILURE(vrc))
1876 rc = setError(VBOX_E_FILE_ERROR,
1877 tr("Cannot delete temporary directory '%s' (%Rrc)"), pszTmpDir, vrc);
1878 }
1879 if (pszTmpDir)
1880 RTStrFree(pszTmpDir);
1881
1882 pTask->rc = rc;
1883
1884 if (!pTask->progress.isNull())
1885 pTask->progress->notifyComplete(rc);
1886
1887 LogFlowFunc(("rc=%Rhrc\n", rc));
1888 LogFlowFuncLeave();
1889
1890 return VINF_SUCCESS;
1891}
1892
1893HRESULT Appliance::writeImpl(int aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
1894{
1895 HRESULT rc = S_OK;
1896 try
1897 {
1898 /* Initialize our worker task */
1899 std::auto_ptr<TaskExportOVF> task(new TaskExportOVF(this));
1900 /* What should the task do */
1901 task->taskType = TaskExportOVF::Write;
1902 /* The OVF version to write */
1903 task->enFormat = (TaskExportOVF::OVFFormat)aFormat;
1904 /* Copy the current location info to the task */
1905 task->locInfo = aLocInfo;
1906
1907 Bstr progressDesc = BstrFmt(tr("Export appliance '%s'"),
1908 task->locInfo.strPath.c_str());
1909
1910 /* todo: This progress init stuff should be done a little bit more generic */
1911 if (task->locInfo.storageType == VFSType_File)
1912 rc = setUpProgressFS(aProgress, progressDesc);
1913 else
1914 rc = setUpProgressWriteS3(aProgress, progressDesc);
1915
1916 task->progress = aProgress;
1917
1918 rc = task->startThread();
1919 CheckComRCThrowRC(rc);
1920
1921 /* Don't destruct on success */
1922 task.release();
1923 }
1924 catch (HRESULT aRC)
1925 {
1926 rc = aRC;
1927 }
1928
1929 return rc;
1930}
1931
1932DECLCALLBACK(int) Appliance::taskThreadWriteOVF(RTTHREAD /* aThread */, void *pvUser)
1933{
1934 std::auto_ptr<TaskExportOVF> task(static_cast<TaskExportOVF*>(pvUser));
1935 AssertReturn(task.get(), VERR_GENERAL_FAILURE);
1936
1937 Appliance *pAppliance = task->pAppliance;
1938
1939 LogFlowFuncEnter();
1940 LogFlowFunc(("Appliance %p\n", pAppliance));
1941
1942 HRESULT rc = S_OK;
1943
1944 switch(task->taskType)
1945 {
1946 case TaskExportOVF::Write:
1947 {
1948 if (task->locInfo.storageType == VFSType_File)
1949 rc = pAppliance->writeFS(task.get());
1950 else if (task->locInfo.storageType == VFSType_S3)
1951 rc = pAppliance->writeS3(task.get());
1952 break;
1953 }
1954 }
1955
1956 LogFlowFunc(("rc=%Rhrc\n", rc));
1957 LogFlowFuncLeave();
1958
1959 return VINF_SUCCESS;
1960}
1961
1962int Appliance::TaskExportOVF::startThread()
1963{
1964 int vrc = RTThreadCreate(NULL, Appliance::taskThreadWriteOVF, this,
1965 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
1966 "Appliance::Task");
1967
1968 ComAssertMsgRCRet(vrc,
1969 ("Could not create taskThreadWriteOVF (%Rrc)\n", vrc), E_FAIL);
1970
1971 return S_OK;
1972}
1973
1974int Appliance::writeFS(TaskExportOVF *pTask)
1975{
1976 LogFlowFuncEnter();
1977 LogFlowFunc(("Appliance %p\n", this));
1978
1979 AutoCaller autoCaller(this);
1980 CheckComRCReturnRC(autoCaller.rc());
1981
1982 AutoWriteLock appLock(this);
1983
1984 HRESULT rc = S_OK;
1985
1986 try
1987 {
1988 xml::Document doc;
1989 xml::ElementNode *pelmRoot = doc.createRootElement("Envelope");
1990
1991 pelmRoot->setAttribute("ovf:version", (pTask->enFormat == TaskExportOVF::OVF_1_0) ? "1.0" : "0.9");
1992 pelmRoot->setAttribute("xml:lang", "en-US");
1993
1994 Utf8Str strNamespace = (pTask->enFormat == TaskExportOVF::OVF_0_9)
1995 ? "http://www.vmware.com/schema/ovf/1/envelope" // 0.9
1996 : "http://schemas.dmtf.org/ovf/envelope/1"; // 1.0
1997 pelmRoot->setAttribute("xmlns", strNamespace);
1998 pelmRoot->setAttribute("xmlns:ovf", strNamespace);
1999
2000// pelmRoot->setAttribute("xmlns:ovfstr", "http://schema.dmtf.org/ovf/strings/1");
2001 pelmRoot->setAttribute("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData");
2002 pelmRoot->setAttribute("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData");
2003 pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
2004// pelmRoot->setAttribute("xsi:schemaLocation", "http://schemas.dmtf.org/ovf/envelope/1 ../ovf-envelope.xsd");
2005
2006 // <Envelope>/<References>
2007 xml::ElementNode *pelmReferences = pelmRoot->createChild("References"); // 0.9 and 1.0
2008
2009 /* <Envelope>/<DiskSection>:
2010 <DiskSection>
2011 <Info>List of the virtual disks used in the package</Info>
2012 <Disk ovf:capacity="4294967296" ovf:diskId="lamp" ovf:format="http://www.vmware.com/specifications/vmdk.html#compressed" ovf:populatedSize="1924967692"/>
2013 </DiskSection> */
2014 xml::ElementNode *pelmDiskSection;
2015 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2016 {
2017 // <Section xsi:type="ovf:DiskSection_Type">
2018 pelmDiskSection = pelmRoot->createChild("Section");
2019 pelmDiskSection->setAttribute("xsi:type", "ovf:DiskSection_Type");
2020 }
2021 else
2022 pelmDiskSection = pelmRoot->createChild("DiskSection");
2023
2024 xml::ElementNode *pelmDiskSectionInfo = pelmDiskSection->createChild("Info");
2025 pelmDiskSectionInfo->addContent("List of the virtual disks used in the package");
2026 // for now, set up a map so we have a list of unique disk names (to make
2027 // sure the same disk name is only added once)
2028 map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
2029
2030 /* <Envelope>/<NetworkSection>:
2031 <NetworkSection>
2032 <Info>Logical networks used in the package</Info>
2033 <Network ovf:name="VM Network">
2034 <Description>The network that the LAMP Service will be available on</Description>
2035 </Network>
2036 </NetworkSection> */
2037 xml::ElementNode *pelmNetworkSection;
2038 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2039 {
2040 // <Section xsi:type="ovf:NetworkSection_Type">
2041 pelmNetworkSection = pelmRoot->createChild("Section");
2042 pelmNetworkSection->setAttribute("xsi:type", "ovf:NetworkSection_Type");
2043 }
2044 else
2045 pelmNetworkSection = pelmRoot->createChild("NetworkSection");
2046
2047 xml::ElementNode *pelmNetworkSectionInfo = pelmNetworkSection->createChild("Info");
2048 pelmNetworkSectionInfo->addContent("Logical networks used in the package");
2049 // for now, set up a map so we have a list of unique network names (to make
2050 // sure the same network name is only added once)
2051 map<Utf8Str, bool> mapNetworks;
2052 // we fill this later below when we iterate over the networks
2053
2054 // and here come the virtual systems:
2055
2056 // write a collection if we have more than one virtual system _and_ we're
2057 // writing OVF 1.0; otherwise fail since ovftool can't import more than
2058 // one machine, it seems
2059 xml::ElementNode *pelmToAddVirtualSystemsTo;
2060 if (m->virtualSystemDescriptions.size() > 1)
2061 {
2062 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2063 throw setError(VBOX_E_FILE_ERROR,
2064 tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0"));
2065
2066 pelmToAddVirtualSystemsTo = pelmRoot->createChild("VirtualSystemCollection");
2067 /* xml::AttributeNode *pattrVirtualSystemCollectionId = */ pelmToAddVirtualSystemsTo->setAttribute("ovf:name", "ExportedVirtualBoxMachines"); // whatever
2068 }
2069 else
2070 pelmToAddVirtualSystemsTo = pelmRoot; // add virtual system directly under root element
2071
2072 uint32_t cDisks = 0;
2073
2074 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
2075 /* Iterate through all virtual systems of that appliance */
2076 for (it = m->virtualSystemDescriptions.begin();
2077 it != m->virtualSystemDescriptions.end();
2078 ++it)
2079 {
2080 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
2081
2082 xml::ElementNode *pelmVirtualSystem;
2083 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2084 {
2085 // <Section xsi:type="ovf:NetworkSection_Type">
2086 pelmVirtualSystem = pelmToAddVirtualSystemsTo->createChild("Content");
2087 pelmVirtualSystem->setAttribute("xsi:type", "ovf:VirtualSystem_Type");
2088 }
2089 else
2090 pelmVirtualSystem = pelmToAddVirtualSystemsTo->createChild("VirtualSystem");
2091
2092 /*xml::ElementNode *pelmVirtualSystemInfo =*/ pelmVirtualSystem->createChild("Info")->addContent("A virtual machine");
2093
2094 std::list<VirtualSystemDescriptionEntry*> llName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
2095 if (llName.size() != 1)
2096 throw setError(VBOX_E_NOT_SUPPORTED,
2097 tr("Missing VM name"));
2098 Utf8Str &strVMName = llName.front()->strVbox;
2099 pelmVirtualSystem->setAttribute("ovf:id", strVMName);
2100
2101 // product info
2102 std::list<VirtualSystemDescriptionEntry*> llProduct = vsdescThis->findByType(VirtualSystemDescriptionType_Product);
2103 std::list<VirtualSystemDescriptionEntry*> llProductUrl = vsdescThis->findByType(VirtualSystemDescriptionType_ProductUrl);
2104 std::list<VirtualSystemDescriptionEntry*> llVendor = vsdescThis->findByType(VirtualSystemDescriptionType_Vendor);
2105 std::list<VirtualSystemDescriptionEntry*> llVendorUrl = vsdescThis->findByType(VirtualSystemDescriptionType_VendorUrl);
2106 std::list<VirtualSystemDescriptionEntry*> llVersion = vsdescThis->findByType(VirtualSystemDescriptionType_Version);
2107 bool fProduct = llProduct.size() && !llProduct.front()->strVbox.isEmpty();
2108 bool fProductUrl = llProductUrl.size() && !llProductUrl.front()->strVbox.isEmpty();
2109 bool fVendor = llVendor.size() && !llVendor.front()->strVbox.isEmpty();
2110 bool fVendorUrl = llVendorUrl.size() && !llVendorUrl.front()->strVbox.isEmpty();
2111 bool fVersion = llVersion.size() && !llVersion.front()->strVbox.isEmpty();
2112 if (fProduct ||
2113 fProductUrl ||
2114 fVersion ||
2115 fVendorUrl ||
2116 fVersion)
2117 {
2118 /* <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
2119 <Info>Meta-information about the installed software</Info>
2120 <Product>VAtest</Product>
2121 <Vendor>SUN Microsystems</Vendor>
2122 <Version>10.0</Version>
2123 <ProductUrl>http://blogs.sun.com/VirtualGuru</ProductUrl>
2124 <VendorUrl>http://www.sun.com</VendorUrl>
2125 </Section> */
2126 xml::ElementNode *pelmAnnotationSection;
2127 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2128 {
2129 // <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
2130 pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
2131 pelmAnnotationSection->setAttribute("xsi:type", "ovf:ProductSection_Type");
2132 }
2133 else
2134 pelmAnnotationSection = pelmVirtualSystem->createChild("ProductSection");
2135
2136 pelmAnnotationSection->createChild("Info")->addContent("Meta-information about the installed software");
2137 if (fProduct)
2138 pelmAnnotationSection->createChild("Product")->addContent(llProduct.front()->strVbox);
2139 if (fVendor)
2140 pelmAnnotationSection->createChild("Vendor")->addContent(llVendor.front()->strVbox);
2141 if (fVersion)
2142 pelmAnnotationSection->createChild("Version")->addContent(llVersion.front()->strVbox);
2143 if (fProductUrl)
2144 pelmAnnotationSection->createChild("ProductUrl")->addContent(llProductUrl.front()->strVbox);
2145 if (fVendorUrl)
2146 pelmAnnotationSection->createChild("VendorUrl")->addContent(llVendorUrl.front()->strVbox);
2147 }
2148
2149 // description
2150 std::list<VirtualSystemDescriptionEntry*> llDescription = vsdescThis->findByType(VirtualSystemDescriptionType_Description);
2151 if (llDescription.size() &&
2152 !llDescription.front()->strVbox.isEmpty())
2153 {
2154 /* <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
2155 <Info>A human-readable annotation</Info>
2156 <Annotation>Plan 9</Annotation>
2157 </Section> */
2158 xml::ElementNode *pelmAnnotationSection;
2159 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2160 {
2161 // <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
2162 pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
2163 pelmAnnotationSection->setAttribute("xsi:type", "ovf:AnnotationSection_Type");
2164 }
2165 else
2166 pelmAnnotationSection = pelmVirtualSystem->createChild("AnnotationSection");
2167
2168 pelmAnnotationSection->createChild("Info")->addContent("A human-readable annotation");
2169 pelmAnnotationSection->createChild("Annotation")->addContent(llDescription.front()->strVbox);
2170 }
2171
2172 // license
2173 std::list<VirtualSystemDescriptionEntry*> llLicense = vsdescThis->findByType(VirtualSystemDescriptionType_License);
2174 if (llLicense.size() &&
2175 !llLicense.front()->strVbox.isEmpty())
2176 {
2177 /* <EulaSection>
2178 <Info ovf:msgid="6">License agreement for the Virtual System.</Info>
2179 <License ovf:msgid="1">License terms can go in here.</License>
2180 </EulaSection> */
2181 xml::ElementNode *pelmEulaSection;
2182 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2183 {
2184 pelmEulaSection = pelmVirtualSystem->createChild("Section");
2185 pelmEulaSection->setAttribute("xsi:type", "ovf:EulaSection_Type");
2186 }
2187 else
2188 pelmEulaSection = pelmVirtualSystem->createChild("EulaSection");
2189
2190 pelmEulaSection->createChild("Info")->addContent("License agreement for the virtual system");
2191 pelmEulaSection->createChild("License")->addContent(llLicense.front()->strVbox);
2192 }
2193
2194 // operating system
2195 std::list<VirtualSystemDescriptionEntry*> llOS = vsdescThis->findByType(VirtualSystemDescriptionType_OS);
2196 if (llOS.size() != 1)
2197 throw setError(VBOX_E_NOT_SUPPORTED,
2198 tr("Missing OS type"));
2199 /* <OperatingSystemSection ovf:id="82">
2200 <Info>Guest Operating System</Info>
2201 <Description>Linux 2.6.x</Description>
2202 </OperatingSystemSection> */
2203 xml::ElementNode *pelmOperatingSystemSection;
2204 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2205 {
2206 pelmOperatingSystemSection = pelmVirtualSystem->createChild("Section");
2207 pelmOperatingSystemSection->setAttribute("xsi:type", "ovf:OperatingSystemSection_Type");
2208 }
2209 else
2210 pelmOperatingSystemSection = pelmVirtualSystem->createChild("OperatingSystemSection");
2211
2212 pelmOperatingSystemSection->setAttribute("ovf:id", llOS.front()->strOvf);
2213 pelmOperatingSystemSection->createChild("Info")->addContent("The kind of installed guest operating system");
2214 Utf8Str strOSDesc;
2215 convertCIMOSType2VBoxOSType(strOSDesc, (CIMOSType_T)llOS.front()->strOvf.toInt32(), "");
2216 pelmOperatingSystemSection->createChild("Description")->addContent(strOSDesc);
2217
2218 // <VirtualHardwareSection ovf:id="hw1" ovf:transport="iso">
2219 xml::ElementNode *pelmVirtualHardwareSection;
2220 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2221 {
2222 // <Section xsi:type="ovf:VirtualHardwareSection_Type">
2223 pelmVirtualHardwareSection = pelmVirtualSystem->createChild("Section");
2224 pelmVirtualHardwareSection->setAttribute("xsi:type", "ovf:VirtualHardwareSection_Type");
2225 }
2226 else
2227 pelmVirtualHardwareSection = pelmVirtualSystem->createChild("VirtualHardwareSection");
2228
2229 pelmVirtualHardwareSection->createChild("Info")->addContent("Virtual hardware requirements for a virtual machine");
2230
2231 /* <System>
2232 <vssd:Description>Description of the virtual hardware section.</vssd:Description>
2233 <vssd:ElementName>vmware</vssd:ElementName>
2234 <vssd:InstanceID>1</vssd:InstanceID>
2235 <vssd:VirtualSystemIdentifier>MyLampService</vssd:VirtualSystemIdentifier>
2236 <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
2237 </System> */
2238 xml::ElementNode *pelmSystem = pelmVirtualHardwareSection->createChild("System");
2239
2240 pelmSystem->createChild("vssd:ElementName")->addContent("Virtual Hardware Family"); // required OVF 1.0
2241
2242 // <vssd:InstanceId>0</vssd:InstanceId>
2243 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2244 pelmSystem->createChild("vssd:InstanceId")->addContent("0");
2245 else // capitalization changed...
2246 pelmSystem->createChild("vssd:InstanceID")->addContent("0");
2247
2248 // <vssd:VirtualSystemIdentifier>VAtest</vssd:VirtualSystemIdentifier>
2249 pelmSystem->createChild("vssd:VirtualSystemIdentifier")->addContent(strVMName);
2250 // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
2251 const char *pcszHardware = "virtualbox-2.2";
2252 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2253 // pretend to be vmware compatible then
2254 pcszHardware = "vmx-6";
2255 pelmSystem->createChild("vssd:VirtualSystemType")->addContent(pcszHardware);
2256
2257 // loop thru all description entries twice; once to write out all
2258 // devices _except_ disk images, and a second time to assign the
2259 // disk images; this is because disk images need to reference
2260 // IDE controllers, and we can't know their instance IDs without
2261 // assigning them first
2262
2263 uint32_t idIDEController = 0;
2264 int32_t lIDEControllerIndex = 0;
2265 uint32_t idSATAController = 0;
2266 int32_t lSATAControllerIndex = 0;
2267 uint32_t idSCSIController = 0;
2268 int32_t lSCSIControllerIndex = 0;
2269
2270 uint32_t ulInstanceID = 1;
2271
2272 for (size_t uLoop = 1;
2273 uLoop <= 2;
2274 ++uLoop)
2275 {
2276 int32_t lIndexThis = 0;
2277 list<VirtualSystemDescriptionEntry>::const_iterator itD;
2278 for (itD = vsdescThis->m->llDescriptions.begin();
2279 itD != vsdescThis->m->llDescriptions.end();
2280 ++itD, ++lIndexThis)
2281 {
2282 const VirtualSystemDescriptionEntry &desc = *itD;
2283
2284 OVFResourceType_T type = (OVFResourceType_T)0; // if this becomes != 0 then we do stuff
2285 Utf8Str strResourceSubType;
2286
2287 Utf8Str strDescription; // results in <rasd:Description>...</rasd:Description> block
2288 Utf8Str strCaption; // results in <rasd:Caption>...</rasd:Caption> block
2289
2290 uint32_t ulParent = 0;
2291
2292 int32_t lVirtualQuantity = -1;
2293 Utf8Str strAllocationUnits;
2294
2295 int32_t lAddress = -1;
2296 int32_t lBusNumber = -1;
2297 int32_t lAddressOnParent = -1;
2298
2299 int32_t lAutomaticAllocation = -1; // 0 means "false", 1 means "true"
2300 Utf8Str strConnection; // results in <rasd:Connection>...</rasd:Connection> block
2301 Utf8Str strHostResource;
2302
2303 uint64_t uTemp;
2304
2305 switch (desc.type)
2306 {
2307 case VirtualSystemDescriptionType_CPU:
2308 /* <Item>
2309 <rasd:Caption>1 virtual CPU</rasd:Caption>
2310 <rasd:Description>Number of virtual CPUs</rasd:Description>
2311 <rasd:ElementName>virtual CPU</rasd:ElementName>
2312 <rasd:InstanceID>1</rasd:InstanceID>
2313 <rasd:ResourceType>3</rasd:ResourceType>
2314 <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
2315 </Item> */
2316 if (uLoop == 1)
2317 {
2318 strDescription = "Number of virtual CPUs";
2319 type = OVFResourceType_Processor; // 3
2320 desc.strVbox.toInt(uTemp);
2321 lVirtualQuantity = uTemp;
2322 strCaption = Utf8StrFmt("%d virtual CPU", lVirtualQuantity); // without this ovftool won't eat the item
2323 }
2324 break;
2325
2326 case VirtualSystemDescriptionType_Memory:
2327 /* <Item>
2328 <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
2329 <rasd:Caption>256 MB of memory</rasd:Caption>
2330 <rasd:Description>Memory Size</rasd:Description>
2331 <rasd:ElementName>Memory</rasd:ElementName>
2332 <rasd:InstanceID>2</rasd:InstanceID>
2333 <rasd:ResourceType>4</rasd:ResourceType>
2334 <rasd:VirtualQuantity>256</rasd:VirtualQuantity>
2335 </Item> */
2336 if (uLoop == 1)
2337 {
2338 strDescription = "Memory Size";
2339 type = OVFResourceType_Memory; // 4
2340 desc.strVbox.toInt(uTemp);
2341 lVirtualQuantity = (int32_t)(uTemp / _1M);
2342 strAllocationUnits = "MegaBytes";
2343 strCaption = Utf8StrFmt("%d MB of memory", lVirtualQuantity); // without this ovftool won't eat the item
2344 }
2345 break;
2346
2347 case VirtualSystemDescriptionType_HardDiskControllerIDE:
2348 /* <Item>
2349 <rasd:Caption>ideController1</rasd:Caption>
2350 <rasd:Description>IDE Controller</rasd:Description>
2351 <rasd:InstanceId>5</rasd:InstanceId>
2352 <rasd:ResourceType>5</rasd:ResourceType>
2353 <rasd:Address>1</rasd:Address>
2354 <rasd:BusNumber>1</rasd:BusNumber>
2355 </Item> */
2356 if (uLoop == 1)
2357 {
2358 strDescription = "IDE Controller";
2359 strCaption = "ideController0";
2360 type = OVFResourceType_IDEController; // 5
2361 strResourceSubType = desc.strVbox;
2362 // it seems that OVFTool always writes these two, and since we can only
2363 // have one IDE controller, we'll use this as well
2364 lAddress = 1;
2365 lBusNumber = 1;
2366
2367 // remember this ID
2368 idIDEController = ulInstanceID;
2369 lIDEControllerIndex = lIndexThis;
2370 }
2371 break;
2372
2373 case VirtualSystemDescriptionType_HardDiskControllerSATA:
2374 /* <Item>
2375 <rasd:Caption>sataController0</rasd:Caption>
2376 <rasd:Description>SATA Controller</rasd:Description>
2377 <rasd:InstanceId>4</rasd:InstanceId>
2378 <rasd:ResourceType>20</rasd:ResourceType>
2379 <rasd:ResourceSubType>ahci</rasd:ResourceSubType>
2380 <rasd:Address>0</rasd:Address>
2381 <rasd:BusNumber>0</rasd:BusNumber>
2382 </Item>
2383 */
2384 if (uLoop == 1)
2385 {
2386 strDescription = "SATA Controller";
2387 strCaption = "sataController0";
2388 type = OVFResourceType_OtherStorageDevice; // 20
2389 // it seems that OVFTool always writes these two, and since we can only
2390 // have one SATA controller, we'll use this as well
2391 lAddress = 0;
2392 lBusNumber = 0;
2393
2394 if ( desc.strVbox.isEmpty() // AHCI is the default in VirtualBox
2395 || (!desc.strVbox.compare("ahci", Utf8Str::CaseInsensitive))
2396 )
2397 strResourceSubType = "AHCI";
2398 else
2399 throw setError(VBOX_E_NOT_SUPPORTED,
2400 tr("Invalid config string \"%s\" in SATA controller"), desc.strVbox.c_str());
2401
2402 // remember this ID
2403 idSATAController = ulInstanceID;
2404 lSATAControllerIndex = lIndexThis;
2405 }
2406 break;
2407
2408 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
2409 /* <Item>
2410 <rasd:Caption>scsiController0</rasd:Caption>
2411 <rasd:Description>SCSI Controller</rasd:Description>
2412 <rasd:InstanceId>4</rasd:InstanceId>
2413 <rasd:ResourceType>6</rasd:ResourceType>
2414 <rasd:ResourceSubType>buslogic</rasd:ResourceSubType>
2415 <rasd:Address>0</rasd:Address>
2416 <rasd:BusNumber>0</rasd:BusNumber>
2417 </Item>
2418 */
2419 if (uLoop == 1)
2420 {
2421 strDescription = "SCSI Controller";
2422 strCaption = "scsiController0";
2423 type = OVFResourceType_ParallelSCSIHBA; // 6
2424 // it seems that OVFTool always writes these two, and since we can only
2425 // have one SATA controller, we'll use this as well
2426 lAddress = 0;
2427 lBusNumber = 0;
2428
2429 if ( desc.strVbox.isEmpty() // LsiLogic is the default in VirtualBox
2430 || (!desc.strVbox.compare("lsilogic", Utf8Str::CaseInsensitive))
2431 )
2432 strResourceSubType = "lsilogic";
2433 else if (!desc.strVbox.compare("buslogic", Utf8Str::CaseInsensitive))
2434 strResourceSubType = "buslogic";
2435 else
2436 throw setError(VBOX_E_NOT_SUPPORTED,
2437 tr("Invalid config string \"%s\" in SCSI controller"), desc.strVbox.c_str());
2438
2439 // remember this ID
2440 idSCSIController = ulInstanceID;
2441 lSCSIControllerIndex = lIndexThis;
2442 }
2443 break;
2444
2445 case VirtualSystemDescriptionType_HardDiskImage:
2446 /* <Item>
2447 <rasd:Caption>disk1</rasd:Caption>
2448 <rasd:InstanceId>8</rasd:InstanceId>
2449 <rasd:ResourceType>17</rasd:ResourceType>
2450 <rasd:HostResource>/disk/vmdisk1</rasd:HostResource>
2451 <rasd:Parent>4</rasd:Parent>
2452 <rasd:AddressOnParent>0</rasd:AddressOnParent>
2453 </Item> */
2454 if (uLoop == 2)
2455 {
2456 Utf8Str strDiskID = Utf8StrFmt("vmdisk%RI32", ++cDisks);
2457
2458 strDescription = "Disk Image";
2459 strCaption = Utf8StrFmt("disk%RI32", cDisks); // this is not used for anything else
2460 type = OVFResourceType_HardDisk; // 17
2461
2462 // the following references the "<Disks>" XML block
2463 strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str());
2464
2465 // controller=<index>;channel=<c>
2466 size_t pos1 = desc.strExtraConfig.find("controller=");
2467 size_t pos2 = desc.strExtraConfig.find("channel=");
2468 if (pos1 != Utf8Str::npos)
2469 {
2470 int32_t lControllerIndex = -1;
2471 RTStrToInt32Ex(desc.strExtraConfig.c_str() + pos1 + 11, NULL, 0, &lControllerIndex);
2472 if (lControllerIndex == lIDEControllerIndex)
2473 ulParent = idIDEController;
2474 else if (lControllerIndex == lSCSIControllerIndex)
2475 ulParent = idSCSIController;
2476 else if (lControllerIndex == lSATAControllerIndex)
2477 ulParent = idSATAController;
2478 }
2479 if (pos2 != Utf8Str::npos)
2480 RTStrToInt32Ex(desc.strExtraConfig.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
2481
2482 if ( !ulParent
2483 || lAddressOnParent == -1
2484 )
2485 throw setError(VBOX_E_NOT_SUPPORTED,
2486 tr("Missing or bad extra config string in hard disk image: \"%s\""), desc.strExtraConfig.c_str());
2487
2488 mapDisks[strDiskID] = &desc;
2489 }
2490 break;
2491
2492 case VirtualSystemDescriptionType_Floppy:
2493 if (uLoop == 1)
2494 {
2495 strDescription = "Floppy Drive";
2496 strCaption = "floppy0"; // this is what OVFTool writes
2497 type = OVFResourceType_FloppyDrive; // 14
2498 lAutomaticAllocation = 0;
2499 lAddressOnParent = 0; // this is what OVFTool writes
2500 }
2501 break;
2502
2503 case VirtualSystemDescriptionType_CDROM:
2504 if (uLoop == 2)
2505 {
2506 // we can't have a CD without an IDE controller
2507 if (!idIDEController)
2508 throw setError(VBOX_E_NOT_SUPPORTED,
2509 tr("Can't have CD-ROM without IDE controller"));
2510
2511 strDescription = "CD-ROM Drive";
2512 strCaption = "cdrom1"; // this is what OVFTool writes
2513 type = OVFResourceType_CDDrive; // 15
2514 lAutomaticAllocation = 1;
2515 ulParent = idIDEController;
2516 lAddressOnParent = 0; // this is what OVFTool writes
2517 }
2518 break;
2519
2520 case VirtualSystemDescriptionType_NetworkAdapter:
2521 /* <Item>
2522 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
2523 <rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption>
2524 <rasd:Connection>VM Network</rasd:Connection>
2525 <rasd:ElementName>VM network</rasd:ElementName>
2526 <rasd:InstanceID>3</rasd:InstanceID>
2527 <rasd:ResourceType>10</rasd:ResourceType>
2528 </Item> */
2529 if (uLoop == 1)
2530 {
2531 lAutomaticAllocation = 1;
2532 strCaption = Utf8StrFmt("Ethernet adapter on '%s'", desc.strOvf.c_str());
2533 type = OVFResourceType_EthernetAdapter; // 10
2534 /* Set the hardware type to something useful.
2535 * To be compatible with vmware & others we set
2536 * PCNet32 for our PCNet types & E1000 for the
2537 * E1000 cards. */
2538 switch (desc.strVbox.toInt32())
2539 {
2540 case NetworkAdapterType_Am79C970A:
2541 case NetworkAdapterType_Am79C973: strResourceSubType = "PCNet32"; break;
2542#ifdef VBOX_WITH_E1000
2543 case NetworkAdapterType_I82540EM:
2544 case NetworkAdapterType_I82545EM:
2545 case NetworkAdapterType_I82543GC: strResourceSubType = "E1000"; break;
2546#endif /* VBOX_WITH_E1000 */
2547 }
2548 strConnection = desc.strOvf;
2549
2550 mapNetworks[desc.strOvf] = true;
2551 }
2552 break;
2553
2554 case VirtualSystemDescriptionType_USBController:
2555 /* <Item ovf:required="false">
2556 <rasd:Caption>usb</rasd:Caption>
2557 <rasd:Description>USB Controller</rasd:Description>
2558 <rasd:InstanceId>3</rasd:InstanceId>
2559 <rasd:ResourceType>23</rasd:ResourceType>
2560 <rasd:Address>0</rasd:Address>
2561 <rasd:BusNumber>0</rasd:BusNumber>
2562 </Item> */
2563 if (uLoop == 1)
2564 {
2565 strDescription = "USB Controller";
2566 strCaption = "usb";
2567 type = OVFResourceType_USBController; // 23
2568 lAddress = 0; // this is what OVFTool writes
2569 lBusNumber = 0; // this is what OVFTool writes
2570 }
2571 break;
2572
2573 case VirtualSystemDescriptionType_SoundCard:
2574 /* <Item ovf:required="false">
2575 <rasd:Caption>sound</rasd:Caption>
2576 <rasd:Description>Sound Card</rasd:Description>
2577 <rasd:InstanceId>10</rasd:InstanceId>
2578 <rasd:ResourceType>35</rasd:ResourceType>
2579 <rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
2580 <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
2581 <rasd:AddressOnParent>3</rasd:AddressOnParent>
2582 </Item> */
2583 if (uLoop == 1)
2584 {
2585 strDescription = "Sound Card";
2586 strCaption = "sound";
2587 type = OVFResourceType_SoundCard; // 35
2588 strResourceSubType = desc.strOvf; // e.g. ensoniq1371
2589 lAutomaticAllocation = 0;
2590 lAddressOnParent = 3; // what gives? this is what OVFTool writes
2591 }
2592 break;
2593 }
2594
2595 if (type)
2596 {
2597 xml::ElementNode *pItem;
2598
2599 pItem = pelmVirtualHardwareSection->createChild("Item");
2600
2601 // NOTE: do not change the order of these items without good reason! While we don't care
2602 // about ordering, VMware's ovftool does and fails if the items are not written in
2603 // exactly this order, as stupid as it seems.
2604
2605 if (!strCaption.isEmpty())
2606 {
2607 pItem->createChild("rasd:Caption")->addContent(strCaption);
2608 if (pTask->enFormat == TaskExportOVF::OVF_1_0)
2609 pItem->createChild("rasd:ElementName")->addContent(strCaption);
2610 }
2611
2612 if (!strDescription.isEmpty())
2613 pItem->createChild("rasd:Description")->addContent(strDescription);
2614
2615 // <rasd:InstanceID>1</rasd:InstanceID>
2616 xml::ElementNode *pelmInstanceID;
2617 if (pTask->enFormat == TaskExportOVF::OVF_0_9)
2618 pelmInstanceID = pItem->createChild("rasd:InstanceId");
2619 else
2620 pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed...
2621 pelmInstanceID->addContent(Utf8StrFmt("%d", ulInstanceID++));
2622
2623 // <rasd:ResourceType>3</rasd:ResourceType>
2624 pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type));
2625 if (!strResourceSubType.isEmpty())
2626 pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType);
2627
2628 if (!strHostResource.isEmpty())
2629 pItem->createChild("rasd:HostResource")->addContent(strHostResource);
2630
2631 if (!strAllocationUnits.isEmpty())
2632 pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits);
2633
2634 // <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
2635 if (lVirtualQuantity != -1)
2636 pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity));
2637
2638 if (lAutomaticAllocation != -1)
2639 pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" );
2640
2641 if (!strConnection.isEmpty())
2642 pItem->createChild("rasd:Connection")->addContent(strConnection);
2643
2644 if (lAddress != -1)
2645 pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress));
2646
2647 if (lBusNumber != -1)
2648 if (pTask->enFormat == TaskExportOVF::OVF_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool compatibility
2649 pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber));
2650
2651 if (ulParent)
2652 pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent));
2653 if (lAddressOnParent != -1)
2654 pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent));
2655 }
2656 }
2657 } // for (size_t uLoop = 0; ...
2658 }
2659
2660 // finally, fill in the network section we set up empty above according
2661 // to the networks we found with the hardware items
2662 map<Utf8Str, bool>::const_iterator itN;
2663 for (itN = mapNetworks.begin();
2664 itN != mapNetworks.end();
2665 ++itN)
2666 {
2667 const Utf8Str &strNetwork = itN->first;
2668 xml::ElementNode *pelmNetwork = pelmNetworkSection->createChild("Network");
2669 pelmNetwork->setAttribute("ovf:name", strNetwork.c_str());
2670 pelmNetwork->createChild("Description")->addContent("Logical network used by this appliance.");
2671 }
2672
2673 map<Utf8Str, const VirtualSystemDescriptionEntry*>::const_iterator itS;
2674 uint32_t ulFile = 1;
2675 for (itS = mapDisks.begin();
2676 itS != mapDisks.end();
2677 ++itS)
2678 {
2679 const Utf8Str &strDiskID = itS->first;
2680 const VirtualSystemDescriptionEntry *pDiskEntry = itS->second;
2681
2682 // source path: where the VBox image is
2683 const Utf8Str &strSrcFilePath = pDiskEntry->strVbox;
2684 Bstr bstrSrcFilePath(strSrcFilePath);
2685 if (!RTPathExists(strSrcFilePath.c_str()))
2686 /* This isn't allowed */
2687 throw setError(VBOX_E_FILE_ERROR,
2688 tr("Source virtual disk image file '%s' doesn't exist"),
2689 strSrcFilePath.c_str());
2690
2691 // output filename
2692 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf;
2693 // target path needs to be composed from where the output OVF is
2694 Utf8Str strTargetFilePath(pTask->locInfo.strPath);
2695 strTargetFilePath.stripFilename();
2696 strTargetFilePath.append("/");
2697 strTargetFilePath.append(strTargetFileNameOnly);
2698
2699 // clone the disk:
2700 ComPtr<IHardDisk> pSourceDisk;
2701 ComPtr<IHardDisk> pTargetDisk;
2702 ComPtr<IProgress> pProgress2;
2703
2704 Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw()));
2705 rc = mVirtualBox->FindHardDisk(bstrSrcFilePath, pSourceDisk.asOutParam());
2706 if (FAILED(rc)) throw rc;
2707
2708 /* We are always exporting to vmdfk stream optimized for now */
2709 Bstr bstrSrcFormat = L"VMDK";
2710
2711 // create a new hard disk interface for the destination disk image
2712 Log(("Creating target disk \"%s\"\n", strTargetFilePath.raw()));
2713 rc = mVirtualBox->CreateHardDisk(bstrSrcFormat, Bstr(strTargetFilePath), pTargetDisk.asOutParam());
2714 if (FAILED(rc)) throw rc;
2715
2716 // the target disk is now registered and needs to be removed again,
2717 // both after successful cloning or if anything goes bad!
2718 try
2719 {
2720 // create a flat copy of the source disk image
2721 rc = pSourceDisk->CloneTo(pTargetDisk, HardDiskVariant_VmdkStreamOptimized, NULL, pProgress2.asOutParam());
2722 if (FAILED(rc)) throw rc;
2723
2724 // advance to the next operation
2725 if (!pTask->progress.isNull())
2726 pTask->progress->setNextOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()),
2727 pDiskEntry->ulSizeMB); // operation's weight, as set up with the IProgress originally);
2728
2729 // now wait for the background disk operation to complete; this throws HRESULTs on error
2730 waitForAsyncProgress(pTask->progress, pProgress2);
2731 }
2732 catch (HRESULT rc3)
2733 {
2734 // upon error after registering, close the disk or
2735 // it'll stick in the registry forever
2736 pTargetDisk->Close();
2737 throw;
2738 }
2739
2740 // we need the following for the XML
2741 uint64_t cbFile = 0; // actual file size
2742 rc = pTargetDisk->COMGETTER(Size)(&cbFile);
2743 if (FAILED(rc)) throw rc;
2744
2745 ULONG64 cbCapacity = 0; // size reported to guest
2746 rc = pTargetDisk->COMGETTER(LogicalSize)(&cbCapacity);
2747 if (FAILED(rc)) throw rc;
2748 // capacity is reported in megabytes, so...
2749 cbCapacity *= _1M;
2750
2751 // upon success, close the disk as well
2752 rc = pTargetDisk->Close();
2753 if (FAILED(rc)) throw rc;
2754
2755 // now handle the XML for the disk:
2756 Utf8StrFmt strFileRef("file%RI32", ulFile++);
2757 // <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/>
2758 xml::ElementNode *pelmFile = pelmReferences->createChild("File");
2759 pelmFile->setAttribute("ovf:href", strTargetFileNameOnly);
2760 pelmFile->setAttribute("ovf:id", strFileRef);
2761 pelmFile->setAttribute("ovf:size", Utf8StrFmt("%RI64", cbFile).c_str());
2762
2763 // add disk to XML Disks section
2764 // <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/specifications/vmdk.html#sparse"/>
2765 xml::ElementNode *pelmDisk = pelmDiskSection->createChild("Disk");
2766 pelmDisk->setAttribute("ovf:capacity", Utf8StrFmt("%RI64", cbCapacity).c_str());
2767 pelmDisk->setAttribute("ovf:diskId", strDiskID);
2768 pelmDisk->setAttribute("ovf:fileRef", strFileRef);
2769 pelmDisk->setAttribute("ovf:format", "http://www.vmware.com/specifications/vmdk.html#sparse"); // must be sparse or ovftool chokes
2770 }
2771
2772 // now go write the XML
2773 xml::XmlFileWriter writer(doc);
2774 writer.write(pTask->locInfo.strPath.c_str());
2775 }
2776 catch(xml::Error &x)
2777 {
2778 rc = setError(VBOX_E_FILE_ERROR,
2779 x.what());
2780 }
2781 catch(HRESULT aRC)
2782 {
2783 rc = aRC;
2784 }
2785
2786 pTask->rc = rc;
2787
2788 if (!pTask->progress.isNull())
2789 pTask->progress->notifyComplete(rc);
2790
2791 LogFlowFunc(("rc=%Rhrc\n", rc));
2792 LogFlowFuncLeave();
2793
2794 return VINF_SUCCESS;
2795}
2796
2797int Appliance::writeS3(TaskExportOVF *pTask)
2798{
2799 LogFlowFuncEnter();
2800 LogFlowFunc(("Appliance %p\n", this));
2801
2802 AutoCaller autoCaller(this);
2803 CheckComRCReturnRC(autoCaller.rc());
2804
2805 HRESULT rc = S_OK;
2806
2807 AutoWriteLock appLock(this);
2808
2809 int vrc = VINF_SUCCESS;
2810 RTS3 hS3 = NIL_RTS3;
2811 char szOSTmpDir[RTPATH_MAX];
2812 RTPathTemp(szOSTmpDir, sizeof(szOSTmpDir));
2813 /* The template for the temporary directory created below */
2814 char *pszTmpDir;
2815 RTStrAPrintf(&pszTmpDir, "%s"RTPATH_SLASH_STR"vbox-ovf-XXXXXX", szOSTmpDir);
2816 list< pair<Utf8Str, ULONG> > filesList;
2817
2818 // todo:
2819 // - usable error codes
2820 // - seems snapshot filenames are problematic {uuid}.vdi
2821 try
2822 {
2823 /* Extract the bucket */
2824 Utf8Str tmpPath = pTask->locInfo.strPath;
2825 Utf8Str bucket;
2826 parseBucket(tmpPath, bucket);
2827
2828 /* We need a temporary directory which we can put the OVF file & all
2829 * disk images in */
2830 vrc = RTDirCreateTemp(pszTmpDir);
2831 if (RT_FAILURE(rc))
2832 throw setError(VBOX_E_FILE_ERROR,
2833 tr("Cannot create temporary directory '%s'"), pszTmpDir);
2834
2835 /* The temporary name of the target OVF file */
2836 Utf8StrFmt strTmpOvf("%s/%s", pszTmpDir, RTPathFilename(tmpPath));
2837
2838 /* Prepare the temporary writing of the OVF */
2839 ComObjPtr<Progress> progress;
2840 /* Create a temporary file based location info for the sub task */
2841 LocationInfo li;
2842 li.strPath = strTmpOvf;
2843 rc = writeImpl(pTask->enFormat, li, progress);
2844 if (FAILED(rc)) throw rc;
2845
2846 /* Unlock the appliance for the writing thread */
2847 appLock.unlock();
2848 /* Wait until the writing is done, but report the progress back to the
2849 caller */
2850 ComPtr<IProgress> progressInt(progress);
2851 waitForAsyncProgress(pTask->progress, progressInt); /* Any errors will be thrown */
2852
2853 /* Again lock the appliance for the next steps */
2854 appLock.lock();
2855
2856 vrc = RTPathExists(strTmpOvf.c_str()); /* Paranoid check */
2857 if(RT_FAILURE(vrc))
2858 throw setError(VBOX_E_FILE_ERROR,
2859 tr("Cannot find source file '%s'"), strTmpOvf.c_str());
2860 /* Add the OVF file */
2861 filesList.push_back(pair<Utf8Str, ULONG>(strTmpOvf, m->ulWeightPerOperation)); /* Use 1% of the total for the OVF file upload */
2862
2863 /* Now add every disks of every virtual system */
2864 list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
2865 for (it = m->virtualSystemDescriptions.begin();
2866 it != m->virtualSystemDescriptions.end();
2867 ++it)
2868 {
2869 ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
2870 std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
2871 std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
2872 for (itH = avsdeHDs.begin();
2873 itH != avsdeHDs.end();
2874 ++itH)
2875 {
2876 const Utf8Str &strTargetFileNameOnly = (*itH)->strOvf;
2877 /* Target path needs to be composed from where the output OVF is */
2878 Utf8Str strTargetFilePath(strTmpOvf);
2879 strTargetFilePath.stripFilename();
2880 strTargetFilePath.append("/");
2881 strTargetFilePath.append(strTargetFileNameOnly);
2882 vrc = RTPathExists(strTargetFilePath.c_str()); /* Paranoid check */
2883 if(RT_FAILURE(vrc))
2884 throw setError(VBOX_E_FILE_ERROR,
2885 tr("Cannot find source file '%s'"), strTargetFilePath.c_str());
2886 filesList.push_back(pair<Utf8Str, ULONG>(strTargetFilePath, (*itH)->ulSizeMB));
2887 }
2888 }
2889 /* Next we have to upload the OVF & all disk images */
2890 vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
2891 if(RT_FAILURE(vrc))
2892 throw setError(VBOX_E_IPRT_ERROR,
2893 tr("Cannot create S3 service handler"));
2894 RTS3SetProgressCallback(hS3, pTask->updateProgress, &pTask);
2895
2896 /* Upload all files */
2897 for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
2898 {
2899 const pair<Utf8Str, ULONG> &s = (*it1);
2900 char *pszFilename = RTPathFilename(s.first.c_str());
2901 /* Advance to the next operation */
2902 if (!pTask->progress.isNull())
2903 pTask->progress->setNextOperation(BstrFmt(tr("Uploading file '%s'"), pszFilename), s.second);
2904 vrc = RTS3PutKey(hS3, bucket.c_str(), pszFilename, s.first.c_str());
2905 if (RT_FAILURE(vrc))
2906 {
2907 if(vrc == VERR_S3_CANCELED)
2908 break;
2909 else if(vrc == VERR_S3_ACCESS_DENIED)
2910 throw setError(E_ACCESSDENIED,
2911 tr("Cannot upload file '%s' to S3 storage server (Access denied)"), pszFilename);
2912 else if(vrc == VERR_S3_NOT_FOUND)
2913 throw setError(VBOX_E_FILE_ERROR,
2914 tr("Cannot upload file '%s' to S3 storage server (File not found)"), pszFilename);
2915 else
2916 throw setError(VBOX_E_IPRT_ERROR,
2917 tr("Cannot upload file '%s' to S3 storage server (%Rrc)"), pszFilename, vrc);
2918 }
2919 }
2920 }
2921 catch(HRESULT aRC)
2922 {
2923 rc = aRC;
2924 }
2925 /* Cleanup */
2926 RTS3Destroy(hS3);
2927 /* Delete all files which where temporary created */
2928 for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
2929 {
2930 const char *pszFilePath = (*it1).first.c_str();
2931 if (RTPathExists(pszFilePath))
2932 {
2933 vrc = RTFileDelete(pszFilePath);
2934 if(RT_FAILURE(vrc))
2935 rc = setError(VBOX_E_FILE_ERROR,
2936 tr("Cannot delete file '%s' (%Rrc)"), pszFilePath, vrc);
2937 }
2938 }
2939 /* Delete the temporary directory */
2940 if (RTPathExists(pszTmpDir))
2941 {
2942 vrc = RTDirRemove(pszTmpDir);
2943 if(RT_FAILURE(vrc))
2944 rc = setError(VBOX_E_FILE_ERROR,
2945 tr("Cannot delete temporary directory '%s' (%Rrc)"), pszTmpDir, vrc);
2946 }
2947 if (pszTmpDir)
2948 RTStrFree(pszTmpDir);
2949
2950 pTask->rc = rc;
2951
2952 if (!pTask->progress.isNull())
2953 pTask->progress->notifyComplete(rc);
2954
2955 LogFlowFunc(("rc=%Rhrc\n", rc));
2956 LogFlowFuncLeave();
2957
2958 return VINF_SUCCESS;
2959}
2960
2961////////////////////////////////////////////////////////////////////////////////
2962//
2963// IAppliance public methods
2964//
2965////////////////////////////////////////////////////////////////////////////////
2966
2967/**
2968 * Public method implementation.
2969 * @param
2970 * @return
2971 */
2972STDMETHODIMP Appliance::COMGETTER(Path)(BSTR *aPath)
2973{
2974 if (!aPath)
2975 return E_POINTER;
2976
2977 AutoCaller autoCaller(this);
2978 CheckComRCReturnRC(autoCaller.rc());
2979
2980 AutoReadLock alock(this);
2981
2982 Bstr bstrPath(m->locInfo.strPath);
2983 bstrPath.cloneTo(aPath);
2984
2985 return S_OK;
2986}
2987
2988/**
2989 * Public method implementation.
2990 * @param
2991 * @return
2992 */
2993STDMETHODIMP Appliance::COMGETTER(Disks)(ComSafeArrayOut(BSTR, aDisks))
2994{
2995 CheckComArgOutSafeArrayPointerValid(aDisks);
2996
2997 AutoCaller autoCaller(this);
2998 CheckComRCReturnRC(autoCaller.rc());
2999
3000 AutoReadLock alock(this);
3001
3002 if (m->pReader) // OVFReader instantiated?
3003 {
3004 size_t c = m->pReader->m_mapDisks.size();
3005 com::SafeArray<BSTR> sfaDisks(c);
3006
3007 DiskImagesMap::const_iterator it;
3008 size_t i = 0;
3009 for (it = m->pReader->m_mapDisks.begin();
3010 it != m->pReader->m_mapDisks.end();
3011 ++it, ++i)
3012 {
3013 // create a string representing this disk
3014 const DiskImage &d = it->second;
3015 char *psz = NULL;
3016 RTStrAPrintf(&psz,
3017 "%s\t"
3018 "%RI64\t"
3019 "%RI64\t"
3020 "%s\t"
3021 "%s\t"
3022 "%RI64\t"
3023 "%RI64\t"
3024 "%s",
3025 d.strDiskId.c_str(),
3026 d.iCapacity,
3027 d.iPopulatedSize,
3028 d.strFormat.c_str(),
3029 d.strHref.c_str(),
3030 d.iSize,
3031 d.iChunkSize,
3032 d.strCompression.c_str());
3033 Utf8Str utf(psz);
3034 Bstr bstr(utf);
3035 // push to safearray
3036 bstr.cloneTo(&sfaDisks[i]);
3037 RTStrFree(psz);
3038 }
3039
3040 sfaDisks.detachTo(ComSafeArrayOutArg(aDisks));
3041 }
3042
3043 return S_OK;
3044}
3045
3046/**
3047 * Public method implementation.
3048 * @param
3049 * @return
3050 */
3051STDMETHODIMP Appliance::COMGETTER(VirtualSystemDescriptions)(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions))
3052{
3053 CheckComArgOutSafeArrayPointerValid(aVirtualSystemDescriptions);
3054
3055 AutoCaller autoCaller(this);
3056 CheckComRCReturnRC(autoCaller.rc());
3057
3058 AutoReadLock alock(this);
3059
3060 SafeIfaceArray<IVirtualSystemDescription> sfaVSD(m->virtualSystemDescriptions);
3061 sfaVSD.detachTo(ComSafeArrayOutArg(aVirtualSystemDescriptions));
3062
3063 return S_OK;
3064}
3065
3066/**
3067 * Public method implementation.
3068 * @param path
3069 * @return
3070 */
3071STDMETHODIMP Appliance::Read(IN_BSTR path, IProgress **aProgress)
3072{
3073 if (!path) return E_POINTER;
3074 CheckComArgOutPointerValid(aProgress);
3075
3076 AutoCaller autoCaller(this);
3077 CheckComRCReturnRC(autoCaller.rc());
3078
3079 AutoWriteLock alock(this);
3080
3081 if (m->pReader)
3082 {
3083 delete m->pReader;
3084 m->pReader = NULL;
3085 }
3086
3087 // see if we can handle this file; for now we insist it has an ".ovf" extension
3088 Utf8Str strPath (path);
3089 if (!strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
3090 return setError(VBOX_E_FILE_ERROR,
3091 tr("Appliance file must have .ovf extension"));
3092
3093 ComObjPtr<Progress> progress;
3094 HRESULT rc = S_OK;
3095 try
3096 {
3097 /* Parse all necessary info out of the URI */
3098 parseURI(strPath, m->locInfo);
3099 rc = readImpl(m->locInfo, progress);
3100 }
3101 catch (HRESULT aRC)
3102 {
3103 rc = aRC;
3104 }
3105
3106 if (SUCCEEDED(rc))
3107 /* Return progress to the caller */
3108 progress.queryInterfaceTo(aProgress);
3109
3110 return S_OK;
3111}
3112
3113/**
3114 * Public method implementation.
3115 * @return
3116 */
3117STDMETHODIMP Appliance::Interpret()
3118{
3119 // @todo:
3120 // - don't use COM methods but the methods directly (faster, but needs appropriate locking of that objects itself (s. HardDisk))
3121 // - Appropriate handle errors like not supported file formats
3122 AutoCaller autoCaller(this);
3123 CheckComRCReturnRC(autoCaller.rc());
3124
3125 AutoWriteLock(this);
3126
3127 HRESULT rc = S_OK;
3128
3129 /* Clear any previous virtual system descriptions */
3130 m->virtualSystemDescriptions.clear();
3131
3132 /* We need the default path for storing disk images */
3133 ComPtr<ISystemProperties> systemProps;
3134 rc = mVirtualBox->COMGETTER(SystemProperties)(systemProps.asOutParam());
3135 CheckComRCReturnRC(rc);
3136 Bstr bstrDefaultHardDiskLocation;
3137 rc = systemProps->COMGETTER(DefaultHardDiskFolder)(bstrDefaultHardDiskLocation.asOutParam());
3138 CheckComRCReturnRC(rc);
3139
3140 if (!m->pReader)
3141 return setError(E_FAIL,
3142 tr("Cannot interpret appliance without reading it first (call read() before interpret())"));
3143
3144 /* Try/catch so we can clean up on error */
3145 try
3146 {
3147 list<VirtualSystem>::const_iterator it;
3148 /* Iterate through all virtual systems */
3149 for (it = m->pReader->m_llVirtualSystems.begin();
3150 it != m->pReader->m_llVirtualSystems.end();
3151 ++it)
3152 {
3153 const VirtualSystem &vsysThis = *it;
3154
3155 ComObjPtr<VirtualSystemDescription> pNewDesc;
3156 rc = pNewDesc.createObject();
3157 CheckComRCThrowRC(rc);
3158 rc = pNewDesc->init();
3159 CheckComRCThrowRC(rc);
3160
3161 /* Guest OS type */
3162 Utf8Str strOsTypeVBox,
3163 strCIMOSType = Utf8StrFmt("%RI32", (uint32_t)vsysThis.cimos);
3164 convertCIMOSType2VBoxOSType(strOsTypeVBox, vsysThis.cimos, vsysThis.strCimosDesc);
3165 pNewDesc->addEntry(VirtualSystemDescriptionType_OS,
3166 "",
3167 strCIMOSType,
3168 strOsTypeVBox);
3169
3170 /* VM name */
3171 /* If the there isn't any name specified create a default one out of
3172 * the OS type */
3173 Utf8Str nameVBox = vsysThis.strName;
3174 if (nameVBox.isEmpty())
3175 nameVBox = strOsTypeVBox;
3176 searchUniqueVMName(nameVBox);
3177 pNewDesc->addEntry(VirtualSystemDescriptionType_Name,
3178 "",
3179 vsysThis.strName,
3180 nameVBox);
3181
3182 /* VM Product */
3183 if (!vsysThis.strProduct.isEmpty())
3184 pNewDesc->addEntry(VirtualSystemDescriptionType_Product,
3185 "",
3186 vsysThis.strProduct,
3187 vsysThis.strProduct);
3188
3189 /* VM Vendor */
3190 if (!vsysThis.strVendor.isEmpty())
3191 pNewDesc->addEntry(VirtualSystemDescriptionType_Vendor,
3192 "",
3193 vsysThis.strVendor,
3194 vsysThis.strVendor);
3195
3196 /* VM Version */
3197 if (!vsysThis.strVersion.isEmpty())
3198 pNewDesc->addEntry(VirtualSystemDescriptionType_Version,
3199 "",
3200 vsysThis.strVersion,
3201 vsysThis.strVersion);
3202
3203 /* VM ProductUrl */
3204 if (!vsysThis.strProductUrl.isEmpty())
3205 pNewDesc->addEntry(VirtualSystemDescriptionType_ProductUrl,
3206 "",
3207 vsysThis.strProductUrl,
3208 vsysThis.strProductUrl);
3209
3210 /* VM VendorUrl */
3211 if (!vsysThis.strVendorUrl.isEmpty())
3212 pNewDesc->addEntry(VirtualSystemDescriptionType_VendorUrl,
3213 "",
3214 vsysThis.strVendorUrl,
3215 vsysThis.strVendorUrl);
3216
3217 /* VM description */
3218 if (!vsysThis.strDescription.isEmpty())
3219 pNewDesc->addEntry(VirtualSystemDescriptionType_Description,
3220 "",
3221 vsysThis.strDescription,
3222 vsysThis.strDescription);
3223
3224 /* VM license */
3225 if (!vsysThis.strLicenseText.isEmpty())
3226 pNewDesc->addEntry(VirtualSystemDescriptionType_License,
3227 "",
3228 vsysThis.strLicenseText,
3229 vsysThis.strLicenseText);
3230
3231 /* Now that we know the OS type, get our internal defaults based on that. */
3232 ComPtr<IGuestOSType> pGuestOSType;
3233 rc = mVirtualBox->GetGuestOSType(Bstr(strOsTypeVBox), pGuestOSType.asOutParam());
3234 CheckComRCThrowRC(rc);
3235
3236 /* CPU count */
3237 ULONG cpuCountVBox = vsysThis.cCPUs;
3238 /* Check for the constrains */
3239 if (cpuCountVBox > SchemaDefs::MaxCPUCount)
3240 {
3241 addWarning(tr("The virtual system \"%s\" claims support for %u CPU's, but VirtualBox has support for max %u CPU's only."),
3242 vsysThis.strName.c_str(), cpuCountVBox, SchemaDefs::MaxCPUCount);
3243 cpuCountVBox = SchemaDefs::MaxCPUCount;
3244 }
3245 if (vsysThis.cCPUs == 0)
3246 cpuCountVBox = 1;
3247 pNewDesc->addEntry(VirtualSystemDescriptionType_CPU,
3248 "",
3249 Utf8StrFmt("%RI32", (uint32_t)vsysThis.cCPUs),
3250 Utf8StrFmt("%RI32", (uint32_t)cpuCountVBox));
3251
3252 /* RAM */
3253 uint64_t ullMemSizeVBox = vsysThis.ullMemorySize / _1M;
3254 /* Check for the constrains */
3255 if (ullMemSizeVBox != 0 &&
3256 (ullMemSizeVBox < MM_RAM_MIN_IN_MB ||
3257 ullMemSizeVBox > MM_RAM_MAX_IN_MB))
3258 {
3259 addWarning(tr("The virtual system \"%s\" claims support for %llu MB RAM size, but VirtualBox has support for min %u & max %u MB RAM size only."),
3260 vsysThis.strName.c_str(), ullMemSizeVBox, MM_RAM_MIN_IN_MB, MM_RAM_MAX_IN_MB);
3261 ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, MM_RAM_MIN_IN_MB), MM_RAM_MAX_IN_MB);
3262 }
3263 if (vsysThis.ullMemorySize == 0)
3264 {
3265 /* If the RAM of the OVF is zero, use our predefined values */
3266 ULONG memSizeVBox2;
3267 rc = pGuestOSType->COMGETTER(RecommendedRAM)(&memSizeVBox2);
3268 CheckComRCThrowRC(rc);
3269 /* VBox stores that in MByte */
3270 ullMemSizeVBox = (uint64_t)memSizeVBox2;
3271 }
3272 pNewDesc->addEntry(VirtualSystemDescriptionType_Memory,
3273 "",
3274 Utf8StrFmt("%RI64", (uint64_t)vsysThis.ullMemorySize),
3275 Utf8StrFmt("%RI64", (uint64_t)ullMemSizeVBox));
3276
3277 /* Audio */
3278 if (!vsysThis.strSoundCardType.isEmpty())
3279 /* Currently we set the AC97 always.
3280 @todo: figure out the hardware which could be possible */
3281 pNewDesc->addEntry(VirtualSystemDescriptionType_SoundCard,
3282 "",
3283 vsysThis.strSoundCardType,
3284 Utf8StrFmt("%RI32", (uint32_t)AudioControllerType_AC97));
3285
3286#ifdef VBOX_WITH_USB
3287 /* USB Controller */
3288 if (vsysThis.fHasUsbController)
3289 pNewDesc->addEntry(VirtualSystemDescriptionType_USBController, "", "", "");
3290#endif /* VBOX_WITH_USB */
3291
3292 /* Network Controller */
3293 size_t cEthernetAdapters = vsysThis.llEthernetAdapters.size();
3294 if (cEthernetAdapters > 0)
3295 {
3296 /* Check for the constrains */
3297 if (cEthernetAdapters > SchemaDefs::NetworkAdapterCount)
3298 addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox has support for max %u network adapter only."),
3299 vsysThis.strName.c_str(), cEthernetAdapters, SchemaDefs::NetworkAdapterCount);
3300
3301 /* Get the default network adapter type for the selected guest OS */
3302 NetworkAdapterType_T defaultAdapterVBox = NetworkAdapterType_Am79C970A;
3303 rc = pGuestOSType->COMGETTER(AdapterType)(&defaultAdapterVBox);
3304 CheckComRCThrowRC(rc);
3305
3306 EthernetAdaptersList::const_iterator itEA;
3307 /* Iterate through all abstract networks. We support 8 network
3308 * adapters at the maximum, so the first 8 will be added only. */
3309 size_t a = 0;
3310 for (itEA = vsysThis.llEthernetAdapters.begin();
3311 itEA != vsysThis.llEthernetAdapters.end() && a < SchemaDefs::NetworkAdapterCount;
3312 ++itEA, ++a)
3313 {
3314 const EthernetAdapter &ea = *itEA; // logical network to connect to
3315 Utf8Str strNetwork = ea.strNetworkName;
3316 // make sure it's one of these two
3317 if ( (strNetwork.compare("Null", Utf8Str::CaseInsensitive))
3318 && (strNetwork.compare("NAT", Utf8Str::CaseInsensitive))
3319 && (strNetwork.compare("Bridged", Utf8Str::CaseInsensitive))
3320 && (strNetwork.compare("Internal", Utf8Str::CaseInsensitive))
3321 && (strNetwork.compare("HostOnly", Utf8Str::CaseInsensitive))
3322 )
3323 strNetwork = "Bridged"; // VMware assumes this is the default apparently
3324
3325 /* Figure out the hardware type */
3326 NetworkAdapterType_T nwAdapterVBox = defaultAdapterVBox;
3327 if (!ea.strAdapterType.compare("PCNet32", Utf8Str::CaseInsensitive))
3328 {
3329 /* If the default adapter is already one of the two
3330 * PCNet adapters use the default one. If not use the
3331 * Am79C970A as fallback. */
3332 if (!(defaultAdapterVBox == NetworkAdapterType_Am79C970A ||
3333 defaultAdapterVBox == NetworkAdapterType_Am79C973))
3334 nwAdapterVBox = NetworkAdapterType_Am79C970A;
3335 }
3336#ifdef VBOX_WITH_E1000
3337 /* VMWare accidentally write this with VirtualCenter 3.5,
3338 so make sure in this case always to use the VMWare one */
3339 else if (!ea.strAdapterType.compare("E10000", Utf8Str::CaseInsensitive))
3340 nwAdapterVBox = NetworkAdapterType_I82545EM;
3341 else if (!ea.strAdapterType.compare("E1000", Utf8Str::CaseInsensitive))
3342 {
3343 /* Check if this OVF was written by VirtualBox */
3344 if (Utf8Str(vsysThis.strVirtualSystemType).contains("virtualbox", Utf8Str::CaseInsensitive))
3345 {
3346 /* If the default adapter is already one of the three
3347 * E1000 adapters use the default one. If not use the
3348 * I82545EM as fallback. */
3349 if (!(defaultAdapterVBox == NetworkAdapterType_I82540EM ||
3350 defaultAdapterVBox == NetworkAdapterType_I82543GC ||
3351 defaultAdapterVBox == NetworkAdapterType_I82545EM))
3352 nwAdapterVBox = NetworkAdapterType_I82540EM;
3353 }
3354 else
3355 /* Always use this one since it's what VMware uses */
3356 nwAdapterVBox = NetworkAdapterType_I82545EM;
3357 }
3358#endif /* VBOX_WITH_E1000 */
3359
3360 pNewDesc->addEntry(VirtualSystemDescriptionType_NetworkAdapter,
3361 "", // ref
3362 ea.strNetworkName, // orig
3363 Utf8StrFmt("%RI32", (uint32_t)nwAdapterVBox), // conf
3364 0,
3365 Utf8StrFmt("type=%s", strNetwork.c_str())); // extra conf
3366 }
3367 }
3368
3369 /* Floppy Drive */
3370 if (vsysThis.fHasFloppyDrive)
3371 pNewDesc->addEntry(VirtualSystemDescriptionType_Floppy, "", "", "");
3372
3373 /* CD Drive */
3374 /* @todo: I can't disable the CDROM. So nothing to do for now */
3375 /*
3376 if (vsysThis.fHasCdromDrive)
3377 pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, "", "", "");*/
3378
3379 /* Hard disk Controller */
3380 uint16_t cIDEused = 0;
3381 uint16_t cSATAused = 0; NOREF(cSATAused);
3382 uint16_t cSCSIused = 0; NOREF(cSCSIused);
3383 ControllersMap::const_iterator hdcIt;
3384 /* Iterate through all hard disk controllers */
3385 for (hdcIt = vsysThis.mapControllers.begin();
3386 hdcIt != vsysThis.mapControllers.end();
3387 ++hdcIt)
3388 {
3389 const HardDiskController &hdc = hdcIt->second;
3390 Utf8Str strControllerID = Utf8StrFmt("%RI32", (uint32_t)hdc.idController);
3391
3392 switch (hdc.system)
3393 {
3394 case HardDiskController::IDE:
3395 {
3396 /* Check for the constrains */
3397 /* @todo: I'm very confused! Are these bits *one* controller or
3398 is every port/bus declared as an extra controller. */
3399 if (cIDEused < 4)
3400 {
3401 // @todo: figure out the IDE types
3402 /* Use PIIX4 as default */
3403 Utf8Str strType = "PIIX4";
3404 if (!hdc.strControllerType.compare("PIIX3", Utf8Str::CaseInsensitive))
3405 strType = "PIIX3";
3406 else if (!hdc.strControllerType.compare("ICH6", Utf8Str::CaseInsensitive))
3407 strType = "ICH6";
3408 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
3409 strControllerID,
3410 hdc.strControllerType,
3411 strType);
3412 }
3413 else
3414 {
3415 /* Warn only once */
3416 if (cIDEused == 1)
3417 addWarning(tr("The virtual \"%s\" system requests support for more than one IDE controller, but VirtualBox has support for only one."),
3418 vsysThis.strName.c_str());
3419
3420 }
3421 ++cIDEused;
3422 break;
3423 }
3424
3425 case HardDiskController::SATA:
3426 {
3427#ifdef VBOX_WITH_AHCI
3428 /* Check for the constrains */
3429 if (cSATAused < 1)
3430 {
3431 // @todo: figure out the SATA types
3432 /* We only support a plain AHCI controller, so use them always */
3433 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSATA,
3434 strControllerID,
3435 hdc.strControllerType,
3436 "AHCI");
3437 }
3438 else
3439 {
3440 /* Warn only once */
3441 if (cSATAused == 1)
3442 addWarning(tr("The virtual system \"%s\" requests support for more than one SATA controller, but VirtualBox has support for only one"),
3443 vsysThis.strName.c_str());
3444
3445 }
3446 ++cSATAused;
3447 break;
3448#else /* !VBOX_WITH_AHCI */
3449 addWarning(tr("The virtual system \"%s\" requests at least one SATA controller but this version of VirtualBox does not provide a SATA controller emulation"),
3450 vsysThis.strName.c_str());
3451#endif /* !VBOX_WITH_AHCI */
3452 }
3453
3454 case HardDiskController::SCSI:
3455 {
3456#ifdef VBOX_WITH_LSILOGIC
3457 /* Check for the constrains */
3458 if (cSCSIused < 1)
3459 {
3460 Utf8Str hdcController = "LsiLogic";
3461 if (!hdc.strControllerType.compare("BusLogic", Utf8Str::CaseInsensitive))
3462 hdcController = "BusLogic";
3463 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSCSI,
3464 strControllerID,
3465 hdc.strControllerType,
3466 hdcController);
3467 }
3468 else
3469 addWarning(tr("The virtual system \"%s\" requests support for an additional SCSI controller of type \"%s\" with ID %s, but VirtualBox presently supports only one SCSI controller."),
3470 vsysThis.strName.c_str(),
3471 hdc.strControllerType.c_str(),
3472 strControllerID.c_str());
3473 ++cSCSIused;
3474 break;
3475#else /* !VBOX_WITH_LSILOGIC */
3476 addWarning(tr("The virtual system \"%s\" requests at least one SATA controller but this version of VirtualBox does not provide a SCSI controller emulation"),
3477 vsysThis.strName.c_str());
3478#endif /* !VBOX_WITH_LSILOGIC */
3479 }
3480 }
3481 }
3482
3483 /* Hard disks */
3484 if (vsysThis.mapVirtualDisks.size() > 0)
3485 {
3486 VirtualDisksMap::const_iterator itVD;
3487 /* Iterate through all hard disks ()*/
3488 for (itVD = vsysThis.mapVirtualDisks.begin();
3489 itVD != vsysThis.mapVirtualDisks.end();
3490 ++itVD)
3491 {
3492 const VirtualDisk &hd = itVD->second;
3493 /* Get the associated disk image */
3494 const DiskImage &di = m->pReader->m_mapDisks[hd.strDiskId];
3495
3496 // @todo:
3497 // - figure out all possible vmdk formats we also support
3498 // - figure out if there is a url specifier for vhd already
3499 // - we need a url specifier for the vdi format
3500 if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
3501 || di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive))
3502 {
3503 /* If the href is empty use the VM name as filename */
3504 Utf8Str strFilename = di.strHref;
3505 if (!strFilename.length())
3506 strFilename = Utf8StrFmt("%s.vmdk", nameVBox.c_str());
3507 /* Construct a unique target path */
3508 Utf8StrFmt strPath("%ls%c%s",
3509 bstrDefaultHardDiskLocation.raw(),
3510 RTPATH_DELIMITER,
3511 strFilename.c_str());
3512 searchUniqueDiskImageFilePath(strPath);
3513
3514 /* find the description for the hard disk controller
3515 * that has the same ID as hd.idController */
3516 const VirtualSystemDescriptionEntry *pController;
3517 if (!(pController = pNewDesc->findControllerFromID(hd.idController)))
3518 throw setError(E_FAIL,
3519 tr("Cannot find hard disk controller with OVF instance ID %RI32 to which disk \"%s\" should be attached"),
3520 hd.idController,
3521 di.strHref.c_str());
3522
3523 /* controller to attach to, and the bus within that controller */
3524 Utf8StrFmt strExtraConfig("controller=%RI16;channel=%RI16",
3525 pController->ulIndex,
3526 hd.ulAddressOnParent);
3527 ULONG ulSize = 0;
3528 if (di.iCapacity != -1)
3529 ulSize = (ULONG)(di.iCapacity / _1M);
3530 else if (di.iPopulatedSize != -1)
3531 ulSize = (ULONG)(di.iPopulatedSize / _1M);
3532 else if (di.iSize != -1)
3533 ulSize = (ULONG)(di.iSize / _1M);
3534 if (ulSize == 0)
3535 ulSize = 10000; // assume 10 GB, this is for the progress bar only anyway
3536 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage,
3537 hd.strDiskId,
3538 di.strHref,
3539 strPath,
3540 ulSize,
3541 strExtraConfig);
3542 }
3543 else
3544 throw setError(VBOX_E_FILE_ERROR,
3545 tr("Unsupported format for virtual disk image in OVF: \"%s\"", di.strFormat.c_str()));
3546 }
3547 }
3548
3549 m->virtualSystemDescriptions.push_back(pNewDesc);
3550 }
3551 }
3552 catch (HRESULT aRC)
3553 {
3554 /* On error we clear the list & return */
3555 m->virtualSystemDescriptions.clear();
3556 rc = aRC;
3557 }
3558
3559 return rc;
3560}
3561
3562/**
3563 * Public method implementation.
3564 * @param aProgress
3565 * @return
3566 */
3567STDMETHODIMP Appliance::ImportMachines(IProgress **aProgress)
3568{
3569 CheckComArgOutPointerValid(aProgress);
3570
3571 AutoCaller autoCaller(this);
3572 CheckComRCReturnRC(autoCaller.rc());
3573
3574 AutoReadLock(this);
3575
3576 if (!m->pReader)
3577 return setError(E_FAIL,
3578 tr("Cannot import machines without reading it first (call read() before importMachines())"));
3579
3580 ComObjPtr<Progress> progress;
3581 HRESULT rc = S_OK;
3582 try
3583 {
3584 rc = importImpl(m->locInfo, progress);
3585 }
3586 catch (HRESULT aRC)
3587 {
3588 rc = aRC;
3589 }
3590
3591 if (SUCCEEDED(rc))
3592 /* Return progress to the caller */
3593 progress.queryInterfaceTo(aProgress);
3594
3595 return rc;
3596}
3597
3598STDMETHODIMP Appliance::CreateVFSExplorer(IN_BSTR aURI, IVFSExplorer **aExplorer)
3599{
3600 CheckComArgOutPointerValid(aExplorer);
3601
3602 AutoCaller autoCaller(this);
3603 CheckComRCReturnRC(autoCaller.rc());
3604
3605 AutoReadLock(this);
3606
3607 ComObjPtr<VFSExplorer> explorer;
3608 HRESULT rc = S_OK;
3609 try
3610 {
3611 Utf8Str uri(aURI);
3612 /* Check which kind of export the user has requested */
3613 LocationInfo li;
3614 parseURI(uri, li);
3615 /* Create the explorer object */
3616 explorer.createObject();
3617 rc = explorer->init(li.storageType, li.strPath, li.strHostname, li.strUsername, li.strPassword, mVirtualBox);
3618 }
3619 catch (HRESULT aRC)
3620 {
3621 rc = aRC;
3622 }
3623
3624 if (SUCCEEDED(rc))
3625 /* Return explorer to the caller */
3626 explorer.queryInterfaceTo(aExplorer);
3627
3628 return rc;
3629}
3630
3631STDMETHODIMP Appliance::Write(IN_BSTR format, IN_BSTR path, IProgress **aProgress)
3632{
3633 if (!path) return E_POINTER;
3634 CheckComArgOutPointerValid(aProgress);
3635
3636 AutoCaller autoCaller(this);
3637 CheckComRCReturnRC(autoCaller.rc());
3638
3639 AutoWriteLock(this);
3640
3641 // see if we can handle this file; for now we insist it has an ".ovf" extension
3642 Utf8Str strPath = path;
3643 if (!strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
3644 return setError(VBOX_E_FILE_ERROR,
3645 tr("Appliance file must have .ovf extension"));
3646
3647 Utf8Str strFormat(format);
3648 TaskExportOVF::OVFFormat ovfF;
3649 if (strFormat == "ovf-0.9")
3650 ovfF = TaskExportOVF::OVF_0_9;
3651 else if (strFormat == "ovf-1.0")
3652 ovfF = TaskExportOVF::OVF_1_0;
3653 else
3654 return setError(VBOX_E_FILE_ERROR,
3655 tr("Invalid format \"%s\" specified"), strFormat.c_str());
3656
3657 ComObjPtr<Progress> progress;
3658 HRESULT rc = S_OK;
3659 try
3660 {
3661 /* Parse all necessary info out of the URI */
3662 parseURI(strPath, m->locInfo);
3663 rc = writeImpl(ovfF, m->locInfo, progress);
3664 }
3665 catch (HRESULT aRC)
3666 {
3667 rc = aRC;
3668 }
3669
3670 if (SUCCEEDED(rc))
3671 /* Return progress to the caller */
3672 progress.queryInterfaceTo(aProgress);
3673
3674 return rc;
3675}
3676
3677/**
3678* Public method implementation.
3679 * @return
3680 */
3681STDMETHODIMP Appliance::GetWarnings(ComSafeArrayOut(BSTR, aWarnings))
3682{
3683 if (ComSafeArrayOutIsNull(aWarnings))
3684 return E_POINTER;
3685
3686 AutoCaller autoCaller(this);
3687 CheckComRCReturnRC(autoCaller.rc());
3688
3689 AutoReadLock alock(this);
3690
3691 com::SafeArray<BSTR> sfaWarnings(m->llWarnings.size());
3692
3693 list<Utf8Str>::const_iterator it;
3694 size_t i = 0;
3695 for (it = m->llWarnings.begin();
3696 it != m->llWarnings.end();
3697 ++it, ++i)
3698 {
3699 Bstr bstr = *it;
3700 bstr.cloneTo(&sfaWarnings[i]);
3701 }
3702
3703 sfaWarnings.detachTo(ComSafeArrayOutArg(aWarnings));
3704
3705 return S_OK;
3706}
3707
3708////////////////////////////////////////////////////////////////////////////////
3709//
3710// IVirtualSystemDescription constructor / destructor
3711//
3712////////////////////////////////////////////////////////////////////////////////
3713
3714DEFINE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
3715
3716/**
3717 * COM initializer.
3718 * @return
3719 */
3720HRESULT VirtualSystemDescription::init()
3721{
3722 /* Enclose the state transition NotReady->InInit->Ready */
3723 AutoInitSpan autoInitSpan(this);
3724 AssertReturn(autoInitSpan.isOk(), E_FAIL);
3725
3726 /* Initialize data */
3727 m = new Data();
3728
3729 /* Confirm a successful initialization */
3730 autoInitSpan.setSucceeded();
3731 return S_OK;
3732}
3733
3734/**
3735* COM uninitializer.
3736*/
3737
3738void VirtualSystemDescription::uninit()
3739{
3740 delete m;
3741 m = NULL;
3742}
3743
3744////////////////////////////////////////////////////////////////////////////////
3745//
3746// IVirtualSystemDescription public methods
3747//
3748////////////////////////////////////////////////////////////////////////////////
3749
3750/**
3751 * Public method implementation.
3752 * @param
3753 * @return
3754 */
3755STDMETHODIMP VirtualSystemDescription::COMGETTER(Count)(ULONG *aCount)
3756{
3757 if (!aCount)
3758 return E_POINTER;
3759
3760 AutoCaller autoCaller(this);
3761 CheckComRCReturnRC(autoCaller.rc());
3762
3763 AutoReadLock alock(this);
3764
3765 *aCount = (ULONG)m->llDescriptions.size();
3766
3767 return S_OK;
3768}
3769
3770/**
3771 * Public method implementation.
3772 * @return
3773 */
3774STDMETHODIMP VirtualSystemDescription::GetDescription(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
3775 ComSafeArrayOut(BSTR, aRefs),
3776 ComSafeArrayOut(BSTR, aOrigValues),
3777 ComSafeArrayOut(BSTR, aVboxValues),
3778 ComSafeArrayOut(BSTR, aExtraConfigValues))
3779{
3780 if (ComSafeArrayOutIsNull(aTypes) ||
3781 ComSafeArrayOutIsNull(aRefs) ||
3782 ComSafeArrayOutIsNull(aOrigValues) ||
3783 ComSafeArrayOutIsNull(aVboxValues) ||
3784 ComSafeArrayOutIsNull(aExtraConfigValues))
3785 return E_POINTER;
3786
3787 AutoCaller autoCaller(this);
3788 CheckComRCReturnRC(autoCaller.rc());
3789
3790 AutoReadLock alock(this);
3791
3792 ULONG c = (ULONG)m->llDescriptions.size();
3793 com::SafeArray<VirtualSystemDescriptionType_T> sfaTypes(c);
3794 com::SafeArray<BSTR> sfaRefs(c);
3795 com::SafeArray<BSTR> sfaOrigValues(c);
3796 com::SafeArray<BSTR> sfaVboxValues(c);
3797 com::SafeArray<BSTR> sfaExtraConfigValues(c);
3798
3799 list<VirtualSystemDescriptionEntry>::const_iterator it;
3800 size_t i = 0;
3801 for (it = m->llDescriptions.begin();
3802 it != m->llDescriptions.end();
3803 ++it, ++i)
3804 {
3805 const VirtualSystemDescriptionEntry &vsde = (*it);
3806
3807 sfaTypes[i] = vsde.type;
3808
3809 Bstr bstr = vsde.strRef;
3810 bstr.cloneTo(&sfaRefs[i]);
3811
3812 bstr = vsde.strOvf;
3813 bstr.cloneTo(&sfaOrigValues[i]);
3814
3815 bstr = vsde.strVbox;
3816 bstr.cloneTo(&sfaVboxValues[i]);
3817
3818 bstr = vsde.strExtraConfig;
3819 bstr.cloneTo(&sfaExtraConfigValues[i]);
3820 }
3821
3822 sfaTypes.detachTo(ComSafeArrayOutArg(aTypes));
3823 sfaRefs.detachTo(ComSafeArrayOutArg(aRefs));
3824 sfaOrigValues.detachTo(ComSafeArrayOutArg(aOrigValues));
3825 sfaVboxValues.detachTo(ComSafeArrayOutArg(aVboxValues));
3826 sfaExtraConfigValues.detachTo(ComSafeArrayOutArg(aExtraConfigValues));
3827
3828 return S_OK;
3829}
3830
3831/**
3832 * Public method implementation.
3833 * @return
3834 */
3835STDMETHODIMP VirtualSystemDescription::GetDescriptionByType(VirtualSystemDescriptionType_T aType,
3836 ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
3837 ComSafeArrayOut(BSTR, aRefs),
3838 ComSafeArrayOut(BSTR, aOrigValues),
3839 ComSafeArrayOut(BSTR, aVboxValues),
3840 ComSafeArrayOut(BSTR, aExtraConfigValues))
3841{
3842 if (ComSafeArrayOutIsNull(aTypes) ||
3843 ComSafeArrayOutIsNull(aRefs) ||
3844 ComSafeArrayOutIsNull(aOrigValues) ||
3845 ComSafeArrayOutIsNull(aVboxValues) ||
3846 ComSafeArrayOutIsNull(aExtraConfigValues))
3847 return E_POINTER;
3848
3849 AutoCaller autoCaller(this);
3850 CheckComRCReturnRC(autoCaller.rc());
3851
3852 AutoReadLock alock(this);
3853
3854 std::list<VirtualSystemDescriptionEntry*> vsd = findByType (aType);
3855 ULONG c = (ULONG)vsd.size();
3856 com::SafeArray<VirtualSystemDescriptionType_T> sfaTypes(c);
3857 com::SafeArray<BSTR> sfaRefs(c);
3858 com::SafeArray<BSTR> sfaOrigValues(c);
3859 com::SafeArray<BSTR> sfaVboxValues(c);
3860 com::SafeArray<BSTR> sfaExtraConfigValues(c);
3861
3862 list<VirtualSystemDescriptionEntry*>::const_iterator it;
3863 size_t i = 0;
3864 for (it = vsd.begin();
3865 it != vsd.end();
3866 ++it, ++i)
3867 {
3868 const VirtualSystemDescriptionEntry *vsde = (*it);
3869
3870 sfaTypes[i] = vsde->type;
3871
3872 Bstr bstr = vsde->strRef;
3873 bstr.cloneTo(&sfaRefs[i]);
3874
3875 bstr = vsde->strOvf;
3876 bstr.cloneTo(&sfaOrigValues[i]);
3877
3878 bstr = vsde->strVbox;
3879 bstr.cloneTo(&sfaVboxValues[i]);
3880
3881 bstr = vsde->strExtraConfig;
3882 bstr.cloneTo(&sfaExtraConfigValues[i]);
3883 }
3884
3885 sfaTypes.detachTo(ComSafeArrayOutArg(aTypes));
3886 sfaRefs.detachTo(ComSafeArrayOutArg(aRefs));
3887 sfaOrigValues.detachTo(ComSafeArrayOutArg(aOrigValues));
3888 sfaVboxValues.detachTo(ComSafeArrayOutArg(aVboxValues));
3889 sfaExtraConfigValues.detachTo(ComSafeArrayOutArg(aExtraConfigValues));
3890
3891 return S_OK;
3892}
3893
3894/**
3895 * Public method implementation.
3896 * @return
3897 */
3898STDMETHODIMP VirtualSystemDescription::GetValuesByType(VirtualSystemDescriptionType_T aType,
3899 VirtualSystemDescriptionValueType_T aWhich,
3900 ComSafeArrayOut(BSTR, aValues))
3901{
3902 if (ComSafeArrayOutIsNull(aValues))
3903 return E_POINTER;
3904
3905 AutoCaller autoCaller(this);
3906 CheckComRCReturnRC(autoCaller.rc());
3907
3908 AutoReadLock alock(this);
3909
3910 std::list<VirtualSystemDescriptionEntry*> vsd = findByType (aType);
3911 com::SafeArray<BSTR> sfaValues((ULONG)vsd.size());
3912
3913 list<VirtualSystemDescriptionEntry*>::const_iterator it;
3914 size_t i = 0;
3915 for (it = vsd.begin();
3916 it != vsd.end();
3917 ++it, ++i)
3918 {
3919 const VirtualSystemDescriptionEntry *vsde = (*it);
3920
3921 Bstr bstr;
3922 switch (aWhich)
3923 {
3924 case VirtualSystemDescriptionValueType_Reference: bstr = vsde->strRef; break;
3925 case VirtualSystemDescriptionValueType_Original: bstr = vsde->strOvf; break;
3926 case VirtualSystemDescriptionValueType_Auto: bstr = vsde->strVbox; break;
3927 case VirtualSystemDescriptionValueType_ExtraConfig: bstr = vsde->strExtraConfig; break;
3928 }
3929
3930 bstr.cloneTo(&sfaValues[i]);
3931 }
3932
3933 sfaValues.detachTo(ComSafeArrayOutArg(aValues));
3934
3935 return S_OK;
3936}
3937
3938/**
3939 * Public method implementation.
3940 * @return
3941 */
3942STDMETHODIMP VirtualSystemDescription::SetFinalValues(ComSafeArrayIn(BOOL, aEnabled),
3943 ComSafeArrayIn(IN_BSTR, argVboxValues),
3944 ComSafeArrayIn(IN_BSTR, argExtraConfigValues))
3945{
3946#ifndef RT_OS_WINDOWS
3947 NOREF(aEnabledSize);
3948#endif /* RT_OS_WINDOWS */
3949
3950 CheckComArgSafeArrayNotNull(aEnabled);
3951 CheckComArgSafeArrayNotNull(argVboxValues);
3952 CheckComArgSafeArrayNotNull(argExtraConfigValues);
3953
3954 AutoCaller autoCaller(this);
3955 CheckComRCReturnRC(autoCaller.rc());
3956
3957 AutoWriteLock alock(this);
3958
3959 com::SafeArray<BOOL> sfaEnabled(ComSafeArrayInArg(aEnabled));
3960 com::SafeArray<IN_BSTR> sfaVboxValues(ComSafeArrayInArg(argVboxValues));
3961 com::SafeArray<IN_BSTR> sfaExtraConfigValues(ComSafeArrayInArg(argExtraConfigValues));
3962
3963 if ( (sfaEnabled.size() != m->llDescriptions.size())
3964 || (sfaVboxValues.size() != m->llDescriptions.size())
3965 || (sfaExtraConfigValues.size() != m->llDescriptions.size())
3966 )
3967 return E_INVALIDARG;
3968
3969 list<VirtualSystemDescriptionEntry>::iterator it;
3970 size_t i = 0;
3971 for (it = m->llDescriptions.begin();
3972 it != m->llDescriptions.end();
3973 ++it, ++i)
3974 {
3975 VirtualSystemDescriptionEntry& vsde = *it;
3976
3977 if (sfaEnabled[i])
3978 {
3979 vsde.strVbox = sfaVboxValues[i];
3980 vsde.strExtraConfig = sfaExtraConfigValues[i];
3981 }
3982 else
3983 vsde.type = VirtualSystemDescriptionType_Ignore;
3984 }
3985
3986 return S_OK;
3987}
3988
3989/**
3990 * Public method implementation.
3991 * @return
3992 */
3993STDMETHODIMP VirtualSystemDescription::AddDescription(VirtualSystemDescriptionType_T aType,
3994 IN_BSTR aVboxValue,
3995 IN_BSTR aExtraConfigValue)
3996{
3997 CheckComArgNotNull(aVboxValue);
3998 CheckComArgNotNull(aExtraConfigValue);
3999
4000 AutoCaller autoCaller(this);
4001 CheckComRCReturnRC(autoCaller.rc());
4002
4003 AutoWriteLock alock(this);
4004
4005 addEntry(aType, "", aVboxValue, aVboxValue, 0, aExtraConfigValue);
4006
4007 return S_OK;
4008}
4009
4010/**
4011 * Internal method; adds a new description item to the member list.
4012 * @param aType Type of description for the new item.
4013 * @param strRef Reference item; only used with hard disk controllers.
4014 * @param aOrigValue Corresponding original value from OVF.
4015 * @param aAutoValue Initial configuration value (can be overridden by caller with setFinalValues).
4016 * @param ulSizeMB Weight for IProgress
4017 * @param strExtraConfig Extra configuration; meaning dependent on type.
4018 */
4019void VirtualSystemDescription::addEntry(VirtualSystemDescriptionType_T aType,
4020 const Utf8Str &strRef,
4021 const Utf8Str &aOrigValue,
4022 const Utf8Str &aAutoValue,
4023 uint32_t ulSizeMB,
4024 const Utf8Str &strExtraConfig /*= ""*/)
4025{
4026 VirtualSystemDescriptionEntry vsde;
4027 vsde.ulIndex = (uint32_t)m->llDescriptions.size(); // each entry gets an index so the client side can reference them
4028 vsde.type = aType;
4029 vsde.strRef = strRef;
4030 vsde.strOvf = aOrigValue;
4031 vsde.strVbox = aAutoValue;
4032 vsde.strExtraConfig = strExtraConfig;
4033 vsde.ulSizeMB = ulSizeMB;
4034
4035 m->llDescriptions.push_back(vsde);
4036}
4037
4038/**
4039 * Private method; returns a list of description items containing all the items from the member
4040 * description items of this virtual system that match the given type.
4041 * @param aType
4042 * @return
4043 */
4044std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::findByType(VirtualSystemDescriptionType_T aType)
4045{
4046 std::list<VirtualSystemDescriptionEntry*> vsd;
4047
4048 list<VirtualSystemDescriptionEntry>::iterator it;
4049 for (it = m->llDescriptions.begin();
4050 it != m->llDescriptions.end();
4051 ++it)
4052 {
4053 if (it->type == aType)
4054 vsd.push_back(&(*it));
4055 }
4056
4057 return vsd;
4058}
4059
4060/**
4061 * Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
4062 * the given reference ID. Useful when needing the controller for a particular
4063 * virtual disk.
4064 * @param id
4065 * @return
4066 */
4067const VirtualSystemDescriptionEntry* VirtualSystemDescription::findControllerFromID(uint32_t id)
4068{
4069 Utf8Str strRef = Utf8StrFmt("%RI32", id);
4070 list<VirtualSystemDescriptionEntry>::const_iterator it;
4071 for (it = m->llDescriptions.begin();
4072 it != m->llDescriptions.end();
4073 ++it)
4074 {
4075 const VirtualSystemDescriptionEntry &d = *it;
4076 switch (d.type)
4077 {
4078 case VirtualSystemDescriptionType_HardDiskControllerIDE:
4079 case VirtualSystemDescriptionType_HardDiskControllerSATA:
4080 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
4081 if (d.strRef == strRef)
4082 return &d;
4083 break;
4084 }
4085 }
4086
4087 return NULL;
4088}
4089
4090////////////////////////////////////////////////////////////////////////////////
4091//
4092// IMachine public methods
4093//
4094////////////////////////////////////////////////////////////////////////////////
4095
4096// This code is here so we won't have to include the appliance headers in the
4097// IMachine implementation, and we also need to access private appliance data.
4098
4099/**
4100* Public method implementation.
4101* @param appliance
4102* @return
4103*/
4104
4105STDMETHODIMP Machine::Export(IAppliance *aAppliance, IVirtualSystemDescription **aDescription)
4106{
4107 HRESULT rc = S_OK;
4108
4109 if (!aAppliance)
4110 return E_POINTER;
4111
4112 AutoCaller autoCaller(this);
4113 CheckComRCReturnRC(autoCaller.rc());
4114
4115 AutoReadLock alock(this);
4116
4117 ComObjPtr<VirtualSystemDescription> pNewDesc;
4118
4119 try
4120 {
4121 Bstr bstrName;
4122 Bstr bstrDescription;
4123 Bstr bstrGuestOSType;
4124 uint32_t cCPUs;
4125 uint32_t ulMemSizeMB;
4126 BOOL fDVDEnabled;
4127 BOOL fFloppyEnabled;
4128 BOOL fUSBEnabled;
4129 BOOL fAudioEnabled;
4130 AudioControllerType_T audioController;
4131
4132 ComPtr<IUSBController> pUsbController;
4133 ComPtr<IAudioAdapter> pAudioAdapter;
4134
4135 // get name
4136 bstrName = mUserData->mName;
4137 // get description
4138 bstrDescription = mUserData->mDescription;
4139 // get guest OS
4140 bstrGuestOSType = mUserData->mOSTypeId;
4141 // CPU count
4142 cCPUs = mHWData->mCPUCount;
4143 // memory size in MB
4144 ulMemSizeMB = mHWData->mMemorySize;
4145 // VRAM size?
4146 // BIOS settings?
4147 // 3D acceleration enabled?
4148 // hardware virtualization enabled?
4149 // nested paging enabled?
4150 // HWVirtExVPIDEnabled?
4151 // PAEEnabled?
4152 // snapshotFolder?
4153 // VRDPServer?
4154
4155 // floppy
4156 rc = mFloppyDrive->COMGETTER(Enabled)(&fFloppyEnabled);
4157 if (FAILED(rc)) throw rc;
4158
4159 // CD-ROM ?!?
4160 // ComPtr<IDVDDrive> pDVDDrive;
4161 fDVDEnabled = 1;
4162
4163 // this is more tricky so use the COM method
4164 rc = COMGETTER(USBController)(pUsbController.asOutParam());
4165 if (FAILED(rc))
4166 fUSBEnabled = false;
4167 else
4168 rc = pUsbController->COMGETTER(Enabled)(&fUSBEnabled);
4169
4170 pAudioAdapter = mAudioAdapter;
4171 rc = pAudioAdapter->COMGETTER(Enabled)(&fAudioEnabled);
4172 if (FAILED(rc)) throw rc;
4173 rc = pAudioAdapter->COMGETTER(AudioController)(&audioController);
4174 if (FAILED(rc)) throw rc;
4175
4176 // create a new virtual system
4177 rc = pNewDesc.createObject();
4178 CheckComRCThrowRC(rc);
4179 rc = pNewDesc->init();
4180 CheckComRCThrowRC(rc);
4181
4182 /* Guest OS type */
4183 Utf8Str strOsTypeVBox(bstrGuestOSType);
4184 CIMOSType_T cim = convertVBoxOSType2CIMOSType(strOsTypeVBox.c_str());
4185 pNewDesc->addEntry(VirtualSystemDescriptionType_OS,
4186 "",
4187 Utf8StrFmt("%RI32", cim),
4188 strOsTypeVBox);
4189
4190 /* VM name */
4191 Utf8Str strVMName(bstrName);
4192 pNewDesc->addEntry(VirtualSystemDescriptionType_Name,
4193 "",
4194 strVMName,
4195 strVMName);
4196
4197 // description
4198 Utf8Str strDescription(bstrDescription);
4199 pNewDesc->addEntry(VirtualSystemDescriptionType_Description,
4200 "",
4201 strDescription,
4202 strDescription);
4203
4204 /* CPU count*/
4205 Utf8Str strCpuCount = Utf8StrFmt("%RI32", cCPUs);
4206 pNewDesc->addEntry(VirtualSystemDescriptionType_CPU,
4207 "",
4208 strCpuCount,
4209 strCpuCount);
4210
4211 /* Memory */
4212 Utf8Str strMemory = Utf8StrFmt("%RI32", (uint64_t)ulMemSizeMB * _1M);
4213 pNewDesc->addEntry(VirtualSystemDescriptionType_Memory,
4214 "",
4215 strMemory,
4216 strMemory);
4217
4218 int32_t lIDEControllerIndex = 0;
4219 int32_t lSATAControllerIndex = 0;
4220 int32_t lSCSIControllerIndex = 0;
4221
4222// <const name="HardDiskControllerIDE" value="6" />
4223 ComPtr<IStorageController> pController;
4224 rc = GetStorageControllerByName(Bstr("IDE"), pController.asOutParam());
4225 if (FAILED(rc)) throw rc;
4226 Utf8Str strVbox;
4227 StorageControllerType_T ctlr;
4228 rc = pController->COMGETTER(ControllerType)(&ctlr);
4229 if (FAILED(rc)) throw rc;
4230 switch(ctlr)
4231 {
4232 case StorageControllerType_PIIX3: strVbox = "PIIX3"; break;
4233 case StorageControllerType_PIIX4: strVbox = "PIIX4"; break;
4234 case StorageControllerType_ICH6: strVbox = "ICH6"; break;
4235 }
4236
4237 if (strVbox.length())
4238 {
4239 lIDEControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
4240 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
4241 Utf8StrFmt("%d", lIDEControllerIndex),
4242 strVbox,
4243 strVbox);
4244 }
4245
4246#ifdef VBOX_WITH_AHCI
4247// <const name="HardDiskControllerSATA" value="7" />
4248 rc = GetStorageControllerByName(Bstr("SATA"), pController.asOutParam());
4249 if (SUCCEEDED(rc))
4250 {
4251 strVbox = "AHCI";
4252 lSATAControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
4253 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSATA,
4254 Utf8StrFmt("%d", lSATAControllerIndex),
4255 strVbox,
4256 strVbox);
4257 }
4258#endif // VBOX_WITH_AHCI
4259
4260#ifdef VBOX_WITH_LSILOGIC
4261// <const name="HardDiskControllerSCSI" value="8" />
4262 rc = GetStorageControllerByName(Bstr("SCSI"), pController.asOutParam());
4263 if (SUCCEEDED(rc))
4264 {
4265 rc = pController->COMGETTER(ControllerType)(&ctlr);
4266 if (SUCCEEDED(rc))
4267 {
4268 strVbox = "LsiLogic"; // the default in VBox
4269 switch(ctlr)
4270 {
4271 case StorageControllerType_LsiLogic: strVbox = "LsiLogic"; break;
4272 case StorageControllerType_BusLogic: strVbox = "BusLogic"; break;
4273 }
4274 lSCSIControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
4275 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSCSI,
4276 Utf8StrFmt("%d", lSCSIControllerIndex),
4277 strVbox,
4278 strVbox);
4279 }
4280 else
4281 throw rc;
4282 }
4283#endif // VBOX_WITH_LSILOGIC
4284
4285// <const name="HardDiskImage" value="9" />
4286 HDData::AttachmentList::iterator itA;
4287 for (itA = mHDData->mAttachments.begin();
4288 itA != mHDData->mAttachments.end();
4289 ++itA)
4290 {
4291 ComObjPtr<HardDiskAttachment> pHDA = *itA;
4292
4293 // the attachment's data
4294 ComPtr<IHardDisk> pHardDisk;
4295 ComPtr<IStorageController> ctl;
4296 Bstr controllerName;
4297
4298 rc = pHDA->COMGETTER(Controller)(controllerName.asOutParam());
4299 if (FAILED(rc)) throw rc;
4300
4301 rc = GetStorageControllerByName(controllerName, ctl.asOutParam());
4302 if (FAILED(rc)) throw rc;
4303
4304 StorageBus_T storageBus;
4305 LONG lChannel;
4306 LONG lDevice;
4307
4308 rc = ctl->COMGETTER(Bus)(&storageBus);
4309 if (FAILED(rc)) throw rc;
4310
4311 rc = pHDA->COMGETTER(HardDisk)(pHardDisk.asOutParam());
4312 if (FAILED(rc)) throw rc;
4313
4314 rc = pHDA->COMGETTER(Port)(&lChannel);
4315 if (FAILED(rc)) throw rc;
4316
4317 rc = pHDA->COMGETTER(Device)(&lDevice);
4318 if (FAILED(rc)) throw rc;
4319
4320 Bstr bstrLocation;
4321 rc = pHardDisk->COMGETTER(Location)(bstrLocation.asOutParam());
4322 if (FAILED(rc)) throw rc;
4323 Bstr bstrName;
4324 rc = pHardDisk->COMGETTER(Name)(bstrName.asOutParam());
4325 if (FAILED(rc)) throw rc;
4326
4327 // force reading state, or else size will be returned as 0
4328 MediaState_T ms;
4329 rc = pHardDisk->COMGETTER(State)(&ms);
4330 if (FAILED(rc)) throw rc;
4331
4332 ULONG64 ullSize;
4333 rc = pHardDisk->COMGETTER(Size)(&ullSize);
4334 if (FAILED(rc)) throw rc;
4335
4336 // and how this translates to the virtual system
4337 int32_t lControllerVsys = 0;
4338 LONG lChannelVsys;
4339
4340 switch (storageBus)
4341 {
4342 case StorageBus_IDE:
4343 // this is the exact reverse to what we're doing in Appliance::taskThreadImportMachines,
4344 // and it must be updated when that is changed!
4345
4346 if (lChannel == 0 && lDevice == 0) // primary master
4347 lChannelVsys = 0;
4348 else if (lChannel == 0 && lDevice == 1) // primary slave
4349 lChannelVsys = 1;
4350 else if (lChannel == 1 && lDevice == 1) // secondary slave; secondary master is always CDROM
4351 lChannelVsys = 2;
4352 else
4353 throw setError(VBOX_E_NOT_SUPPORTED,
4354 tr("Cannot handle hard disk attachment: channel is %d, device is %d"), lChannel, lDevice);
4355
4356 lControllerVsys = lIDEControllerIndex;
4357 break;
4358
4359 case StorageBus_SATA:
4360 lChannelVsys = lChannel; // should be between 0 and 29
4361 lControllerVsys = lSATAControllerIndex;
4362 break;
4363
4364 case StorageBus_SCSI:
4365 lChannelVsys = lChannel; // should be between 0 and 15
4366 lControllerVsys = lSCSIControllerIndex;
4367 break;
4368
4369 default:
4370 throw setError(VBOX_E_NOT_SUPPORTED,
4371 tr("Cannot handle hard disk attachment: storageBus is %d, channel is %d, device is %d"), storageBus, lChannel, lDevice);
4372 break;
4373 }
4374
4375 Utf8Str strTargetVmdkName(bstrName);
4376 strTargetVmdkName.stripExt();
4377 strTargetVmdkName.append(".vmdk");
4378
4379 pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage,
4380 strTargetVmdkName, // disk ID: let's use the name
4381 strTargetVmdkName, // OVF value:
4382 Utf8Str(bstrLocation), // vbox value: media path
4383 (uint32_t)(ullSize / _1M),
4384 Utf8StrFmt("controller=%RI32;channel=%RI32", lControllerVsys, lChannelVsys));
4385 }
4386
4387 /* Floppy Drive */
4388 if (fFloppyEnabled)
4389 pNewDesc->addEntry(VirtualSystemDescriptionType_Floppy, "", "", "");
4390
4391 /* CD Drive */
4392 if (fDVDEnabled)
4393 pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, "", "", "");
4394
4395// <const name="NetworkAdapter" />
4396 size_t a;
4397 for (a = 0;
4398 a < SchemaDefs::NetworkAdapterCount;
4399 ++a)
4400 {
4401 ComPtr<INetworkAdapter> pNetworkAdapter;
4402 BOOL fEnabled;
4403 NetworkAdapterType_T adapterType;
4404 NetworkAttachmentType_T attachmentType;
4405
4406 rc = GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam());
4407 if (FAILED(rc)) throw rc;
4408 /* Enable the network card & set the adapter type */
4409 rc = pNetworkAdapter->COMGETTER(Enabled)(&fEnabled);
4410 if (FAILED(rc)) throw rc;
4411
4412 if (fEnabled)
4413 {
4414 Utf8Str strAttachmentType;
4415
4416 rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType);
4417 if (FAILED(rc)) throw rc;
4418
4419 rc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType);
4420 if (FAILED(rc)) throw rc;
4421
4422 switch (attachmentType)
4423 {
4424 case NetworkAttachmentType_Null:
4425 strAttachmentType = "Null";
4426 break;
4427
4428 case NetworkAttachmentType_NAT:
4429 strAttachmentType = "NAT";
4430 break;
4431
4432 case NetworkAttachmentType_Bridged:
4433 strAttachmentType = "Bridged";
4434 break;
4435
4436 case NetworkAttachmentType_Internal:
4437 strAttachmentType = "Internal";
4438 break;
4439
4440 case NetworkAttachmentType_HostOnly:
4441 strAttachmentType = "HostOnly";
4442 break;
4443 }
4444
4445 pNewDesc->addEntry(VirtualSystemDescriptionType_NetworkAdapter,
4446 "", // ref
4447 strAttachmentType, // orig
4448 Utf8StrFmt("%RI32", (uint32_t)adapterType), // conf
4449 0,
4450 Utf8StrFmt("type=%s", strAttachmentType.c_str())); // extra conf
4451 }
4452 }
4453
4454// <const name="USBController" />
4455#ifdef VBOX_WITH_USB
4456 if (fUSBEnabled)
4457 pNewDesc->addEntry(VirtualSystemDescriptionType_USBController, "", "", "");
4458#endif /* VBOX_WITH_USB */
4459
4460// <const name="SoundCard" />
4461 if (fAudioEnabled)
4462 {
4463 pNewDesc->addEntry(VirtualSystemDescriptionType_SoundCard,
4464 "",
4465 "ensoniq1371", // this is what OVFTool writes and VMware supports
4466 Utf8StrFmt("%RI32", audioController));
4467 }
4468
4469 // finally, add the virtual system to the appliance
4470 Appliance *pAppliance = static_cast<Appliance*>(aAppliance);
4471 AutoCaller autoCaller1(pAppliance);
4472 CheckComRCReturnRC(autoCaller1.rc());
4473
4474 /* We return the new description to the caller */
4475 ComPtr<IVirtualSystemDescription> copy(pNewDesc);
4476 copy.queryInterfaceTo(aDescription);
4477
4478 AutoWriteLock alock(pAppliance);
4479
4480 pAppliance->m->virtualSystemDescriptions.push_back(pNewDesc);
4481 }
4482 catch(HRESULT arc)
4483 {
4484 rc = arc;
4485 }
4486
4487 return rc;
4488}
4489
4490/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette