ApplianceImplImport.cpp revision 7a71f66d53a7dcdf19a7a357e99e560fda812dc3
/* $Id$ */
/** @file
*
* IAppliance and IVirtualSystem COM class implementations.
*/
/*
* Copyright (C) 2008-2010 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 <iprt/manifest.h>
#include "ApplianceImpl.h"
#include "VFSExplorerImpl.h"
#include "VirtualBoxImpl.h"
#include "GuestOSTypeImpl.h"
#include "ProgressImpl.h"
#include "MachineImpl.h"
#include "MediumImpl.h"
#include "HostNetworkInterfaceImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "ApplianceImplPrivate.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//
// IAppliance public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* 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);
if (!isApplianceIdle())
return E_ACCESSDENIED;
/* 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())"));
// Change the appliance state so we can safely leave the lock while doing time-consuming
// disk imports; also the below method calls do all kinds of locking which conflicts with
// the appliance object lock
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 */
if (vsysThis.fHasCdromDrive)
/* 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 */
}
// reset the appliance state
return rc;
}
/**
* Public method implementation.
* @param aProgress
* @return
*/
{
AutoCaller autoCaller(this);
// do not allow entering this method if the appliance is busy reading or writing
if (!isApplianceIdle())
return E_ACCESSDENIED;
if (!m->pReader)
tr("Cannot import machines without reading it first (call read() before importMachines())"));
try
{
}
{
}
/* Return progress to the caller */
return rc;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance private methods
//
////////////////////////////////////////////////////////////////////////////////
/**
*
* @param aLocInfo
* @param aProgress
* @return
*/
{
/* 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;
}
/**
*
* @param pTask
* @return
*/
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
try
{
/* Read & parse the XML structure of the OVF file */
/* Create the SHA1 sum of the OVF file for later validation */
char *pszDigest;
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Couldn't calculate SHA1 digest for file '%s' (%Rrc)"),
m->strOVFSHA1Digest = pszDigest;
}
{
x.what());
}
{
}
return VINF_SUCCESS;
}
/**
*
* @param pTask
* @return
*/
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(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(vrc))
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,
tr("Cannot download file '%s' from S3 storage server (Access denied). Make sure that your credentials are right. Also check that your host clock is properly synced"), pszFilename);
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;
}
/**
* Helper that converts VirtualSystem attachment values into VirtualBox attachment values.
* Throws HRESULT values on errors!
*
* @param hdc
* @param vd
* @param mhda
*/
{
{
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 (ulAddressOnParent)
{
case 0: // interpret this as primary master
lChannel = (long)0;
lDevice = (long)0;
break;
case 1: // interpret this as primary slave
lChannel = (long)0;
lDevice = (long)1;
break;
case 2: // interpret this as secondary master
lChannel = (long)1;
lDevice = (long)0;
break;
case 3: // interpret this as secondary slave
lChannel = (long)1;
lDevice = (long)1;
break;
default:
throw setError(VBOX_E_NOT_SUPPORTED,
break;
}
break;
case HardDiskController::SATA:
lChannel = (long)ulAddressOnParent;
lDevice = (long)0;
break;
case HardDiskController::SCSI:
lChannel = (long)ulAddressOnParent;
lDevice = (long)0;
break;
default: break;
}
}
/**
* Implementation of the import code. This gets called from the public Appliance::ImportMachines()
* method as well as Appliance::importS3().
* @param aLocInfo
* @param aProgress
* @return
*/
{
/* 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;
}
/**
*
* @return
*/
{
"Appliance::Task");
return S_OK;
}
/**
*
* @param pTask
* @return
*/
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(this);
if (!isApplianceIdle())
return VERR_ACCESS_DENIED;
// Change the appliance state so we can safely leave the lock while doing time-consuming
// disk imports; also the below method calls do all kinds of locking which conflicts with
// the appliance object lock
// rollback for errors:
bool fSessionOpen = false;
// this is safe to access because this thread only gets started
// if pReader != NULL
/* If an manifest file exists, verify the content. Therefore we need all
* files which are referenced by the OVF & the OVF itself */
{
/* Add every disks of every virtual system to an internal list */
++it)
{
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
++itH)
{
/* Find the disk from the OVF's disk list */
}
}
/* Create the test list */
PRTMANIFESTTEST pTestList = (PRTMANIFESTTEST)RTMemAllocZ(sizeof(RTMANIFESTTEST)*(filesList.size()+1));
int vrc = VINF_SUCCESS;
size_t i = 1;
++it1, ++i)
{
char* pszDigest;
}
if (vrc == VERR_MANIFEST_DIGEST_MISMATCH)
tr("The SHA1 digest of '%s' doesn't match to the one in '%s'"),
else if (RT_FAILURE(vrc))
tr("Couldn't verify the content of '%s' against the available files (%Rrc)"),
vrc);
/* Cleanup */
for (size_t j = 1;
++j)
{
/* Return on error */
return rc;
}
}
/* 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 */
for (size_t j = 0;
j < nwInterfaces.size();
++j)
{
{
/* 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 */
for (size_t j = 0;
j < nwInterfaces.size();
++j)
{
{
/* Set the interface name to attach to */
break;
}
}
}
}
}
/* 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; import facility only supports one"));
{
rc = pNewMachine->AddStorageController(Bstr("IDE Controller"), StorageBus_IDE, pController.asOutParam());
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; import facility only supports one"));
if (vsdeHDCSATA.size() > 0)
{
if (hdcVBox == "AHCI")
{
rc = pNewMachine->AddStorageController(Bstr("SATA Controller"), StorageBus_SATA, pController.asOutParam());
}
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; import facility 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\""),
rc = pNewMachine->AddStorageController(Bstr("SCSI Controller"), StorageBus_SCSI, pController.asOutParam());
}
#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
// Add floppies and CD-ROMs to the appropriate controllers.
std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);
throw setError(VBOX_E_FILE_ERROR,
tr("Too many floppy controllers in OVF; import facility only supports one"));
std::list<VirtualSystemDescriptionEntry*> vsdeCDROM = vsdescThis->findByType(VirtualSystemDescriptionType_CDROM);
if ( (vsdeFloppy.size() > 0)
)
{
// If there's an error here we need to close the session, so
try
{
/* In order to attach things we need to open a session
* for the new machine */
fSessionOpen = true;
// floppy first
{
rc = sMachine->AddStorageController(Bstr("Floppy Controller"), StorageBus_Floppy, pController.asOutParam());
// this is for rollback later
Log(("Attaching floppy\n"));
NULL);
}
// CD-ROMs next
++jt)
{
// for now always attach to secondary master on IDE controller;
// there seems to be no useful information in OVF where else to
// attach jt (@todo test with latest versions of OVF software)
// find the IDE controller
++kt)
{
{
}
}
if (!pController)
throw setError(VBOX_E_FILE_ERROR,
tr("OVF wants a CD-ROM drive but cannot find IDE controller, which is required in this version of VirtualBox"));
// this is for rollback later
2, // interpreted as secondary master
NULL);
} // 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;
}
}
/* Create the hard disks & connect them to the appropriate controllers. */
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
{
// If there's an error here we need to close the session, so
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. */
)
/* 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, MediumVariant_Standard, pProgress2.asOutParam());
/* Advance to the next operation */
pTask->progress->SetNextOperation(BstrFmt(tr("Creating virtual disk image '%s'"), vsdeHD->strVbox.c_str()),
}
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 */
false,
NULL,
false,
NULL,
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
Log(("Attaching disk %s to channel %d on device %d\n", vsdeHD->strVbox.c_str(), mhda.lChannel, mhda.lDevice));
hdId);
} // 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)
{
}
}
// restore the appliance state
return VINF_SUCCESS;
}
/**
*
* @param pTask
* @return
*/
{
LogFlowFunc(("Appliance %p\n", this));
AutoCaller autoCaller(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(vrc))
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,
tr("Cannot download file '%s' from S3 storage server (Access denied). Make sure that your credentials are right. Also check that your host clock is properly synced"), pszFilename);
else if(vrc == VERR_S3_NOT_FOUND)
throw setError(VBOX_E_FILE_ERROR,
else
throw setError(VBOX_E_IPRT_ERROR,
}
}
/* Provide a OVF file (haven't to exist) so the import routine can
/* Now check if there is an manifest file. This is optional. */
/* Try to download it. If the error is VERR_S3_NOT_FOUND, it isn't fatal. */
if (RT_SUCCESS(vrc))
else if (RT_FAILURE(vrc))
{
if(vrc == VERR_S3_CANCELED)
throw S_OK; /* todo: !!!!!!!!!!!!! */
else if(vrc == VERR_S3_NOT_FOUND)
else if(vrc == VERR_S3_ACCESS_DENIED)
throw setError(E_ACCESSDENIED,
tr("Cannot download file '%s' from S3 storage server (Access denied). Make sure that your credentials are right. Also check that your host clock is properly synced"), pszFilename);
else
throw setError(VBOX_E_IPRT_ERROR,
}
/* Close the connection early */
/* Import the whole temporary OVF & the disk images */
/* 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;
}