ApplianceImplExport.cpp revision 5e363664ceebe79185d44c3a1f354a39913e411a
/* $Id$ */
/** @file
* IAppliance and IVirtualSystem COM class implementations.
*/
/*
* Copyright (C) 2008-2014 Oracle Corporation
*
* 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.
*/
#include <iprt/manifest.h>
#include "ApplianceImpl.h"
#include "VirtualBoxImpl.h"
#include "ProgressImpl.h"
#include "MachineImpl.h"
#include "MediumImpl.h"
#include "MediumFormatImpl.h"
#include "Global.h"
#include "SystemPropertiesImpl.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
*/
STDMETHODIMP Machine::ExportTo(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription)
{
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()
// first, call the COM methods, as they request locks
{
for (unsigned i = 0; i < usbControllers.size(); i++)
{
if (enmType == USBControllerType_OHCI)
fUSBEnabled = TRUE;
}
}
// request the machine lock while accessing 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?
// Long mode enabled?
// 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 */
{
if ( eType == StorageBus_IDE
&& pIDEController.isNull())
pIDEController = nwControllers[j];
else if ( eType == StorageBus_SATA
&& pSATAController.isNull())
pSATAController = nwControllers[j];
else if ( eType == StorageBus_SCSI
&& pSATAController.isNull())
pSCSIController = nwControllers[j];
else if ( eType == StorageBus_SAS
&& pSASController.isNull())
pSASController = nwControllers[j];
}
// <const name="HardDiskControllerIDE" value="6" />
if (!pIDEController.isNull())
{
switch(ctlr)
{
}
{
strVBox, // aOvfValue
strVBox); // aVBoxValue
strVBox);
}
}
// <const name="HardDiskControllerSATA" value="7" />
if (!pSATAController.isNull())
{
strVBox);
}
// <const name="HardDiskControllerSCSI" value="8" />
if (!pSCSIController.isNull())
{
{
switch(ctlr)
{
}
strVBox);
}
else
throw rc;
}
if (!pSASController.isNull())
{
// VirtualBox considers the SAS controller a class of its own but in OVF
// it should be a SCSI controller
strVBox);
}
// <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
throw setError(VBOX_E_NOT_SUPPORTED,
// force reading state, or else size will be returned as 0
}
else if ( deviceType == DeviceType_DVD
&& pMedium)
{
/*
* check the minimal rules to grant access to export an image
* 2. the image must be accessible and readable
* 3. only ISO image is exported
*/
BOOL fHostDrive = false;
if(fHostDrive)
continue;
//2. the image must be accessible and readable
if (ms != MediumState_Created)
continue;
//3. only ISO image is exported
if (eq != 0)
continue;
throw setError(VBOX_E_NOT_SUPPORTED,
}
// 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:
case StorageBus_SAS:
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:
strTargetImageName, // disk ID: let's use the name
strTargetImageName, // OVF value:
strLocation, // vbox value: media path
strExtra);
break;
case DeviceType_DVD:
strTargetImageName, // disk ID
strTargetImageName, // OVF value
strLocation, // vbox value
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 < maxNetworkAdapters; ++a)
{
/* Enable the network card & set the adapter type */
if (fEnabled)
{
"", // 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
/* We return the new description to the caller */
// finally, add the virtual system to the appliance
}
{
}
return rc;
}
////////////////////////////////////////////////////////////////////////////////
//
// IAppliance public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param format
* @param options
* @param path
* @param aProgress
* @return
*/
{
m->optListExport.clear();
{
{
}
}
// AssertReturn(!(m->optListExport.contains(ExportOptions_CreateManifest) && m->optListExport.contains(ExportOptions_ExportDVDImages)), E_INVALIDARG);
if (!m->fExportISOImages)/* remove all ISO images from VirtualSystemDescription */
{
++it)
{
std::list<VirtualSystemDescriptionEntry*> skipped = vsdescThis->i_findByType(VirtualSystemDescriptionType_CDROM);
{
(*pItSkipped)->skipIt = true;
++pItSkipped;
}
}
}
// do not allow entering this method if the appliance is busy reading or writing
if (!i_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 or .ova extension"));
if (aFormat == "ovf-0.9")
{
}
else if (aFormat == "ovf-1.0")
{
}
else if (aFormat == "ovf-2.0")
{
}
else
return setError(VBOX_E_FILE_ERROR,
/* as of OVF 2.0 we have to use SHA256 */
try
{
/* Parse all necessary info out of the URI */
}
{
}
/* Return progress to the caller */
return rc;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance private methods
//
////////////////////////////////////////////////////////////////////////////////
/*******************************************************************************
* Export stuff
******************************************************************************/
/**
* 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) in a second worker thread; in that case, Appliance::Write() called Appliance::i_writeImpl(), which
* called Appliance::i_writeFSOVA(), which called Appliance::i_writeImpl(), which then called this again.
*
* 3) from Appliance::i_writeS3(), which got called from a previous instance of Appliance::taskThreadWriteOVF().
*
* @param aFormat
* @param aLocInfo
* @param aProgress
* @return
*/
HRESULT Appliance::i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
{
try
{
/* Initialize our worker task */
/* The OVF version to write */
/* Don't destruct on success */
}
{
}
return rc;
}
/**
* Called from Appliance::i_writeFS() for creating a XML document for this
* Appliance.
*
* @param writeLock The current write lock.
* @param doc The xml document to fill.
* @param stack Structure for temporary private
* data shared with caller.
* @param strPath Path to the target OVF.
* instance for which to write XML.
* @param enFormat OVF format (0.9 or 1.0).
*/
{
: "0.9");
{
}
{
}
else
{
}
// 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="..." ovf:populatedSize="1924967692"/>
</DiskSection> */
{
// <Section xsi:type="ovf:DiskSection_Type">
}
else
/* <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:
// 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
// this list receives pointers to the XML elements in the machine XML which
// might have UUIDs that need fixing after we know the UUIDs of the exported images
/* Iterate through 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 disk info
++itS)
{
// source path: where the VBox image is
//skip empty Medium. There are no information to add into section <References> or <DiskSection>
if (strSrcFilePath.isEmpty() ||
pDiskEntry->skipIt == true)
continue;
// Do NOT check here whether the file exists. FindMedium will figure
// that out, and filesystem-based tests are simply wrong in the
// general case (think of iSCSI).
// We need some info from the source disks
//DeviceType_T deviceType = DeviceType_HardDisk;// by default
{
FALSE /* fForceNewUuid */,
throw rc;
}
{
throw rc;
}
// output filename
// target path needs to be composed from where the output OVF is
// We are always exporting to VMDK stream optimized for now
//Bstr bstrSrcFormat = L"VMDK";//not used
// Todo r=poetzsch: wrong it is reported in bytes ...
// capacity is reported in megabytes, so...
//cbCapacity *= _1M;
guidTarget.create();
// now handle the XML for the disk:
// <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/>
// Todo: the actual size is not available at this point of time,
// cause the disk will be compressed. The 1.0 standard says this is
// optional! 1.1 isn't fully clear if the "gzip" format is used.
// Need to be checked. */
// pelmFile->setAttribute("ovf:size", Utf8StrFmt("%RI64", cbFile).c_str());
// add disk to XML Disks section
// <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="..."/>
if (pDiskEntry->type == VirtualSystemDescriptionType_HardDiskImage)//deviceType == DeviceType_HardDisk
{
? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftool ch
: "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"
// correct string as communicated to us by VMware (public bug #6612)
);
}
else //pDiskEntry->type == VirtualSystemDescriptionType_CDROM, deviceType == DeviceType_DVD
{
);
}
// add the UUID of the newly target image to the OVF disk element, but in the
// vbox: namespace since it's not part of the standard
// now, we might have other XML elements from vbox:Machine pointing to this image,
// but those would refer to the UUID of the _source_ image (which we created the
// export image from); those UUIDs need to be fixed to the export image
++eit)
{
if (strUUID == strGuidSourceCurly)
// overwrite existing uuid attribute
}
}
}
/**
* Called from Appliance::i_buildXML() for each virtual system (machine) that
* needs XML written out.
*
* @param writeLock The current write lock.
* @param elmToAddVirtualSystemsTo XML element to append elements to.
* @param pllElementsWithUuidAttributes out: list of XML elements produced here
* with UUID attributes for quick
* fixing by caller later
* @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->i_findByType(VirtualSystemDescriptionType_Name);
// product info
std::list<VirtualSystemDescriptionEntry*> llProduct = vsdescThis->i_findByType(VirtualSystemDescriptionType_Product);
std::list<VirtualSystemDescriptionEntry*> llProductUrl = vsdescThis->i_findByType(VirtualSystemDescriptionType_ProductUrl);
std::list<VirtualSystemDescriptionEntry*> llVendor = vsdescThis->i_findByType(VirtualSystemDescriptionType_Vendor);
std::list<VirtualSystemDescriptionEntry*> llVendorUrl = vsdescThis->i_findByType(VirtualSystemDescriptionType_VendorUrl);
std::list<VirtualSystemDescriptionEntry*> llVersion = vsdescThis->i_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->i_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->i_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->i_findByType(VirtualSystemDescriptionType_OS);
/* <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");
// add the VirtualBox ostype in a custom tag in a different namespace
// <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";
strResourceSubType = "lsilogicsas";
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,
tr("Missing or bad extra config string in hard disk image: \"%s\""), desc.strExtraConfigCurrent.c_str());
}
break;
if (uLoop == 1)
{
strDescription = "Floppy Drive";
lAutomaticAllocation = 0;
lAddressOnParent = 0; // this is what OVFTool writes
}
break;
/* <Item>
<rasd:Caption>cdrom1</rasd:Caption>
<rasd:InstanceId>8</rasd:InstanceId>
<rasd:ResourceType>15</rasd:ResourceType>
<rasd:Parent>4</rasd:Parent>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
</Item> */
if (uLoop == 2)
{
//uint32_t cDisks = stack.mapDisks.size();
strDescription = "CD-ROM Drive";
lAutomaticAllocation = 1;
//skip empty Medium. There are no information to add into section <References> or <DiskSection>
{
// the following references the "<Disks>" XML block
}
// controller=<index>;channel=<c>
{
else if (lControllerIndex == lIDESecondaryControllerIndex)
else if (lControllerIndex == lSCSIControllerIndex)
else if (lControllerIndex == lSATAControllerIndex)
}
LogFlowFunc(("DVD drive 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,
tr("Missing or bad extra config string in DVD drive medium: \"%s\""), desc.strExtraConfigCurrent.c_str());
// there is no DVD drive map to update because it is
// handled completely with this entry.
}
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 == 2)
{
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)
{
{
if(uLoop == 2)
{
{
itemElement = "epasd:";
}
{
itemElement = "sasd:";
}
else
}
else
{
itemElement = "rasd:";
}
}
else
{
itemElement = "rasd:";
}
// NOTE: DO NOT CHANGE THE ORDER of these items! The OVF standards prescribes that
// the elements from the rasd: namespace must be sorted by letter, and VMware
// actually requires this as well (see public bug #6612)
if (lAddress != -1)
{
//pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress));
}
if (lAddressOnParent != -1)
{
//pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent));
}
if (!strAllocationUnits.isEmpty())
{
//pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits);
}
if (lAutomaticAllocation != -1)
{
//pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" );
}
if (lBusNumber != -1)
{
{
// BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool
//pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber));
}
}
if (!strCaption.isEmpty())
{
//pItem->createChild("rasd:Caption")->addContent(strCaption);
}
if (!strConnection.isEmpty())
{
//pItem->createChild("rasd:Connection")->addContent(strConnection);
}
if (!strDescription.isEmpty())
{
//pItem->createChild("rasd:Description")->addContent(strDescription);
}
if (!strCaption.isEmpty())
{
{
//pItem->createChild("rasd:ElementName")->addContent(strCaption);
}
}
if (!strHostResource.isEmpty())
{
//pItem->createChild("rasd:HostResource")->addContent(strHostResource);
}
{
// <rasd:InstanceID>1</rasd:InstanceID>
//pelmInstanceID = pItem->createChild("rasd:InstanceId");
else
//pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed...
}
if (ulParent)
{
//pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent));
}
if (!strResourceSubType.isEmpty())
{
//pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType);
}
{
// <rasd:ResourceType>3</rasd:ResourceType>
//pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type));
}
// <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
if (lVirtualQuantity != -1)
{
//pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity));
}
}
}
} // 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
// ovf:required="false" tells other OVF parsers that they can ignore this thing
// ovf:Info element is required or VMware will bail out on the vbox:Machine element
pelmVBoxMachine->createChild("ovf:Info")->addContent("Complete VirtualBox machine configuration in VirtualBox format");
// create an empty machine config
try
{
// fill the machine config
// Apply export tweaks to machine settings
if (fStripAllMACs || fStripAllNonNATMACs)
{
for (settings::NetworkAdaptersList::iterator it = pConfig->hardwareMachine.llNetworkAdapters.begin();
++it)
{
}
}
// write the machine config to the vbox:Machine element
/*| settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia*/
// but not BuildMachineXML_IncludeSnapshots nor BuildMachineXML_MediaRegistry
delete pConfig;
}
catch (...)
{
delete pConfig;
throw;
}
}
/**
* Actual worker code for writing out OVF/OVA to disk. This is called from Appliance::taskThreadWriteOVF()
*
* 1) in a first worker thread; in that case, Appliance::Write() called Appliance::i_writeImpl();
*
* 2) in a second worker thread; in that case, Appliance::Write() called Appliance::i_writeImpl(), which
* called Appliance::i_writeS3(), which called Appliance::i_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
*/
{
LogFlowFunc(("ENTER appliance %p\n", this));
AutoCaller autoCaller(this);
// Lock the media tree early to make sure nobody else tries to make changes
// to the tree. Also lock the IAppliance object for writing.
AutoMultiWriteLock2 multiLock(&mVirtualBox->i_getMediaTreeLockHandle(), this->lockHandle() COMMA_LOCKVAL_SRC_POS);
// Additional protect the IAppliance object, cause we leave the lock
// when starting the disk export and we don't won't block other
// callers on this lengthy operations.
else
// reset the state so others can call methods again
return rc;
}
{
PVDINTERFACEIO pShaIo = 0;
PVDINTERFACEIO pFileIo = 0;
do
{
pShaIo = ShaCreateInterface();
if (!pShaIo)
{
rc = E_OUTOFMEMORY;
break;
}
if (!pFileIo)
{
rc = E_OUTOFMEMORY;
break;
}
VDINTERFACETYPE_IO, 0, sizeof(VDINTERFACEIO),
if (RT_FAILURE(vrc))
{
break;
}
} while (0);
/* Cleanup */
if (pShaIo)
if (pFileIo)
return rc;
}
{
int vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);
if (RT_FAILURE(vrc))
return setError(VBOX_E_FILE_ERROR,
tr("Could not create OVA file '%s' (%Rrc)"),
PVDINTERFACEIO pShaIo = 0;
PVDINTERFACEIO pTarIo = 0;
do
{
pShaIo = ShaCreateInterface();
if (!pShaIo)
{
rc = E_OUTOFMEMORY;
break;
}
if (!pTarIo)
{
rc = E_OUTOFMEMORY;
break;
}
if (RT_FAILURE(vrc))
{
break;
}
} while (0);
/* Cleanup */
if (pShaIo)
if (pTarIo)
/* Delete ova file on error */
return rc;
}
HRESULT Appliance::i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pIfIo, PSHASTORAGE pStorage)
{
try
{
int vrc;
// 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
// Scope this to free the memory as soon as this is finished
{
// Create a xml document
// Now fully build a valid ovf document in memory
/* Extract the OVA file name */
/* Extract the path */
// Create a memory buffer containing the XML. */
void *pvBuf = 0;
if (RT_UNLIKELY(!pvBuf))
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create OVF file '%s'"),
strOvfFile.c_str());
/* Write the ovf file to disk. */
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create OVF file '%s' (%Rrc)"),
}
// We need a proper format description
// Scope for the AutoReadLock
{
// We are always exporting to VMDK stream optimized for now
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Invalid medium storage format"));
}
// Finally, write out the disks!
++itS)
{
// source path: where the VBox image is
if (strSrcFilePath.isEmpty() ||
pDiskEntry->skipIt == true)
continue;
// Do NOT check here whether the file exists. findHardDisk will
// figure that out, and filesystem-based tests are simply wrong
// in the general case (think of iSCSI).
// clone the disk:
{
}
else//may be CD or DVD
{
NULL,
true,
&pSourceDisk);
}
// output filename
// target path needs to be composed from where the output OVF is
.append("/")
// The exporting requests a lock on the media tree. So leave our lock temporary.
try
{
// advance to the next operation
// create a flat copy of the source disk image
{
rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"),
// now wait for the background disk operation to complete; this throws HRESULTs on error
}
else
{
{
void *pvStorage;
0,
&pvStorage);
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create or open file '%s' (%Rrc)"),
{
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create or open file '%s' (%Rrc)"),
}
if (RT_SUCCESS(vrc))
{
if (pvTmpBuf)
{
/* The copy loop. */
uint64_t offDstFile = 0;
for (;;)
{
break;
&cbWritten);
if (RT_FAILURE(vrc))
break;
offDstFile += cbWritten;
}
}
else
}
if (RT_FAILURE(vrc))
{
vrc = VINF_SUCCESS;
else
throw setError(VBOX_E_FILE_ERROR,
}
}
}
}
{
throw rc3;
}
// Finished, lock again (so nobody mess around with the medium tree
// in the meantime)
}
if (m->fManifest)
{
// Create & write the manifest file
pTask->pProgress->SetNextOperation(BstrFmt(tr("Creating manifest file '%s'"), strMfFileName.c_str()).raw(),
m->ulWeightForManifestOperation); // operation's weight, as set up with the IProgress originally);
PRTMANIFESTTEST paManifestFiles = (PRTMANIFESTTEST)RTMemAlloc(sizeof(RTMANIFESTTEST) * fileList.size());
size_t i = 0;
++it1, ++i)
{
}
void *pvBuf;
vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, m->fSha256 ? RTDIGESTTYPE_SHA256 : RTDIGESTTYPE_SHA1,
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create manifest file '%s' (%Rrc)"),
/* Disable digest creation for the manifest file. */
pStorage->fCreateDigest = false;
/* Write the manifest file to disk. */
if (RT_FAILURE(vrc))
throw setError(VBOX_E_FILE_ERROR,
tr("Could not create manifest file '%s' (%Rrc)"),
}
}
catch (RTCError &x) // includes all XML exceptions
{
x.what());
}
{
}
/* Cleanup on error */
{
++it1)
}
return rc;
}
#ifdef VBOX_WITH_S3
/**
* 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::i_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 */
// 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->ulWeightForXmlOperation)); /* Use 1% of the total for the OVF file upload */
/* Add the manifest file */
if (m->fManifest)
{
filesList.push_back(pair<Utf8Str, ULONG>(strMfFile , m->ulWeightForXmlOperation)); /* Use 1% of the total for the manifest file upload */
}
/* Now add every disks of every virtual system */
++it)
{
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_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 */
pTask->pProgress->SetNextOperation(BstrFmt(tr("Uploading file '%s'"), pszFilename).raw(), s.second);
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;
}
#endif /* VBOX_WITH_S3 */