ApplianceImpl.cpp revision b8ae33177906f4130b85b7c861cae0e78ed4859b
/* $Id$ */
/** @file
*
* IAppliance and IVirtualSystem COM class implementations.
*/
/*
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "ovfreader.h"
#include "ApplianceImpl.h"
#include "VFSExplorerImpl.h"
#include "VirtualBoxImpl.h"
#include "GuestOSTypeImpl.h"
#include "ProgressImpl.h"
#include "MachineImpl.h"
#include "HostNetworkInterfaceImpl.h"
#include "Logging.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//
// Appliance data definition
//
////////////////////////////////////////////////////////////////////////////////
* local hard disk or a remote target based on the supported inet protocols. */
struct Appliance::LocationInfo
{
: storageType(VFSType_File) {}
};
// opaque private instance data of Appliance class
{
Data()
~Data()
{
if (pReader)
{
delete pReader;
}
}
};
struct VirtualSystemDescription::Data
{
};
////////////////////////////////////////////////////////////////////////////////
//
// internal helpers
//
////////////////////////////////////////////////////////////////////////////////
static const struct
{
const char *pcszVbox;
}
g_osTypes[] =
{
// { CIMOSType_CIMOS_TurboLinux_64, },
};
/* Pattern structure for matching the OS type description field */
struct osTypePattern
{
const char *pcszPattern;
const char *pcszVbox;
};
/* These are the 32-Bit ones. They are sorted by priority. */
static const osTypePattern g_osTypesPattern[] =
{
{"Windows NT", SchemaDefs_OSTypeId_WindowsNT4},
{"Windows XP", SchemaDefs_OSTypeId_WindowsXP},
{"Windows 2000", SchemaDefs_OSTypeId_Windows2000},
{"Windows 2003", SchemaDefs_OSTypeId_Windows2003},
{"Windows Vista", SchemaDefs_OSTypeId_WindowsVista},
{"Windows 2008", SchemaDefs_OSTypeId_Windows2008},
{"SUSE", SchemaDefs_OSTypeId_OpenSUSE},
{"Novell", SchemaDefs_OSTypeId_OpenSUSE},
{"Red Hat", SchemaDefs_OSTypeId_RedHat},
{"Mandriva", SchemaDefs_OSTypeId_Mandriva},
{"Ubuntu", SchemaDefs_OSTypeId_Ubuntu},
{"Debian", SchemaDefs_OSTypeId_Debian},
{"QNX", SchemaDefs_OSTypeId_QNX},
{"Linux 2.4", SchemaDefs_OSTypeId_Linux24},
{"Linux 2.6", SchemaDefs_OSTypeId_Linux26},
{"Linux", SchemaDefs_OSTypeId_Linux},
{"OpenSolaris", SchemaDefs_OSTypeId_OpenSolaris},
{"Solaris", SchemaDefs_OSTypeId_OpenSolaris},
{"FreeBSD", SchemaDefs_OSTypeId_FreeBSD},
{"NetBSD", SchemaDefs_OSTypeId_NetBSD},
{"Windows 95", SchemaDefs_OSTypeId_Windows95},
{"Windows 98", SchemaDefs_OSTypeId_Windows98},
{"Windows Me", SchemaDefs_OSTypeId_WindowsMe},
{"Windows 3.", SchemaDefs_OSTypeId_Windows31},
{"DOS", SchemaDefs_OSTypeId_DOS},
{"OS2", SchemaDefs_OSTypeId_OS2}
};
/* These are the 64-Bit ones. They are sorted by priority. */
static const osTypePattern g_osTypesPattern64[] =
{
{"Windows XP", SchemaDefs_OSTypeId_WindowsXP_64},
{"Windows 2003", SchemaDefs_OSTypeId_Windows2003_64},
{"Windows Vista", SchemaDefs_OSTypeId_WindowsVista_64},
{"Windows 2008", SchemaDefs_OSTypeId_Windows2008_64},
{"SUSE", SchemaDefs_OSTypeId_OpenSUSE_64},
{"Novell", SchemaDefs_OSTypeId_OpenSUSE_64},
{"Red Hat", SchemaDefs_OSTypeId_RedHat_64},
{"Mandriva", SchemaDefs_OSTypeId_Mandriva_64},
{"Ubuntu", SchemaDefs_OSTypeId_Ubuntu_64},
{"Debian", SchemaDefs_OSTypeId_Debian_64},
{"Linux 2.4", SchemaDefs_OSTypeId_Linux24_64},
{"Linux 2.6", SchemaDefs_OSTypeId_Linux26_64},
{"Linux", SchemaDefs_OSTypeId_Linux26_64},
{"OpenSolaris", SchemaDefs_OSTypeId_OpenSolaris_64},
{"Solaris", SchemaDefs_OSTypeId_OpenSolaris_64},
{"FreeBSD", SchemaDefs_OSTypeId_FreeBSD_64},
};
/**
* Private helper func that suggests a VirtualBox guest OS type
* for the given OVF operating system type.
* @param osTypeVBox
* @param c
* @param cStr
*/
{
if (c == CIMOSType_CIMOS_Other)
{
{
return;
}
}
else if (c == CIMOSType_CIMOS_Other_64)
{
{
return;
}
}
{
{
return;
}
}
}
/**
* Private helper func that suggests a VirtualBox guest OS type
* for the given OVF operating system type.
* @param osTypeVBox
* @param c
*/
{
{
}
return CIMOSType_CIMOS_Other;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualBox public methods
//
////////////////////////////////////////////////////////////////////////////////
// This code is here so we won't have to include the appliance headers in the
// IVirtualBox implementation.
/**
* Implementation for IVirtualBox::createAppliance.
*
* @param anAppliance IAppliance object created if S_OK is returned.
* @return S_OK or error.
*/
{
return rc;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance constructor / destructor
//
////////////////////////////////////////////////////////////////////////////////
/**
* Appliance COM initializer.
* @param
* @return
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Weak reference to a VirtualBox object */
// initialize data
m = new Data;
/* Confirm a successful initialization */
return S_OK;
}
/**
* Appliance COM uninitializer.
* @return
*/
{
delete m;
m = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance private methods
//
////////////////////////////////////////////////////////////////////////////////
{
int i = 1;
/* @todo: Maybe too cost-intensive; try to find a lighter way */
{
++i;
}
return S_OK;
}
{
int i = 1;
/* Check if the file exists or if a file with this path is registered
* already */
/* @todo: Maybe too cost-intensive; try to find a lighter way */
while (RTPathExists(tmpName) ||
{
++i;
}
return S_OK;
}
/**
* Called from the import and export background threads to synchronize the second
* background disk thread's progress object with the current progress object so
* that the user interface sees progress correctly and that cancel signals are
* passed on to the second thread.
* @param pProgressThis Progress object of the current thread.
* @param pProgressAsync Progress object of asynchronous task running in background.
*/
{
// now loop until the asynchronous operation completes and then report its result
{
if (fCanceled)
{
pProgressAsync->Cancel();
break;
}
if (!pProgressThis.isNull())
if (fCompleted)
break;
/* Make sure the loop is not too tight */
}
// report result of asynchronous operation
// if the thread of the progress object has an error, then
// retrieve the error info from there, or it'll be lost
{
throw rc2;
}
}
{
}
{
ulTotalMB = 0;
cDisks = 0;
/* Weigh the disk images according to their sizes */
++it)
{
/* One for every hard disk of the Virtual System */
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
++itH)
{
++cDisks;
}
}
}
{
/* Create the progress object */
/* Weigh the disk images according to their sizes */
if (ulTotalMB)
{
m->ulWeightPerOperation = (ULONG)((double)ulTotalMB * 1 / 100); // use 1% of the progress for the XML
}
else
{
// no disks to export:
m->ulWeightPerOperation = 1;
}
Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
TRUE /* aCancelable */,
cOperations, // ULONG cOperations,
ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
bstrDescription, // CBSTR bstrFirstOperationDescription,
m->ulWeightPerOperation); // ULONG ulFirstOperationWeight,
return rc;
}
HRESULT Appliance::setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
{
/* Create the progress object */
/* Weigh the disk images according to their sizes */
if (!ulTotalOperationsWeight)
// no disks to export:
Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
TRUE /* aCancelable */,
cOperations, // ULONG cOperations,
ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
ulInitWeight); // ULONG ulFirstOperationWeight,
return rc;
}
HRESULT Appliance::setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription)
{
/* Create the progress object */
/* Weigh the disk images according to their sizes */
ULONG cOperations = 1 + 1 + cDisks; // one op per disk plus 1 for the OVF & 1 plus to the temporary creation */
if (ulTotalMB)
{
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)
}
else
{
// no disks to export:
m->ulWeightPerOperation = 1;
}
ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the creation of the OVF & the disks */
Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightPerOperation = %d\n",
TRUE /* aCancelable */,
cOperations, // ULONG cOperations,
ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
bstrDescription, // CBSTR bstrFirstOperationDescription,
ulOVFCreationWeight); // ULONG ulFirstOperationWeight,
return rc;
}
{
/* Check the URI for the protocol */
{
}
{
}
{
}
throw E_NOTIMPL;
/* Not necessary on a file based URI */
{
{
{
}
}
{
}
}
}
{
/* Buckets are S3 specific. So parse the bucket out of the file path */
throw setError(E_INVALIDARG,
{
}
/* If there is no bucket name provided reject it */
throw setError(E_INVALIDARG,
}
{
: pAppliance(aThat)
};
{
enum TaskType
{
Read,
};
int startThread();
};
{
enum OVFFormat
{
};
enum TaskType
{
};
int startThread();
};
struct MyHardDiskAttachment
{
};
/* static */
{
if (pTask &&
{
if (fCanceled)
return -1;
}
return VINF_SUCCESS;
}
{
/* Initialize our worker task */
/* What should the task do */
/* Copy the current location info to the task */
/* Create the progress object */
{
/* 1 operation only */
TRUE /* aCancelable */);
}
else
{
/* 4/5 is downloading, 1/5 is reading */
TRUE /* aCancelable */,
2, // ULONG cOperations,
5, // ULONG ulTotalOperationsWeight,
4); // ULONG ulFirstOperationWeight,
}
/* Don't destruct on success */
return rc;
}
{
/* Initialize our worker task */
/* What should the task do */
/* Copy the current location info to the task */
/* todo: This progress init stuff should be done a little bit more generic */
else
/* Don't destruct on success */
return rc;
}
/**
* Worker thread implementation for Read() (ovf reader).
* @param aThread
* @param pvUser
*/
/* static */
{
{
case TaskImportOVF::Read:
{
break;
}
case TaskImportOVF::Import:
{
break;
}
}
return VINF_SUCCESS;
}
{
"Appliance::Task");
return S_OK;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
try
{
}
{
x.what());
}
return VINF_SUCCESS;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
int vrc = VINF_SUCCESS;
char szOSTmpDir[RTPATH_MAX];
/* The template for the temporary directory created below */
char *pszTmpDir;
try
{
/* Extract the bucket */
/* We need a temporary directory which we can put the OVF file & all
* disk images in */
if (RT_FAILURE(rc))
throw setError(VBOX_E_FILE_ERROR,
/* The temporary name of the target OVF file */
/* Next we have to download the OVF */
vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
if(RT_FAILURE(vrc))
throw setError(VBOX_E_IPRT_ERROR,
tr("Cannot create S3 service handler"));
/* Get it */
if (RT_FAILURE(vrc))
{
if(vrc == VERR_S3_CANCELED)
throw S_OK; /* todo: !!!!!!!!!!!!! */
else if(vrc == VERR_S3_ACCESS_DENIED)
throw setError(E_ACCESSDENIED,
else if(vrc == VERR_S3_NOT_FOUND)
throw setError(VBOX_E_FILE_ERROR,
else
throw setError(VBOX_E_IPRT_ERROR,
}
/* Close the connection early */
/* Prepare the temporary reading of the OVF */
/* Start the reading from the fs */
/* Unlock the appliance for the reading thread */
/* Wait until the reading is done, but report the progress back to the
caller */
/* Again lock the appliance for the next steps */
}
{
}
/* Cleanup */
/* Delete all files which where temporary created */
{
if(RT_FAILURE(vrc))
}
/* Delete the temporary directory */
if (RTPathExists(pszTmpDir))
{
if(RT_FAILURE(vrc))
}
if (pszTmpDir)
return VINF_SUCCESS;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
// rollback for errors:
bool fSessionOpen = false;
// this is safe to access because this thread only gets started
// if pReader != NULL
/* Iterate through all virtual systems of that appliance */
size_t i = 0;
{
/* Catch possible errors */
try
{
/* Guest OS type */
throw setError(VBOX_E_FILE_ERROR,
tr("Missing guest OS type"));
/* Now that we know the base system get our internal defaults based on that. */
/* Create the machine */
/* First get the name */
std::list<VirtualSystemDescriptionEntry*> vsdeName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
throw setError(VBOX_E_FILE_ERROR,
tr("Missing VM name"));
// and the description
std::list<VirtualSystemDescriptionEntry*> vsdeDescription = vsdescThis->findByType(VirtualSystemDescriptionType_Description);
if (vsdeDescription.size())
{
}
/* CPU count */
std::list<VirtualSystemDescriptionEntry*> vsdeCPU = vsdescThis->findByType (VirtualSystemDescriptionType_CPU);
bool fEnableIOApic = false;
/* We need HWVirt & IO-APIC if more than one CPU is requested */
if (tmpCount > 1)
{
fEnableIOApic = true;
}
/* RAM */
std::list<VirtualSystemDescriptionEntry*> vsdeRAM = vsdescThis->findByType(VirtualSystemDescriptionType_Memory);
/* VRAM */
/* Get the recommended VRAM for this guest OS type */
/* Set the VRAM */
/* I/O APIC: so far we have no setting for this. Enable it if we
import a Windows VM because if if Windows was installed without IOAPIC,
it will not mind finding an one later on, but if Windows was installed
_with_ an IOAPIC, it will bluescreen if it's not found */
if (strFamilyId == "Windows")
fEnableIOApic = true;
/* If IP-APIC should be enabled could be have different reasons.
See CPU count & the Win test above. Here we enable it if it was
previously requested. */
if (fEnableIOApic)
{
}
/* Audio Adapter */
std::list<VirtualSystemDescriptionEntry*> vsdeAudioAdapter = vsdescThis->findByType(VirtualSystemDescriptionType_SoundCard);
/* @todo: we support one audio adapter only */
if (vsdeAudioAdapter.size() > 0)
{
{
}
}
#ifdef VBOX_WITH_USB
/* USB Controller */
std::list<VirtualSystemDescriptionEntry*> vsdeUSBController = vsdescThis->findByType(VirtualSystemDescriptionType_USBController);
// USB support is enabled if there's at least one such entry; to disable USB support,
// the type of the USB item would have been changed to "ignore"
#endif /* VBOX_WITH_USB */
/* Change the network adapters */
std::list<VirtualSystemDescriptionEntry*> vsdeNW = vsdescThis->findByType(VirtualSystemDescriptionType_NetworkAdapter);
{
/* No network adapters, so we have to disable our default one */
}
else
{
/* Iterate through all network cards. We support 8 network adapters
* at the maximum. (@todo: warn if there are more!) */
size_t a = 0;
++nwIt, ++a)
{
/* Enable the network card & set the adapter type */
// default is NAT; change to "bridged" if extra conf says so
{
/* Attach to the right interface */
/* We search for the first host network interface which
* is usable for bridged networking */
{
{
/* Set the interface name to attach to */
break;
}
}
}
/* Next test for host only interfaces */
{
/* Attach to the right interface */
/* We search for the first host network interface which
* is usable for host only networking */
{
{
/* Set the interface name to attach to */
break;
}
}
}
}
}
/* Floppy drive */
std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);
// Floppy support is enabled if there's at least one such entry; to disable floppy support,
// the type of the floppy item would have been changed to "ignore"
/* CDROM drive */
/* @todo: I can't disable the CDROM. So nothing to do for now */
// std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsd->findByType(VirtualSystemDescriptionType_CDROM);
/* Hard disk controller IDE */
std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerIDE);
throw setError(VBOX_E_FILE_ERROR,
tr("Too many IDE controllers in OVF; VirtualBox only supports one"));
{
else
throw setError(VBOX_E_FILE_ERROR,
tr("Invalid IDE controller type \"%s\""),
}
#ifdef VBOX_WITH_AHCI
/* Hard disk controller SATA */
std::list<VirtualSystemDescriptionEntry*> vsdeHDCSATA = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSATA);
throw setError(VBOX_E_FILE_ERROR,
tr("Too many SATA controllers in OVF; VirtualBox only supports one"));
if (vsdeHDCSATA.size() > 0)
{
if (hdcVBox == "AHCI")
{
}
else
throw setError(VBOX_E_FILE_ERROR,
tr("Invalid SATA controller type \"%s\""),
}
#endif /* VBOX_WITH_AHCI */
#ifdef VBOX_WITH_LSILOGIC
/* Hard disk controller SCSI */
std::list<VirtualSystemDescriptionEntry*> vsdeHDCSCSI = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
throw setError(VBOX_E_FILE_ERROR,
tr("Too many SCSI controllers in OVF; VirtualBox only supports one"));
if (vsdeHDCSCSI.size() > 0)
{
if (hdcVBox == "LsiLogic")
else if (hdcVBox == "BusLogic")
else
throw setError(VBOX_E_FILE_ERROR,
tr("Invalid SCSI controller type \"%s\""),
}
#endif /* VBOX_WITH_LSILOGIC */
/* Now its time to register the machine before we add any hard disks */
// store new machine for roll-back in case of errors
/* Create the hard disks & connect them to the appropriate controllers. */
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
{
/* If in the next block an error occur we have to deregister
bool fSourceHdNeedsClosing = false;
try
{
/* In order to attach hard disks we need to open a session
* for the new machine */
fSessionOpen = true;
/* The disk image has to be on the same place as the OVF file. So
* strip the filename out of the full file path. */
/* Iterate over all given disk images */
++itHD)
{
/* Check if the destination file exists already or the
* destination path is empty. */
if ( !(*pcszDstFilePath)
)
/* This isn't allowed */
throw setError(VBOX_E_FILE_ERROR,
tr("Destination file '%s' exists",
/* Find the disk from the OVF's disk list */
/* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
in the virtual system's disks map under that ID and also in the global images map. */
)
tr("Internal inconsistency looking up disk images."));
/* Make sure all target directories exists */
throw rc;
// subprogress object for hard disk
/* If strHref is empty we have to create a new file */
{
/* Which format to use? */
if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
|| di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive))
srcFormat = L"VMDK";
/* Create an empty hard disk */
/* Create a dynamic growing disk image with the given capacity */
rc = dstHdVBox->CreateBaseStorage(di.iCapacity / _1M, HardDiskVariant_Standard, pProgress2.asOutParam());
/* Advance to the next operation */
}
else
{
/* Construct the source file path */
/* Check if the source file exists */
/* This isn't allowed */
throw setError(VBOX_E_FILE_ERROR,
tr("Source virtual disk image file '%s' doesn't exist"),
strSrcFilePath.c_str());
/* Clone the disk image (this is necessary cause the id has
* to be recreated for the case the same hard disk is
* attached already from a previous import) */
/* First open the existing disk image */
srcHdVBox.asOutParam());
fSourceHdNeedsClosing = true;
/* We need the format description of the source disk image */
/* Create a new hard disk interface for the destination disk image */
/* Clone the source disk image */
/* Advance to the next operation */
pTask->progress->setNextOperation(BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()),
}
// now wait for the background disk operation to complete; this throws HRESULTs on error
{
fSourceHdNeedsClosing = false;
}
/* Now use the new uuid to attach the disk image to our new machine */
/* For now we assume we have one controller of every type only */
// this is for rollback later
{
case HardDiskController::IDE:
// For the IDE bus, the channel parameter can be either 0 or 1, to specify the primary
// or secondary IDE controller, respectively. For the primary controller of the IDE bus,
// the device number can be either 0 or 1, to specify the master or the slave device,
// respectively. For the secondary IDE controller, the device number is always 1 because
// the master device is reserved for the CD-ROM drive.
switch (vd.ulAddressOnParent)
{
case 0: // interpret this as primary master
break;
case 1: // interpret this as primary slave
break;
case 2: // interpret this as secondary slave
break;
default:
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Invalid channel %RI16 specified; IDE controllers support only 0, 1 or 2"), vd.ulAddressOnParent);
break;
}
break;
case HardDiskController::SATA:
break;
case HardDiskController::SCSI:
break;
default: break;
}
Log(("Attaching disk %s to channel %d on device %d\n", pcszDstFilePath, mhda.lChannel, mhda.lDevice));
} // end for (itHD = avsdeHDs.begin();
// only now that we're done with all disks, close the session
fSessionOpen = false;
}
catch(HRESULT /* aRC */)
{
if (fSessionOpen)
throw;
}
}
}
{
}
break;
} // for (it = pAppliance->m->llVirtualSystems.begin(),
{
// with _whatever_ error we've had, do a complete roll-back of
// machines and disks we've created; unfortunately this is
// not so trivially done...
// detach all hard disks from all machines we created
++itM)
{
{
{
}
}
}
// now clean up all hard disks we created
++itHD)
{
}
// finally, deregister and remove all machines
++itID)
{
}
}
return VINF_SUCCESS;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
int vrc = VINF_SUCCESS;
char szOSTmpDir[RTPATH_MAX];
/* The template for the temporary directory created below */
char *pszTmpDir;
try
{
/* Extract the bucket */
/* We need a temporary directory which we can put the all disk images
* in */
if (RT_FAILURE(rc))
throw setError(VBOX_E_FILE_ERROR,
/* Add every disks of every virtual system to an internal list */
++it)
{
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
++itH)
{
if (!strTargetFile.isEmpty())
{
/* The temporary name of the target disk file */
}
}
}
/* Next we have to download the disk images */
vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
if(RT_FAILURE(vrc))
throw setError(VBOX_E_IPRT_ERROR,
tr("Cannot create S3 service handler"));
/* Download all files */
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
{
/* Construct the source file name */
/* Advance to the next operation */
if (RT_FAILURE(vrc))
{
if(vrc == VERR_S3_CANCELED)
throw S_OK; /* todo: !!!!!!!!!!!!! */
else if(vrc == VERR_S3_ACCESS_DENIED)
throw setError(E_ACCESSDENIED,
else if(vrc == VERR_S3_NOT_FOUND)
throw setError(VBOX_E_FILE_ERROR,
else
throw setError(VBOX_E_IPRT_ERROR,
}
}
/* Close the connection early */
/* Import the whole temporary OVF & the disk images */
/* Provide a OVF file (haven't to exist) so the import routine can
* figure out where the disk images are located. */
/* Unlock the appliance for the fs import thread */
/* Wait until the import is done, but report the progress back to the
caller */
/* Again lock the appliance for the next steps */
}
{
}
/* Cleanup */
/* Delete all files which where temporary created */
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
{
if (RTPathExists(pszFilePath))
{
if(RT_FAILURE(vrc))
}
}
/* Delete the temporary directory */
if (RTPathExists(pszTmpDir))
{
if(RT_FAILURE(vrc))
}
if (pszTmpDir)
return VINF_SUCCESS;
}
HRESULT Appliance::writeImpl(int aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
{
try
{
/* Initialize our worker task */
/* What should the task do */
/* The OVF version to write */
/* Copy the current location info to the task */
/* todo: This progress init stuff should be done a little bit more generic */
else
/* Don't destruct on success */
}
{
}
return rc;
}
{
{
case TaskExportOVF::Write:
{
break;
}
}
return VINF_SUCCESS;
}
{
"Appliance::Task");
return S_OK;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
try
{
? "http://www.vmware.com/schema/ovf/1/envelope" // 0.9
: "http://schemas.dmtf.org/ovf/envelope/1"; // 1.0
// pelmRoot->setAttribute("xmlns:ovfstr", "http://schema.dmtf.org/ovf/strings/1");
pelmRoot->setAttribute("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData");
pelmRoot->setAttribute("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData");
// pelmRoot->setAttribute("xsi:schemaLocation", "http://schemas.dmtf.org/ovf/envelope/1 ../ovf-envelope.xsd");
// <Envelope>/<References>
/* <Envelope>/<DiskSection>:
<DiskSection>
<Info>List of the virtual disks used in the package</Info>
<Disk ovf:capacity="4294967296" ovf:diskId="lamp" ovf:format="http://www.vmware.com/specifications/vmdk.html#compressed" ovf:populatedSize="1924967692"/>
</DiskSection> */
{
// <Section xsi:type="ovf:DiskSection_Type">
}
else
// for now, set up a map so we have a list of unique disk names (to make
// sure the same disk name is only added once)
/* <Envelope>/<NetworkSection>:
<NetworkSection>
<Info>Logical networks used in the package</Info>
<Network ovf:name="VM Network">
<Description>The network that the LAMP Service will be available on</Description>
</Network>
</NetworkSection> */
{
// <Section xsi:type="ovf:NetworkSection_Type">
}
else
// for now, set up a map so we have a list of unique network names (to make
// sure the same network name is only added once)
// we fill this later below when we iterate over the networks
// and here come the virtual systems:
// write a collection if we have more than one virtual system _and_ we're
// writing OVF 1.0; otherwise fail since ovftool can't import more than
// one machine, it seems
{
throw setError(VBOX_E_FILE_ERROR,
tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0"));
/* xml::AttributeNode *pattrVirtualSystemCollectionId = */ pelmToAddVirtualSystemsTo->setAttribute("ovf:name", "ExportedVirtualBoxMachines"); // whatever
}
else
/* Iterate through all virtual systems of that appliance */
++it)
{
{
// <Section xsi:type="ovf:NetworkSection_Type">
}
else
/*xml::ElementNode *pelmVirtualSystemInfo =*/ pelmVirtualSystem->createChild("Info")->addContent("A virtual machine");
std::list<VirtualSystemDescriptionEntry*> llName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Missing VM name"));
// product info
std::list<VirtualSystemDescriptionEntry*> llProduct = vsdescThis->findByType(VirtualSystemDescriptionType_Product);
std::list<VirtualSystemDescriptionEntry*> llProductUrl = vsdescThis->findByType(VirtualSystemDescriptionType_ProductUrl);
std::list<VirtualSystemDescriptionEntry*> llVendor = vsdescThis->findByType(VirtualSystemDescriptionType_Vendor);
std::list<VirtualSystemDescriptionEntry*> llVendorUrl = vsdescThis->findByType(VirtualSystemDescriptionType_VendorUrl);
std::list<VirtualSystemDescriptionEntry*> llVersion = vsdescThis->findByType(VirtualSystemDescriptionType_Version);
if (fProduct ||
fProductUrl ||
fVersion ||
fVendorUrl ||
{
/* <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
<Info>Meta-information about the installed software</Info>
<Product>VAtest</Product>
<Vendor>SUN Microsystems</Vendor>
<Version>10.0</Version>
<ProductUrl>http://blogs.sun.com/VirtualGuru</ProductUrl>
<VendorUrl>http://www.sun.com</VendorUrl>
</Section> */
{
// <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
}
else
pelmAnnotationSection->createChild("Info")->addContent("Meta-information about the installed software");
if (fProduct)
if (fVendor)
if (fVersion)
if (fProductUrl)
if (fVendorUrl)
}
// description
std::list<VirtualSystemDescriptionEntry*> llDescription = vsdescThis->findByType(VirtualSystemDescriptionType_Description);
if (llDescription.size() &&
{
/* <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
<Info>A human-readable annotation</Info>
<Annotation>Plan 9</Annotation>
</Section> */
{
// <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
}
else
}
// license
std::list<VirtualSystemDescriptionEntry*> llLicense = vsdescThis->findByType(VirtualSystemDescriptionType_License);
{
/* <EulaSection>
<Info ovf:msgid="6">License agreement for the Virtual System.</Info>
<License ovf:msgid="1">License terms can go in here.</License>
</EulaSection> */
{
}
else
}
// operating system
std::list<VirtualSystemDescriptionEntry*> llOS = vsdescThis->findByType(VirtualSystemDescriptionType_OS);
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Missing OS type"));
/* <OperatingSystemSection ovf:id="82">
<Info>Guest Operating System</Info>
<Description>Linux 2.6.x</Description>
</OperatingSystemSection> */
{
}
else
pelmOperatingSystemSection->createChild("Info")->addContent("The kind of installed guest operating system");
// <VirtualHardwareSection ovf:id="hw1" ovf:transport="iso">
{
// <Section xsi:type="ovf:VirtualHardwareSection_Type">
}
else
pelmVirtualHardwareSection->createChild("Info")->addContent("Virtual hardware requirements for a virtual machine");
/* <System>
<vssd:Description>Description of the virtual hardware section.</vssd:Description>
<vssd:ElementName>vmware</vssd:ElementName>
<vssd:InstanceID>1</vssd:InstanceID>
<vssd:VirtualSystemIdentifier>MyLampService</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
</System> */
pelmSystem->createChild("vssd:ElementName")->addContent("Virtual Hardware Family"); // required OVF 1.0
// <vssd:InstanceId>0</vssd:InstanceId>
else // capitalization changed...
// <vssd:VirtualSystemIdentifier>VAtest</vssd:VirtualSystemIdentifier>
// <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
const char *pcszHardware = "virtualbox-2.2";
// pretend to be vmware compatible then
pcszHardware = "vmx-6";
// loop thru all description entries twice; once to write out all
// devices _except_ disk images, and a second time to assign the
// disk images; this is because disk images need to reference
// IDE controllers, and we can't know their instance IDs without
// assigning them first
uint32_t idIDEController = 0;
uint32_t idSATAController = 0;
uint32_t idSCSIController = 0;
uLoop <= 2;
++uLoop)
{
int32_t lIndexThis = 0;
++itD, ++lIndexThis)
{
{
/* <Item>
<rasd:Caption>1 virtual CPU</rasd:Caption>
<rasd:Description>Number of virtual CPUs</rasd:Description>
<rasd:ElementName>virtual CPU</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
</Item> */
if (uLoop == 1)
{
strDescription = "Number of virtual CPUs";
strCaption = Utf8StrFmt("%d virtual CPU", lVirtualQuantity); // without this ovftool won't eat the item
}
break;
/* <Item>
<rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
<rasd:Caption>256 MB of memory</rasd:Caption>
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>Memory</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>256</rasd:VirtualQuantity>
</Item> */
if (uLoop == 1)
{
strDescription = "Memory Size";
strAllocationUnits = "MegaBytes";
strCaption = Utf8StrFmt("%d MB of memory", lVirtualQuantity); // without this ovftool won't eat the item
}
break;
/* <Item>
<rasd:Caption>ideController1</rasd:Caption>
<rasd:Description>IDE Controller</rasd:Description>
<rasd:InstanceId>5</rasd:InstanceId>
<rasd:ResourceType>5</rasd:ResourceType>
<rasd:Address>1</rasd:Address>
<rasd:BusNumber>1</rasd:BusNumber>
</Item> */
if (uLoop == 1)
{
strDescription = "IDE Controller";
strCaption = "ideController0";
// it seems that OVFTool always writes these two, and since we can only
// have one IDE controller, we'll use this as well
lAddress = 1;
lBusNumber = 1;
// remember this ID
}
break;
/* <Item>
<rasd:Caption>sataController0</rasd:Caption>
<rasd:Description>SATA Controller</rasd:Description>
<rasd:InstanceId>4</rasd:InstanceId>
<rasd:ResourceType>20</rasd:ResourceType>
<rasd:ResourceSubType>ahci</rasd:ResourceSubType>
<rasd:Address>0</rasd:Address>
<rasd:BusNumber>0</rasd:BusNumber>
</Item>
*/
if (uLoop == 1)
{
strDescription = "SATA Controller";
strCaption = "sataController0";
// it seems that OVFTool always writes these two, and since we can only
// have one SATA controller, we'll use this as well
lAddress = 0;
lBusNumber = 0;
)
strResourceSubType = "AHCI";
else
throw setError(VBOX_E_NOT_SUPPORTED,
// remember this ID
}
break;
/* <Item>
<rasd:Caption>scsiController0</rasd:Caption>
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:InstanceId>4</rasd:InstanceId>
<rasd:ResourceType>6</rasd:ResourceType>
<rasd:ResourceSubType>buslogic</rasd:ResourceSubType>
<rasd:Address>0</rasd:Address>
<rasd:BusNumber>0</rasd:BusNumber>
</Item>
*/
if (uLoop == 1)
{
strDescription = "SCSI Controller";
strCaption = "scsiController0";
// it seems that OVFTool always writes these two, and since we can only
// have one SATA controller, we'll use this as well
lAddress = 0;
lBusNumber = 0;
)
strResourceSubType = "lsilogic";
strResourceSubType = "buslogic";
else
throw setError(VBOX_E_NOT_SUPPORTED,
// remember this ID
}
break;
/* <Item>
<rasd:Caption>disk1</rasd:Caption>
<rasd:InstanceId>8</rasd:InstanceId>
<rasd:ResourceType>17</rasd:ResourceType>
<rasd:Parent>4</rasd:Parent>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
</Item> */
if (uLoop == 2)
{
strDescription = "Disk Image";
// the following references the "<Disks>" XML block
// controller=<index>;channel=<c>
{
if (lControllerIndex == lIDEControllerIndex)
else if (lControllerIndex == lSCSIControllerIndex)
else if (lControllerIndex == lSATAControllerIndex)
}
if ( !ulParent
|| lAddressOnParent == -1
)
throw setError(VBOX_E_NOT_SUPPORTED,
}
break;
if (uLoop == 1)
{
strDescription = "Floppy Drive";
lAutomaticAllocation = 0;
lAddressOnParent = 0; // this is what OVFTool writes
}
break;
if (uLoop == 2)
{
// we can't have a CD without an IDE controller
if (!idIDEController)
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Can't have CD-ROM without IDE controller"));
strDescription = "CD-ROM Drive";
lAutomaticAllocation = 1;
lAddressOnParent = 0; // this is what OVFTool writes
}
break;
/* <Item>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption>
<rasd:Connection>VM Network</rasd:Connection>
<rasd:ElementName>VM network</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:ResourceType>10</rasd:ResourceType>
</Item> */
if (uLoop == 1)
{
lAutomaticAllocation = 1;
/* Set the hardware type to something useful.
* To be compatible with vmware & others we set
* PCNet32 for our PCNet types & E1000 for the
* E1000 cards. */
{
#ifdef VBOX_WITH_E1000
#endif /* VBOX_WITH_E1000 */
}
}
break;
/* <Item ovf:required="false">
<rasd:Caption>usb</rasd:Caption>
<rasd:Description>USB Controller</rasd:Description>
<rasd:InstanceId>3</rasd:InstanceId>
<rasd:ResourceType>23</rasd:ResourceType>
<rasd:Address>0</rasd:Address>
<rasd:BusNumber>0</rasd:BusNumber>
</Item> */
if (uLoop == 1)
{
strDescription = "USB Controller";
strCaption = "usb";
lAddress = 0; // this is what OVFTool writes
lBusNumber = 0; // this is what OVFTool writes
}
break;
/* <Item ovf:required="false">
<rasd:Caption>sound</rasd:Caption>
<rasd:Description>Sound Card</rasd:Description>
<rasd:InstanceId>10</rasd:InstanceId>
<rasd:ResourceType>35</rasd:ResourceType>
<rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
<rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
<rasd:AddressOnParent>3</rasd:AddressOnParent>
</Item> */
if (uLoop == 1)
{
strDescription = "Sound Card";
strCaption = "sound";
lAutomaticAllocation = 0;
}
break;
}
if (type)
{
// NOTE: do not change the order of these items without good reason! While we don't care
// about ordering, VMware's ovftool does and fails if the items are not written in
// exactly this order, as stupid as it seems.
if (!strCaption.isEmpty())
{
}
if (!strDescription.isEmpty())
// <rasd:InstanceID>1</rasd:InstanceID>
else
// <rasd:ResourceType>3</rasd:ResourceType>
if (!strResourceSubType.isEmpty())
if (!strHostResource.isEmpty())
if (!strAllocationUnits.isEmpty())
// <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
if (lVirtualQuantity != -1)
if (lAutomaticAllocation != -1)
pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" );
if (!strConnection.isEmpty())
if (lAddress != -1)
if (lBusNumber != -1)
if (pTask->enFormat == TaskExportOVF::OVF_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool compatibility
if (ulParent)
if (lAddressOnParent != -1)
}
}
} // for (size_t uLoop = 0; ...
}
// finally, fill in the network section we set up empty above according
// to the networks we found with the hardware items
++itN)
{
}
++itS)
{
// source path: where the VBox image is
/* This isn't allowed */
throw setError(VBOX_E_FILE_ERROR,
tr("Source virtual disk image file '%s' doesn't exist"),
strSrcFilePath.c_str());
// output filename
// target path needs to be composed from where the output OVF is
// clone the disk:
/* We are always exporting to vmdfk stream optimized for now */
// create a new hard disk interface for the destination disk image
// the target disk is now registered and needs to be removed again,
// both after successful cloning or if anything goes bad!
try
{
// create a flat copy of the source disk image
rc = pSourceDisk->CloneTo(pTargetDisk, HardDiskVariant_VmdkStreamOptimized, NULL, pProgress2.asOutParam());
// advance to the next operation
pTask->progress->setNextOperation(BstrFmt(tr("Exporting virtual disk image '%s'"), strSrcFilePath.c_str()),
// now wait for the background disk operation to complete; this throws HRESULTs on error
}
{
// upon error after registering, close the disk or
// it'll stick in the registry forever
pTargetDisk->Close();
throw;
}
// we need the following for the XML
// capacity is reported in megabytes, so...
cbCapacity *= _1M;
// upon success, close the disk as well
// now handle the XML for the disk:
// <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/>
// add disk to XML Disks section
// <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/specifications/vmdk.html#sparse"/>
pelmDisk->setAttribute("ovf:format", "http://www.vmware.com/specifications/vmdk.html#sparse"); // must be sparse or ovftool chokes
}
// now go write the XML
}
{
x.what());
}
{
}
return VINF_SUCCESS;
}
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
AutoWriteLock appLock(this);
int vrc = VINF_SUCCESS;
char szOSTmpDir[RTPATH_MAX];
/* The template for the temporary directory created below */
char *pszTmpDir;
// todo:
// - usable error codes
// - seems snapshot filenames are problematic {uuid}.vdi
try
{
/* Extract the bucket */
/* We need a temporary directory which we can put the OVF file & all
* disk images in */
if (RT_FAILURE(rc))
throw setError(VBOX_E_FILE_ERROR,
/* The temporary name of the target OVF file */
/* Prepare the temporary writing of the OVF */
/* Create a temporary file based location info for the sub task */
/* Unlock the appliance for the writing thread */
/* Wait until the writing is done, but report the progress back to the
caller */
/* Again lock the appliance for the next steps */
if(RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
/* Add the OVF file */
filesList.push_back(pair<Utf8Str, ULONG>(strTmpOvf, m->ulWeightPerOperation)); /* Use 1% of the total for the OVF file upload */
/* Now add every disks of every virtual system */
++it)
{
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
++itH)
{
/* Target path needs to be composed from where the output OVF is */
if(RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
}
}
/* Next we have to upload the OVF & all disk images */
vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
if(RT_FAILURE(vrc))
throw setError(VBOX_E_IPRT_ERROR,
tr("Cannot create S3 service handler"));
/* Upload all files */
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
{
/* Advance to the next operation */
if (RT_FAILURE(vrc))
{
if(vrc == VERR_S3_CANCELED)
break;
else if(vrc == VERR_S3_ACCESS_DENIED)
throw setError(E_ACCESSDENIED,
else if(vrc == VERR_S3_NOT_FOUND)
throw setError(VBOX_E_FILE_ERROR,
else
throw setError(VBOX_E_IPRT_ERROR,
}
}
}
{
}
/* Cleanup */
/* Delete all files which where temporary created */
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
{
if (RTPathExists(pszFilePath))
{
if(RT_FAILURE(vrc))
}
}
/* Delete the temporary directory */
if (RTPathExists(pszTmpDir))
{
if(RT_FAILURE(vrc))
}
if (pszTmpDir)
return VINF_SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
//
// IAppliance public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param
* @return
*/
{
if (!aPath)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Public method implementation.
* @param
* @return
*/
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
if (m->pReader) // OVFReader instantiated?
{
size_t i = 0;
++it, ++i)
{
// create a string representing this disk
"%s\t"
"%RI64\t"
"%RI64\t"
"%s\t"
"%s\t"
"%RI64\t"
"%RI64\t"
"%s",
d.iCapacity,
d.iSize,
d.iChunkSize,
d.strCompression.c_str());
// push to safearray
}
}
return S_OK;
}
/**
* Public method implementation.
* @param
* @return
*/
STDMETHODIMP Appliance::COMGETTER(VirtualSystemDescriptions)(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions))
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Public method implementation.
* @param path
* @return
*/
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
if (m->pReader)
{
delete m->pReader;
}
// see if we can handle this file; for now we insist it has an ".ovf" extension
return setError(VBOX_E_FILE_ERROR,
tr("Appliance file must have .ovf extension"));
try
{
/* Parse all necessary info out of the URI */
}
{
}
/* Return progress to the caller */
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
// @todo:
// - don't use COM methods but the methods directly (faster, but needs appropriate locking of that objects itself (s. HardDisk))
// - Appropriate handle errors like not supported file formats
AutoCaller autoCaller(this);
AutoWriteLock(this);
/* Clear any previous virtual system descriptions */
/* We need the default path for storing disk images */
if (!m->pReader)
tr("Cannot interpret appliance without reading it first (call read() before interpret())"));
try
{
/* Iterate through all virtual systems */
++it)
{
/* Guest OS type */
"",
/* VM name */
/* If the there isn't any name specified create a default one out of
* the OS type */
"",
nameVBox);
/* VM Product */
"",
/* VM Vendor */
"",
/* VM Version */
"",
/* VM ProductUrl */
"",
/* VM VendorUrl */
"",
/* VM description */
"",
/* VM license */
"",
/* Now that we know the OS type, get our internal defaults based on that. */
/* CPU count */
/* Check for the constrains */
{
addWarning(tr("The virtual system \"%s\" claims support for %u CPU's, but VirtualBox has support for max %u CPU's only."),
}
cpuCountVBox = 1;
"",
/* RAM */
/* Check for the constrains */
if (ullMemSizeVBox != 0 &&
{
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."),
}
if (vsysThis.ullMemorySize == 0)
{
/* If the RAM of the OVF is zero, use our predefined values */
/* VBox stores that in MByte */
}
"",
/* Audio */
/* Currently we set the AC97 always.
@todo: figure out the hardware which could be possible */
"",
#ifdef VBOX_WITH_USB
/* USB Controller */
#endif /* VBOX_WITH_USB */
/* Network Controller */
if (cEthernetAdapters > 0)
{
/* Check for the constrains */
addWarning(tr("The virtual system \"%s\" claims support for %zu network adapters, but VirtualBox has support for max %u network adapter only."),
/* Get the default network adapter type for the selected guest OS */
/* Iterate through all abstract networks. We support 8 network
* adapters at the maximum, so the first 8 will be added only. */
size_t a = 0;
++itEA, ++a)
{
// make sure it's one of these two
)
/* Figure out the hardware type */
{
/* If the default adapter is already one of the two
* PCNet adapters use the default one. If not use the
* Am79C970A as fallback. */
if (!(defaultAdapterVBox == NetworkAdapterType_Am79C970A ||
}
#ifdef VBOX_WITH_E1000
/* VMWare accidentally write this with VirtualCenter 3.5,
so make sure in this case always to use the VMWare one */
{
/* Check if this OVF was written by VirtualBox */
{
/* If the default adapter is already one of the three
* E1000 adapters use the default one. If not use the
* I82545EM as fallback. */
if (!(defaultAdapterVBox == NetworkAdapterType_I82540EM ||
}
else
/* Always use this one since it's what VMware uses */
}
#endif /* VBOX_WITH_E1000 */
"", // ref
0,
}
}
/* Floppy Drive */
if (vsysThis.fHasFloppyDrive)
/* CD Drive */
/* @todo: I can't disable the CDROM. So nothing to do for now */
/*
if (vsysThis.fHasCdromDrive)
pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, "", "", "");*/
/* Hard disk Controller */
/* Iterate through all hard disk controllers */
++hdcIt)
{
{
case HardDiskController::IDE:
{
/* Check for the constrains */
/* @todo: I'm very confused! Are these bits *one* controller or
if (cIDEused < 4)
{
// @todo: figure out the IDE types
/* Use PIIX4 as default */
strType = "PIIX3";
strType = "ICH6";
strType);
}
else
{
/* Warn only once */
if (cIDEused == 1)
addWarning(tr("The virtual \"%s\" system requests support for more than one IDE controller, but VirtualBox has support for only one."),
}
++cIDEused;
break;
}
case HardDiskController::SATA:
{
#ifdef VBOX_WITH_AHCI
/* Check for the constrains */
if (cSATAused < 1)
{
// @todo: figure out the SATA types
/* We only support a plain AHCI controller, so use them always */
"AHCI");
}
else
{
/* Warn only once */
if (cSATAused == 1)
addWarning(tr("The virtual system \"%s\" requests support for more than one SATA controller, but VirtualBox has support for only one"),
}
++cSATAused;
break;
#else /* !VBOX_WITH_AHCI */
addWarning(tr("The virtual system \"%s\" requests at least one SATA controller but this version of VirtualBox does not provide a SATA controller emulation"),
#endif /* !VBOX_WITH_AHCI */
}
case HardDiskController::SCSI:
{
#ifdef VBOX_WITH_LSILOGIC
/* Check for the constrains */
if (cSCSIused < 1)
{
hdcController = "BusLogic";
}
else
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."),
strControllerID.c_str());
++cSCSIused;
break;
#else /* !VBOX_WITH_LSILOGIC */
addWarning(tr("The virtual system \"%s\" requests at least one SATA controller but this version of VirtualBox does not provide a SCSI controller emulation"),
#endif /* !VBOX_WITH_LSILOGIC */
}
}
}
/* Hard disks */
{
/* Iterate through all hard disks ()*/
++itVD)
{
/* Get the associated disk image */
// @todo:
// - figure out all possible vmdk formats we also support
// - figure out if there is a url specifier for vhd already
// - we need a url specifier for the vdi format
if ( di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#sparse", Utf8Str::CaseInsensitive)
|| di.strFormat.compare("http://www.vmware.com/specifications/vmdk.html#compressed", Utf8Str::CaseInsensitive))
{
/* If the href is empty use the VM name as filename */
if (!strFilename.length())
/* Construct a unique target path */
strFilename.c_str());
/* find the description for the hard disk controller
* that has the same ID as hd.idController */
tr("Cannot find hard disk controller with OVF instance ID %RI32 to which disk \"%s\" should be attached"),
/* controller to attach to, and the bus within that controller */
if (ulSize == 0)
}
else
throw setError(VBOX_E_FILE_ERROR,
}
}
}
}
{
/* On error we clear the list & return */
}
return rc;
}
/**
* Public method implementation.
* @param aProgress
* @return
*/
{
AutoCaller autoCaller(this);
AutoReadLock(this);
if (!m->pReader)
tr("Cannot import machines without reading it first (call read() before importMachines())"));
try
{
}
{
}
/* Return progress to the caller */
return rc;
}
{
AutoCaller autoCaller(this);
AutoReadLock(this);
try
{
/* Check which kind of export the user has requested */
/* Create the explorer object */
rc = explorer->init(li.storageType, li.strPath, li.strHostname, li.strUsername, li.strPassword, mVirtualBox);
}
{
}
/* Return explorer to the caller */
return rc;
}
{
AutoCaller autoCaller(this);
AutoWriteLock(this);
// see if we can handle this file; for now we insist it has an ".ovf" extension
return setError(VBOX_E_FILE_ERROR,
tr("Appliance file must have .ovf extension"));
if (strFormat == "ovf-0.9")
else if (strFormat == "ovf-1.0")
else
return setError(VBOX_E_FILE_ERROR,
try
{
/* Parse all necessary info out of the URI */
}
{
}
/* Return progress to the caller */
return rc;
}
/**
* Public method implementation.
* @return
*/
{
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
}
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualSystemDescription constructor / destructor
//
////////////////////////////////////////////////////////////////////////////////
/**
* COM initializer.
* @return
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Initialize data */
m = new Data();
/* Confirm a successful initialization */
return S_OK;
}
/**
* COM uninitializer.
*/
void VirtualSystemDescription::uninit()
{
delete m;
m = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualSystemDescription public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param
* @return
*/
{
if (!aCount)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Public method implementation.
* @return
*/
STDMETHODIMP VirtualSystemDescription::GetDescription(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
{
if (ComSafeArrayOutIsNull(aTypes) ||
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
if (ComSafeArrayOutIsNull(aTypes) ||
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
if (ComSafeArrayOutIsNull(aValues))
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
switch (aWhich)
{
}
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
#ifndef RT_OS_WINDOWS
#endif /* RT_OS_WINDOWS */
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
)
return E_INVALIDARG;
size_t i = 0;
++it, ++i)
{
if (sfaEnabled[i])
{
}
else
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
return S_OK;
}
/**
* Internal method; adds a new description item to the member list.
* @param aType Type of description for the new item.
* @param strRef Reference item; only used with hard disk controllers.
* @param aOrigValue Corresponding original value from OVF.
* @param aAutoValue Initial configuration value (can be overridden by caller with setFinalValues).
* @param ulSizeMB Weight for IProgress
* @param strExtraConfig Extra configuration; meaning dependent on type.
*/
const Utf8Str &aOrigValue,
const Utf8Str &aAutoValue,
{
vsde.ulIndex = (uint32_t)m->llDescriptions.size(); // each entry gets an index so the client side can reference them
}
/**
* Private method; returns a list of description items containing all the items from the member
* description items of this virtual system that match the given type.
* @param aType
* @return
*/
std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::findByType(VirtualSystemDescriptionType_T aType)
{
++it)
{
}
return vsd;
}
/**
* Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
* the given reference ID. Useful when needing the controller for a particular
* virtual disk.
* @param id
* @return
*/
{
++it)
{
const VirtualSystemDescriptionEntry &d = *it;
switch (d.type)
{
return &d;
break;
}
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// IMachine public methods
//
////////////////////////////////////////////////////////////////////////////////
// This code is here so we won't have to include the appliance headers in the
// IMachine implementation, and we also need to access private appliance data.
/**
* Public method implementation.
* @param appliance
* @return
*/
{
if (!aAppliance)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
try
{
// get name
// get description
// get guest OS
// CPU count
// memory size in MB
// VRAM size?
// BIOS settings?
// 3D acceleration enabled?
// hardware virtualization enabled?
// nested paging enabled?
// HWVirtExVPIDEnabled?
// PAEEnabled?
// snapshotFolder?
// VRDPServer?
// floppy
// CD-ROM ?!?
// ComPtr<IDVDDrive> pDVDDrive;
fDVDEnabled = 1;
// this is more tricky so use the COM method
fUSBEnabled = false;
else
// create a new virtual system
/* Guest OS type */
"",
/* VM name */
"",
// description
"",
/* CPU count*/
"",
/* Memory */
"",
// <const name="HardDiskControllerIDE" value="6" />
switch(ctlr)
{
}
{
strVbox);
}
#ifdef VBOX_WITH_AHCI
// <const name="HardDiskControllerSATA" value="7" />
{
strVbox = "AHCI";
strVbox);
}
#endif // VBOX_WITH_AHCI
#ifdef VBOX_WITH_LSILOGIC
// <const name="HardDiskControllerSCSI" value="8" />
{
{
switch(ctlr)
{
}
strVbox);
}
else
throw rc;
}
#endif // VBOX_WITH_LSILOGIC
// <const name="HardDiskImage" value="9" />
++itA)
{
// the attachment's data
// force reading state, or else size will be returned as 0
// and how this translates to the virtual system
int32_t lControllerVsys = 0;
switch (storageBus)
{
case StorageBus_IDE:
// this is the exact reverse to what we're doing in Appliance::taskThreadImportMachines,
// and it must be updated when that is changed!
lChannelVsys = 0;
lChannelVsys = 1;
lChannelVsys = 2;
else
throw setError(VBOX_E_NOT_SUPPORTED,
break;
case StorageBus_SATA:
break;
case StorageBus_SCSI:
break;
default:
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Cannot handle hard disk attachment: storageBus is %d, channel is %d, device is %d"), storageBus, lChannel, lDevice);
break;
}
strTargetVmdkName, // disk ID: let's use the name
strTargetVmdkName, // OVF value:
}
/* Floppy Drive */
if (fFloppyEnabled)
/* CD Drive */
if (fDVDEnabled)
// <const name="NetworkAdapter" />
size_t a;
for (a = 0;
++a)
{
/* Enable the network card & set the adapter type */
if (fEnabled)
{
switch (attachmentType)
{
strAttachmentType = "Null";
break;
strAttachmentType = "NAT";
break;
strAttachmentType = "Bridged";
break;
strAttachmentType = "Internal";
break;
strAttachmentType = "HostOnly";
break;
}
"", // ref
strAttachmentType, // orig
0,
}
}
// <const name="USBController" />
#ifdef VBOX_WITH_USB
if (fUSBEnabled)
#endif /* VBOX_WITH_USB */
// <const name="SoundCard" />
if (fAudioEnabled)
{
"",
"ensoniq1371", // this is what OVFTool writes and VMware supports
}
// finally, add the virtual system to the appliance
/* We return the new description to the caller */
}
{
}
return rc;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */