ApplianceImplExport.cpp revision eabb39201b755d8ca4941927552684e88b076746
/* $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 "VirtualBoxImpl.h"
#include "ProgressImpl.h"
#include "MachineImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "ApplianceImplPrivate.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//
// 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);
try
{
// create a new virtual system to store in the appliance
// store the machine object so we can dump the XML in Appliance::Write()
// now fill it with description items
// first, call the COM methods, as they request locks
fUSBEnabled = false;
else
// request the machine lock while acessing internal members
// 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?
/* Guest OS type */
"",
/* VM name */
"",
// description
"",
/* CPU count*/
"",
/* Memory */
"",
// the one VirtualBox IDE controller has two channels with two ports each, which is
// considered two IDE controllers with two ports each by OVF, so export it as two
/* Fetch all available storage controllers */
#ifdef VBOX_WITH_AHCI
#endif /* VBOX_WITH_AHCI */
#ifdef VBOX_WITH_LSILOGIC
#endif /* VBOX_WITH_LSILOGIC */
{
if ( eType == StorageBus_IDE
&& pIDEController.isNull())
pIDEController = nwControllers[j];
#ifdef VBOX_WITH_AHCI
else if ( eType == StorageBus_SATA
&& pSATAController.isNull())
pSATAController = nwControllers[j];
#endif /* VBOX_WITH_AHCI */
#ifdef VBOX_WITH_LSILOGIC
else if ( eType == StorageBus_SCSI
&& pSATAController.isNull())
pSCSIController = nwControllers[j];
#endif /* VBOX_WITH_LSILOGIC */
}
// <const name="HardDiskControllerIDE" value="6" />
if (!pIDEController.isNull())
{
switch(ctlr)
{
}
{
strVbox, // aOvfValue
strVbox); // aVboxValue
strVbox);
}
}
#ifdef VBOX_WITH_AHCI
// <const name="HardDiskControllerSATA" value="7" />
if (!pSATAController.isNull())
{
strVbox);
}
#endif // VBOX_WITH_AHCI
#ifdef VBOX_WITH_LSILOGIC
// <const name="HardDiskControllerSCSI" value="8" />
if (!pSCSIController.isNull())
{
{
switch(ctlr)
{
}
strVbox);
}
else
throw rc;
}
#endif // VBOX_WITH_LSILOGIC
// <const name="HardDiskImage" value="9" />
// <const name="Floppy" value="18" />
// <const name="CDROM" value="19" />
++itA)
{
// the attachment's data
if ( deviceType == DeviceType_HardDisk
&& pMedium
)
{
// find the source's base medium for two things:
// 1) we'll use its name to determine the name of the target disk, which is readable,
// as opposed to the UUID filename of a differencing image, if pMedium is one
// 2) we need the size of the base image so we can give it to addEntry(), and later
// on export, the progress will be based on that (and not the diff image)
// returns pMedium if there are no diff images
// 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!
// Before 3.2 we exported one IDE controller with channel 0-3, but we now maintain
// compatibility with what VMware does and export two IDE controllers with two channels each
{
lChannelVsys = 0;
}
{
lChannelVsys = 1;
}
else if (lChannel == 1 && lDevice == 0) // secondary master; by default this is the CD-ROM but as of VirtualBox 3.1 that can change
{
lChannelVsys = 0;
}
{
lChannelVsys = 1;
}
else
throw setError(VBOX_E_NOT_SUPPORTED,
break;
case StorageBus_SATA:
break;
case StorageBus_SCSI:
break;
case StorageBus_Floppy:
lChannelVsys = 0;
lControllerVsys = 0;
break;
default:
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Cannot handle medium attachment: storageBus is %d, channel is %d, device is %d"), storageBus, lChannel, lDevice);
break;
}
switch (deviceType)
{
case DeviceType_HardDisk:
strTargetVmdkName, // disk ID: let's use the name
strTargetVmdkName, // OVF value:
strLocation, // vbox value: media path
strExtra);
break;
case DeviceType_DVD:
strEmpty, // disk ID
strEmpty, // OVF value
strEmpty, // vbox value
1, // ulSize
strExtra);
break;
case DeviceType_Floppy:
strEmpty, // disk ID
strEmpty, // OVF value
strEmpty, // vbox value
1, // ulSize
strExtra);
break;
}
}
// <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;
}
////////////////////////////////////////////////////////////////////////////////
//
// IAppliance public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param format
* @param path
* @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;
// 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;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance private methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Implementation for writing out the OVF to disk. This starts a new thread which will call
* Appliance::taskThreadWriteOVF().
*
* This is in a separate private method because it is used from two locations:
*
* 1) from the public Appliance::Write().
* 2) from Appliance::writeS3(), which got called from a previous instance of Appliance::taskThreadWriteOVF().
*
* @param aFormat
* @param aLocInfo
* @param aProgress
* @return
*/
HRESULT Appliance::writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
{
try
{
rc = setUpProgress(aProgress, progressDesc, (aLocInfo.storageType == VFSType_File) ? Regular : WriteS3);
/* Initialize our worker task */
/* The OVF version to write */
/* Don't destruct on success */
}
{
}
return rc;
}
/**
* Called from Appliance::writeFS() for each virtual system (machine) that needs XML written out.
*
* @param elmToAddVirtualSystemsTo XML element to append elements to.
* @param vsdescThis The IVirtualSystemDescription instance for which to write XML.
* @param enFormat OVF format (0.9 or 1.0).
* @param stack Structure for temporary private data shared with caller.
*/
{
LogFlowFunc(("ENTER appliance %p\n", this));
{
// <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 idSATAController = 0;
uint32_t idSCSIController = 0;
{
int32_t lIndexThis = 0;
++itD, ++lIndexThis)
{
LogFlowFunc(("Loop %u: handling description entry ulIndex=%u, type=%s, strRef=%s, strOvf=%s, strVbox=%s, strExtraConfig=%s\n",
{
/* <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";
{
// first IDE controller:
strCaption = "ideController0";
lAddress = 0;
lBusNumber = 0;
// remember this ID
}
else
{
// second IDE controller:
strCaption = "ideController1";
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>
{
else if (lControllerIndex == lIDESecondaryControllerIndex)
else if (lControllerIndex == lSCSIControllerIndex)
else if (lControllerIndex == lSATAControllerIndex)
}
LogFlowFunc(("HardDiskImage details: pos1=%d, pos2=%d, lControllerIndex=%d, lIDEPrimaryControllerIndex=%d, lIDESecondaryControllerIndex=%d, ulParent=%d, lAddressOnParent=%d\n",
pos1, pos2, lControllerIndex, lIDEPrimaryControllerIndex, lIDESecondaryControllerIndex, ulParent, lAddressOnParent));
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 (!idIDESecondaryController)
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Can't have CD-ROM without secondary 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 (enFormat == 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 = 1; uLoop <= 2; ++uLoop)
// now that we're done with the official OVF <Item> tags under <VirtualSystem>, write out VirtualBox XML
// under the vbox: namespace
try
{
// but not BuildMachineXML_IncludeSnapshots
delete pConfig;
}
catch (...)
{
delete pConfig;
throw;
}
}
/**
* Actual worker code for writing out OVF to disk. This is called from Appliance::taskThreadWriteOVF()
* and therefore runs on the OVF write worker thread. This runs in two contexts:
*
* 1) in a first worker thread; in that case, Appliance::Write() called Appliance::writeImpl();
*
* 2) in a second worker thread; in that case, Appliance::Write() called Appliance::writeImpl(), which
* called Appliance::writeS3(), which called Appliance::writeImpl(), which then called this. In other
* words, to write to the cloud, the first worker thread first starts a second worker thread to create
* temporary files and then uploads them to the S3 cloud server.
*
* @param pTask
* @return
*/
HRESULT Appliance::writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress)
{
LogFlowFunc(("ENTER appliance %p\n", this));
AutoCaller autoCaller(this);
try
{
AutoMultiWriteLock2 multiLock(&mVirtualBox->getMediaTreeLockHandle(), this->lockHandle() COMMA_LOCKVAL_SRC_POS);
? "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
// the XML stack contains two maps for disks and networks, which allows us to
// a) have a list of unique disk names (to make sure the same disk name is only added once)
// and b) keep a list of all networks
/* <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
// and here come the virtual systems:
// This can take a very long time so leave the locks; in particular, we have the media tree
// lock which Medium::CloneTo() will request, and that would deadlock. Instead, protect
// the appliance by resetting its state so we can safely leave the lock
// 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"));
}
else
/* Iterate throughs all virtual systems of that appliance */
++it)
{
stack); // disks and networks stack
}
// now, fill in the network section we set up empty above according
// to the networks we found with the hardware items
++itN)
{
}
// Finally, write out the disks!
++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());
// clone the disk:
// output filename
// target path needs to be composed from where the output OVF is
// We are always exporting to VMDK 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, MediumVariant_VmdkStreamOptimized, NULL, pProgress2.asOutParam());
// advance to the next operation
// 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 rc3;
}
// 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
/* Create & write the manifest file */
size_t i = 1;
++it1, ++i)
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Couldn't create manifest file '%s' (%Rrc)"),
}
{
x.what());
}
{
}
// reset the state so others can call methods again
return rc;
}
/**
* Worker code for writing out OVF to the cloud. This is called from Appliance::taskThreadWriteOVF()
* in S3 mode and therefore runs on the OVF write worker thread. This then starts a second worker
* thread to create temporary files (see Appliance::writeFS()).
*
* @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;
// 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(vrc))
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 */
filesList.push_back(pair<Utf8Str, ULONG>(strMfFile , m->ulWeightPerOperation)); /* Use 1% of the total for the manifest 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,
tr("Cannot upload file '%s' to 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,
}
}
}
{
}
/* 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 rc;
}