ApplianceImpl.cpp revision 40becad9511726726c5959a8ad8b62fb3e1c020c
/* $Id$ */
/** @file
*
* IAppliance and IVirtualSystem COM class implementations.
*/
/*
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "ApplianceImpl.h"
#include "VirtualBoxImpl.h"
#include "GuestOSTypeImpl.h"
#include "ProgressImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
using namespace std;
// defines
////////////////////////////////////////////////////////////////////////////////
struct DiskImage
{
// (maximum size for dynamic images, I guess; we always translate this to bytes)
// (actual used size of disk, always in bytes; can be an estimate of used disk
// space, but cannot be larger than iCapacity)
// typically http://www.vmware.com/specifications/vmdk.html#sparse
// fields from /References/File; the spec says the file reference from disk can be empty,
// so in that case, strFilename will be empty, then a new disk should be created
Utf8Str strHref; // value from /References/File/@href (filename); if empty, then the remaining fields are ignored
int64_t iSize; // value from /References/File/@size (optional according to spec; then we set -1 here)
Utf8Str strCompression; // value from /References/File/@compression (optional, can be "gzip" according to spec)
};
struct Network
{
// unfortunately the OVF spec is unspecific about how networks should be specified further
};
struct VirtualHardwareItem
{
Utf8Str strHostResource; // "Abstractly specifies how a device shall connect to a resource on the deployment platform.
// Not all devices need a backing." Used with disk items, for which this references a virtual
// disk from the Disks section.
bool fAutomaticAllocation;
bool fAutomaticDeallocation;
Utf8Str strConnection; // "All Ethernet adapters that specify the same abstract network connection name within an OVF
// package shall be deployed on the same network. The abstract network connection name shall be
// listed in the NetworkSection at the outermost envelope level."
Utf8Str strAllocationUnits; // "Specifies the units of allocation used. For example, “byte * 2^20”."
uint64_t ullVirtualQuantity; // "Specifies the quantity of resources presented. For example, “256”."
uint64_t ullReservation; // "Specifies the minimum quantity of resources guaranteed to be available."
uint64_t ullWeight; // "Specifies a relative priority for this allocation in relation to other allocations."
: ulInstanceID(0), fAutomaticAllocation(false), fAutomaticDeallocation(false), ullVirtualQuantity(0), ullReservation(0), ullLimit(0), ullWeight(0), ulBusNumber(0), ulLineNumber(0)
{};
};
struct VirtualSystem;
// opaque private instance data of Appliance class
{
};
struct HardDiskController
{
Utf8Str strControllerType; // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
: idController(0),
ulBusNumber(0)
{
}
};
struct VirtualDisk
{
// points into VirtualSystem.mapControllers
// and possibly higher for disks attached to SCSI controllers (untested)
// this receives the <id> component; points to one of the
// references in Appliance::Data.mapDisks
};
struct VirtualSystem
{
Utf8Str strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
// VMware Workstation 6.5 is "vmx-07"
// list of strings referring to network names
// (one for each VirtualSystem/Item[@ResourceType=10]/Connection element)
// list of hard disk controllers
// (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
// (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
Utf8Str strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
// VMware Workstation 6.5 uses "ensoniq1371" for example
Utf8Str strLicenceText; // license info if any; receives contents of VirtualSystem/EulaSection/License
: ullMemorySize(0), cCPUs(1), fHasFloppyDrive(false), fHasCdromDrive(false), fHasUsbController(false)
{
}
};
struct Appliance::TaskImportMachines
{
{}
~TaskImportMachines() {}
};
////////////////////////////////////////////////////////////////////////////////
//
// globals
//
////////////////////////////////////////////////////////////////////////////////
{
return str2;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualBox public methods
//
////////////////////////////////////////////////////////////////////////////////
// This code is here so we won't have to include the appliance headers in the
// IVirtualBox implementation.
/**
* Implementation for IVirtualBox::createAppliance.
*
* @param anAppliance IAppliance object created if S_OK is returned.
* @return S_OK or error.
*/
{
return rc;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance::task methods
//
////////////////////////////////////////////////////////////////////////////////
{
"Appliance::Task");
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance constructor / destructor
//
////////////////////////////////////////////////////////////////////////////////
struct shutup {};
/**
* Appliance COM initializer.
* @param
* @return
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Weak reference to a VirtualBox object */
// initialize data
m = new Data;
/* Confirm a successful initialization */
return S_OK;
}
/**
* Appliance COM uninitializer.
* @return
*/
{
delete m;
m = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// Appliance private methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Private helper method that goes thru the elements of the given "current" element in the OVF XML
* and handles the contained child elements (which can be "Section" or "Content" elements).
*
* @param pcszPath Path spec of the XML file, for error messages.
* @param pReferencesElement "References" element from OVF, for looking up file specifications; can be NULL if no such element is present.
* @param pCurElem Element whose children are to be analyzed here.
* @return
*/
{
{
const char *pcszTypeAttr = "";
)
)
{
return rc;
}
)
)
{
return rc;
}
{
// TODO
}
{
// child of VirtualSystemCollection -- TODO
}
{
// child of VirtualSystemCollection -- TODO
}
{
// child of VirtualSystemCollection -- TODO
}
)
)
{
return rc;
}
)
)
{
// TODO ResourceAllocationSection
// recurse for this, since it has VirtualSystem elements as children
return rc;
}
}
return S_OK;
}
/**
* Private helper method that handles disk sections in the OVF XML.
* Gets called indirectly from IAppliance::read().
*
* @param pcszPath Path spec of the XML file, for error messages.
* @param pReferencesElement "References" element from OVF, for looking up file specifications; can be NULL if no such element is present.
* @param pSectionElem Section element for which this helper is getting called.
* @return
*/
{
// contains "Disk" child elements
{
DiskImage d;
pcszBad = "diskId";
pcszBad = "format";
pcszBad = "capacity";
else
{
// optional
d.iPopulatedSize = -1;
{
// look up corresponding /References/File nodes (list built above)
if ( pReferencesElem
)
{
// copy remaining values from file node then
const char *pcszBadInFile = NULL;
pcszBadInFile = "href";
// if (!(pFileElem->getAttributeValue("size", d.iChunkSize))) TODO
if (pcszBadInFile)
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": missing or invalid attribute '%s' in 'File' element, line %d"),
pFileElem->getLineNumber());
}
else
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": cannot find References/File element for ID '%s' referenced by 'Disk' element, line %d"),
strFileRef.c_str(),
pelmDisk->getLineNumber());
}
}
if (pcszBad)
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": missing or invalid attribute '%s' in 'DiskSection' element, line %d"),
pelmDisk->getLineNumber());
}
return S_OK;
}
/**
* Private helper method that handles network sections in the OVF XML.
* Gets called indirectly from IAppliance::read().
*
* @param pcszPath Path spec of the XML file, for error messages.
* @param pSectionElem Section element for which this helper is getting called.
* @return
*/
{
// contains "Disk" child elements
{
Network n;
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": missing 'name' attribute in 'Network', line %d"),
pelmNetwork->getLineNumber());
m->mapNetworks[n.strNetworkName] = n;
}
return S_OK;
}
/**
* Private helper method that handles a "VirtualSystem" element in the OVF XML.
* Gets called indirectly from IAppliance::read().
*
* @param pcszPath
* @param pContentElem
* @return
*/
{
if (pIdAttr)
{
{
/* <EulaSection>
<Info ovf:msgid="6">License agreement for the Virtual System.</Info>
<License ovf:msgid="1">License terms can go in here.</License>
</EulaSection> */
)
{
}
}
)
{
{
/* <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>*/
}
{
{
)
{
}
else
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": unknown element \"%s\" under Item element, line %d"),
i.ulLineNumber);
}
// store!
}
++itH)
{
// do some analysis
switch (i.resourceType)
{
case OVFResourceType_Processor: // 3
/* <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>*/
if (i.ullVirtualQuantity < UINT16_MAX)
else
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": CPU count %RI64 is larger than %d, line %d"),
i.ulLineNumber);
break;
case OVFResourceType_Memory: // 4
)
else
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": Invalid allocation unit \"%s\" specified with memory size item, line %d"),
i.strAllocationUnits.c_str(),
i.ulLineNumber);
break;
case OVFResourceType_IdeController: // 5 IdeController
{
/* <Item>
<rasd:Caption>ideController0</rasd:Caption>
<rasd:Description>IDE Controller</rasd:Description>
<rasd:InstanceId>5</rasd:InstanceId>
<rasd:ResourceType>5</rasd:ResourceType>
<rasd:Address>0</rasd:Address>
<rasd:BusNumber>0</rasd:BusNumber>
</Item> */
}
break;
case OVFResourceType_ParallelScsiHba: // 6 SCSI controller
{
/* <Item>
<rasd:Caption>SCSI Controller 0 - LSI Logic</rasd:Caption>
<rasd:Description>SCI Controller</rasd:Description>
<rasd:ElementName>SCSI controller</rasd:ElementName>
<rasd:InstanceID>4</rasd:InstanceID>
<rasd:ResourceSubType>LsiLogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
</Item> */
}
break;
case OVFResourceType_EthernetAdapter: // 10
{
/* <Item>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption>
<rasd:Connection>VM Network</rasd:Connection>
<rasd:Description>VM Network?</rasd:Description>
<rasd:ElementName>Ethernet adapter</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:ResourceType>10</rasd:ResourceType>
</Item>
OVF spec DSP 0243 page 21:
"For an Ethernet adapter, this specifies the abstract network connection name
for the virtual machine. All Ethernet adapters that specify the same abstract
network connection name within an OVF package shall be deployed on the same
network. The abstract network connection name shall be listed in the NetworkSection
at the outermost envelope level." */
// make sure we have a matching NetworkSection/Network
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": Invalid connection \"%s\"; cannot find matching NetworkSection/Network element, line %d"),
i.strConnection.c_str(),
i.ulLineNumber);
}
break;
case OVFResourceType_FloppyDrive: // 14
break;
case OVFResourceType_CdDrive: // 15
/* <Item ovf:required="false">
<rasd:Caption>cdrom1</rasd:Caption>
<rasd:InstanceId>7</rasd:InstanceId>
<rasd:ResourceType>15</rasd:ResourceType>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Parent>5</rasd:Parent>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
</Item> */
// I tried to see what happens if I set an ISO for the CD-ROM in VMware Workstation,
// but then the ovftool dies with "Device backing not supported". So I guess if
// VMware can't export ISOs, then we don't need to be able to import them right now.
break;
case OVFResourceType_HardDisk: // 17
{
/* <Item>
<rasd:Caption>Harddisk 1</rasd:Caption>
<rasd:Description>HD</rasd:Description>
<rasd:ElementName>Hard Disk</rasd:ElementName>
<rasd:InstanceID>5</rasd:InstanceID>
<rasd:Parent>4</rasd:Parent>
<rasd:ResourceType>17</rasd:ResourceType>
</Item> */
// look up the hard disk controller element whose InstanceID equals our Parent;
// this is how the connection is specified in OVF
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": Hard disk item with instance ID %d specifies invalid parent %d, line %d"),
i.ulInstanceID,
i.ulParent,
i.ulLineNumber);
bool fFound = false;
// 12345678901234
)
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": Hard disk item with instance ID %d specifies invalid host resource \"%s\", line %d"),
i.ulInstanceID,
i.strHostResource.c_str(),
i.ulLineNumber);
}
break;
case OVFResourceType_UsbController: // 23
/* <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> */
break;
case OVFResourceType_SoundCard: // 35
/* <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> */
break;
default:
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": Unknown resource type %d in hardware item, line %d"),
i.resourceType,
i.ulLineNumber);
}
}
}
)
{
return setError(VBOX_E_FILE_ERROR,
tr("Error reading \"%s\": missing or invalid 'ovf:id' attribute in operating system section element, line %d"),
pelmThis->getLineNumber());
}
}
// now create the virtual system
return S_OK;
}
////////////////////////////////////////////////////////////////////////////////
//
// IAppliance public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param
* @return
*/
{
if (!aPath)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Public method implementation.
* @param
* @return
*/
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
// create a string representing this disk
"%s\t"
"%RI64\t"
"%RI64\t"
"%s\t"
"%s\t"
"%RI64\t"
"%RI64\t"
"%s",
d.iCapacity,
d.iSize,
d.iChunkSize,
d.strCompression.c_str());
// push to safearray
}
return S_OK;
}
/**
* Public method implementation.
* @param
* @return
*/
STDMETHODIMP Appliance::COMGETTER(VirtualSystemDescriptions)(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions))
{
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Private helper func that suggests a VirtualBox guest OS type
* for the given OVF operating system type.
* @param osTypeVBox
* @param c
*/
{
switch (c)
{
case CIMOSType_CIMOS_Unknown: // 0 - Unknown
break;
case CIMOSType_CIMOS_OS2: // 12 - OS/2
break;
case CIMOSType_CIMOS_MSDOS: // 14 - MSDOS
break;
case CIMOSType_CIMOS_WIN3x: // 15 - WIN3x
break;
case CIMOSType_CIMOS_WIN95: // 16 - WIN95
break;
case CIMOSType_CIMOS_WIN98: // 17 - WIN98
break;
case CIMOSType_CIMOS_WINNT: // 18 - WINNT
break;
case CIMOSType_CIMOS_NetWare: // 21 - NetWare
case CIMOSType_CIMOS_NovellOES: // 86 - Novell OES
break;
case CIMOSType_CIMOS_Solaris: // 29 - Solaris
case CIMOSType_CIMOS_SunOS: // 30 - SunOS
break;
case CIMOSType_CIMOS_FreeBSD: // 42 - FreeBSD
break;
case CIMOSType_CIMOS_NetBSD: // 43 - NetBSD
break;
case CIMOSType_CIMOS_QNX: // 48 - QNX
break;
case CIMOSType_CIMOS_Windows2000: // 58 - Windows 2000
break;
case CIMOSType_CIMOS_WindowsMe: // 63 - Windows (R) Me
break;
case CIMOSType_CIMOS_OpenBSD: // 65 - OpenBSD
break;
case CIMOSType_CIMOS_WindowsXP: // 67 - Windows XP
case CIMOSType_CIMOS_WindowsXPEmbedded: // 72 - Windows XP Embedded
case CIMOSType_CIMOS_WindowsEmbeddedforPointofService: // 75 - Windows Embedded for Point of Service
break;
case CIMOSType_CIMOS_MicrosoftWindowsServer2003: // 69 - Microsoft Windows Server 2003
break;
case CIMOSType_CIMOS_MicrosoftWindowsServer2003_64: // 70 - Microsoft Windows Server 2003 64-Bit
break;
case CIMOSType_CIMOS_WindowsXP_64: // 71 - Windows XP 64-Bit
break;
case CIMOSType_CIMOS_WindowsVista: // 73 - Windows Vista
break;
case CIMOSType_CIMOS_WindowsVista_64: // 74 - Windows Vista 64-Bit
break;
case CIMOSType_CIMOS_MicrosoftWindowsServer2008: // 76 - Microsoft Windows Server 2008
break;
case CIMOSType_CIMOS_MicrosoftWindowsServer2008_64: // 77 - Microsoft Windows Server 2008 64-Bit
break;
case CIMOSType_CIMOS_FreeBSD_64: // 78 - FreeBSD 64-Bit
break;
case CIMOSType_CIMOS_RedHatEnterpriseLinux: // 79 - RedHat Enterprise Linux
break;
case CIMOSType_CIMOS_RedHatEnterpriseLinux_64: // 80 - RedHat Enterprise Linux 64-Bit
break;
case CIMOSType_CIMOS_Solaris_64: // 81 - Solaris 64-Bit
break;
case CIMOSType_CIMOS_SUSE: // 82 - SUSE
case CIMOSType_CIMOS_SLES: // 84 - SLES
case CIMOSType_CIMOS_NovellLinuxDesktop: // 87 - Novell Linux Desktop
break;
case CIMOSType_CIMOS_SUSE_64: // 83 - SUSE 64-Bit
case CIMOSType_CIMOS_SLES_64: // 85 - SLES 64-Bit
break;
case CIMOSType_CIMOS_LINUX: // 36 - LINUX
case CIMOSType_CIMOS_SunJavaDesktopSystem: // 88 - Sun Java Desktop System
case CIMOSType_CIMOS_TurboLinux: // 91 - TurboLinux
break;
// case CIMOSType_CIMOS_TurboLinux_64: // 92 - TurboLinux 64-Bit
// case CIMOSType_CIMOS_Linux_64: // 101 - Linux 64-Bit
// osTypeVBox = VBOXOSTYPE_Linux_x64;
// break;
case CIMOSType_CIMOS_Mandriva: // 89 - Mandriva
break;
case CIMOSType_CIMOS_Mandriva_64: // 90 - Mandriva 64-Bit
break;
case CIMOSType_CIMOS_Ubuntu: // 93 - Ubuntu
break;
case CIMOSType_CIMOS_Ubuntu_64: // 94 - Ubuntu 64-Bit
break;
case CIMOSType_CIMOS_Debian: // 95 - Debian
break;
case CIMOSType_CIMOS_Debian_64: // 96 - Debian 64-Bit
break;
case CIMOSType_CIMOS_Linux_2_4_x: // 97 - Linux 2.4.x
break;
case CIMOSType_CIMOS_Linux_2_4_x_64: // 98 - Linux 2.4.x 64-Bit
break;
case CIMOSType_CIMOS_Linux_2_6_x: // 99 - Linux 2.6.x
break;
case CIMOSType_CIMOS_Linux_2_6_x_64: // 100 - Linux 2.6.x 64-Bit
break;
default:
{
/* If we are here we have no clue what OS this should be. Set
to other type as default. */
}
}
}
/**
* Public method implementation.
* @param path
* @return
*/
{
if (!path)
return E_POINTER;
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
// see if we can handle this file; for now we insist it has an ".ovf" extension
if ( (!pcszLastDot)
)
)
return setError(VBOX_E_FILE_ERROR,
tr("Appliance file must have .ovf extension"));
try
{
doc);
return setError(VBOX_E_FILE_ERROR,
tr("Root element in OVF file must be \"Envelope\"."));
// OVF has the following rough layout:
/*
-- <References> .... files referenced from other parts of the file, such as VMDK images
-- Metadata, comprised of several section commands
-- virtual machines, either a single <VirtualSystem>, or a <VirtualSystemCollection>
-- optionally <Strings> for localization
*/
// get all "File" child elements of "References" section so we can look up files easily;
// first find the "References" sections so we can look up files
// now go though the sections
return rc;
}
{
return setError(VBOX_E_FILE_ERROR,
x.what());
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
// @todo:
// - don't use COM methods but the methods directly (faster, but needs appropriate locking of that objects itself (s. HardDisk))
// - Appropriate handle errors like not supported file formats
AutoCaller autoCaller(this);
AutoWriteLock(this);
/* Clear any previous virtual system descriptions */
// @todo: have the entries deleted also?
/* We need the default path for storing disk images */
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 */
if (nameVBox == "")
"",
nameVBox);
/* Now that we know the OS type, get our internal defaults based on that. */
/* CPU count */
/* Check for the constrains */
{
pNewDesc->addWarning(tr("The virtual system 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 &&
{
pNewDesc->addWarning(tr("The virtual system claims support for %llu MB RAM size, but VirtualBox has support for min %u & max %u MB RAM size only."),
ullMemSizeVBox = RT_MIN(RT_MAX(ullMemSizeVBox, static_cast<uint64_t>(SchemaDefs::MinGuestRAM)), static_cast<uint64_t>(SchemaDefs::MaxGuestRAM));
}
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 */
++itN)
{
"",
}
/* Network Controller */
// @todo: there is no hardware specification in the OVF file; supposedly the
// hardware will then be determined by the VirtualSystemType element (e.g. "vmx-07")
{
/* Check for the constrains */
{
pNewDesc->addWarning(tr("The virtual system claims support for %u 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;
++nwIt, ++a)
{
"", // ref
strNetwork, // orig
}
}
/* Floppy Drive */
if (vsysThis.fHasFloppyDrive)
/* CD Drive */
/* @todo: I can't disable the CDROM. So nothing to do for now */
/*
if (vsysThis.fHasCdromDrive)
pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM, "", "", "");*/
/* Hard disk Controller */
/* Iterate through all hard disk controllers */
++hdcIt)
{
{
case HardDiskController::IDE:
{
/* Check for the constrains */
/* @todo: I'm very confused! Are these bits *one* controller or
if (cIDEused < 4)
{
// @todo: figure out the IDE types
/* Use PIIX4 as default */
strType = "PIIX3";
strType);
}
else
{
/* Warn only once */
if (cIDEused == 1)
pNewDesc->addWarning(tr("The virtual system claims support for more than one IDE controller, but VirtualBox has support for only one."));
}
++cIDEused;
break;
}
#ifdef VBOX_WITH_AHCI
case HardDiskController::SATA:
{
/* 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)
pNewDesc->addWarning(tr("The virtual system claims support for more than one SATA controller, but VirtualBox has support for only one."));
}
++cSATAused;
break;
}
#endif /* VBOX_WITH_AHCI */
case HardDiskController::SCSI:
{
/* Check for the constrains */
if (cSCSIused < 1)
{
// @todo: figure out the SCSI types
/* if (!RTStrICmp(hdc.strControllerType.c_str(), "LsiLogic"))
hdcController = "LsiLogic";
else*/
hdcController = "BusLogic";
}
else
{
/* Warn only once */
if (cSCSIused == 1)
pNewDesc->addWarning(tr("The virtual system claims support for more than one SCSI controller, but VirtualBox has support for only one."));
}
++cSCSIused;
break;
}
default:
{
/* @todo: should we stop? */
}
}
}
/* 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 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("Internal inconsistency looking up hard disk controller."));
/* controller to attach to, and the bus within that controller */
}
else
{
/* @todo: should we stop here? */
pNewDesc->addWarning(tr("The virtual system claims support for the following virtual disk image format which VirtualBox not support: %s"),
}
}
}
}
}
{
/* On error we clear the list & return */
}
return rc;
}
/**
* Public method implementation.
* @param aProgress
* @return
*/
{
AutoCaller autoCaller(this);
AutoReadLock(this);
try
{
/* Figure out how many sub operation the import will need */
/* One for the appliance */
++it)
{
/* One for every Virtual System */
++opCount;
/* One for every hard disk of the Virtual System */
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
}
/* Create the progress object */
FALSE /* aCancelable */,
/* Initialize our worker task */
//AssertComRCThrowRC (task->autoCaller.rc());
}
{
}
/* Return progress to the caller */
return rc;
}
{
return rc;
}
{
int i = 1;
/* @todo: Maybe too cost-intensive; try to find a lighter way */
{
++i;
}
return S_OK;
}
{
int i = 1;
/* Check if the file exists or if a file with this path is registered
* already */
/* @todo: Maybe too cost-intensive; try to find a lighter way */
while (RTPathExists(tmpName) ||
{
++i;
}
return S_OK;
}
struct MyHardDiskAttachment
{
};
/**
* Worker thread implementation for ImportMachines().
* @param aThread
* @param pvUser
*/
/* static */
{
// rollback for errors:
bool fSessionOpen = false;
/* Iterate through all virtual systems of that appliance */
size_t i = 0;
{
/* Catch possible errors */
try
{
/* How many sub notifications are necessary? */
/* 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"));
/* CPU count (ignored for now) */
// EntriesList vsdeCPU = vsd->findByType (VirtualSystemDescriptionType_CPU);
/* RAM */
std::list<VirtualSystemDescriptionEntry*> vsdeRAM = vsdescThis->findByType(VirtualSystemDescriptionType_Memory);
/* VRAM */
/* Get the recommended VRAM for this guest OS type */
/* Set the VRAM */
/* 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 */
/* NAT is set as default */
}
}
/* Floppy drive */
std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);
// Floppy support is enabled if there's at least one such entry; to disable floppy support,
// the type of the floppy item would have been changed to "ignore"
/* CDROM drive */
/* @todo: I can't disable the CDROM. So nothing to do for now */
// std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsd->findByType(VirtualSystemDescriptionType_CDROM);
/* Hard disk controller IDE */
std::list<VirtualSystemDescriptionEntry*> vsdeHDCIDE = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerIDE);
/* @todo: we support one IDE controller only */
if (vsdeHDCIDE.size() > 0)
{
/* Set the appropriate IDE controller in the virtual BIOS of the VM */
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);
/* @todo: we support one SATA controller only */
if (vsdeHDCSATA.size() > 0)
{
if (hdcVBox == "AHCI")
{
/* For now we have just to enable the AHCI controller. */
}
else
{
throw setError(VBOX_E_FILE_ERROR,
tr("Invalid SATA controller type \"%s\""),
}
}
#endif /* VBOX_WITH_AHCI */
/* Hard disk controller SCSI */
std::list<VirtualSystemDescriptionEntry*> vsdeHDCSCSI = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
/* @todo: do we support more than one SCSI controller? */
if (vsdeHDCSCSI.size() > 0)
{
/* @todo: revisit when Main support for SCSI is ready */
}
/* Now its time to register the machine before we add any hard disks */
// store new machine for roll-back in case of errors
/* Create the hard disks & connect them to the appropriate controllers. */
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
{
/* If in the next block an error occur we have to deregister
bool fSourceHdNeedsClosing = false;
try
{
/* In order to attach hard disks we need to open a session
* for the new machine */
fSessionOpen = true;
/* The disk image has to be on the same place as the OVF file. So
* strip the filename out of the full file path. */
/* Iterate over all given disk images */
++itHD)
{
/* Check if the destination file exists already or the
* destination path is empty. */
if ( !(*pcszDstFilePath)
)
/* This isn't allowed */
throw setError(VBOX_E_FILE_ERROR,
tr("Destination file '%s' exists",
/* Find the disk from the OVF's disk list */
/* vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1"), which should exist
in the virtual system's disks map under that ID and also in the global images map. */
)
tr("Internal inconsistency looking up disk images."));
/* Make sure all target directories exists */
throw rc;
/* If strHref is empty we have to create a new file */
{
/* Which format to use? */
srcFormat = L"VMDK";
/* Create an empty hard disk */
/* Create a dynamic growing disk image with the given capacity */
/* Advance to the next operation */
task->progress->advanceOperation (BstrFmt(tr("Creating virtual disk image '%s'"), pcszDstFilePath));
}
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 */
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 */
task->progress->advanceOperation (BstrFmt(tr("Importing virtual disk image '%s'"), strSrcFilePath.c_str()));
}
// now loop until the asynchronous operation completes and then
// report its result
{
if (fCompleted)
break;
/* Make sure the loop is not too tight */
}
// report result of asynchronous operation
// if the thread of the progress object has an error, then
// retrieve the error info from there, or it'll be lost
{
pcsz);
throw rc2;
}
{
fSourceHdNeedsClosing = false;
}
/* Now use the new uuid to attach the disk image to our new machine */
/* For now we assume we have one controller of every type only */
// this is for rollback later
{
case HardDiskController::IDE:
// For the IDE bus, the channel parameter can be either 0 or 1, to specify the primary
// or secondary IDE controller, respectively. For the primary controller of the IDE bus,
// the device number can be either 0 or 1, to specify the master or the slave device,
// respectively. For the secondary IDE controller, the device number is always 1 because
// the master device is reserved for the CD-ROM drive.
switch (vd.ulAddressOnParent)
{
case 0: // interpret this as primary master
break;
case 1: // interpret this as primary slave
break;
case 2: // interpret this as secondary slave
break;
default:
throw setError(VBOX_E_NOT_SUPPORTED,
tr("Invalid channel %RI16 specified; IDE conrollers support only 0, 1 or 2"), vd.ulAddressOnParent);
break;
}
break;
case HardDiskController::SATA:
break;
case HardDiskController::SCSI:
// mhda.busType = StorageBus_SCSI;
throw setError(VBOX_E_NOT_SUPPORTED,
tr("SCSI controller support is not available yet in VirtualBox"));
// @todo
break;
default: break;
}
Log(("Attaching disk %s to channel %d on device %d\n", pcszDstFilePath, mhda.lChannel, mhda.lDevice));
} // end for (itHD = avsdeHDs.begin();
// only now that we're done with all disks, close the session
fSessionOpen = false;
}
catch(HRESULT /* aRC */)
{
if (fSessionOpen)
throw;
}
}
}
{
}
break;
} // for (it = app->m->llVirtualSystems.begin(),
{
// with _whatever_ error we've had, do a complete roll-back of
// machines and disks we've created; unfortunately this is
// not so trivially done...
// detach all hard disks from all machines we created
++itM)
{
{
{
}
}
}
// now clean up all hard disks we created
++itHD)
{
}
// finally, deregister and remove all machines
++itID)
{
}
}
return VINF_SUCCESS;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualSystemDescription constructor / destructor
//
////////////////////////////////////////////////////////////////////////////////
struct shutup3 {};
struct VirtualSystemDescription::Data
{
};
/**
* COM initializer.
* @return
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Initialize data */
m = new Data();
/* Confirm a successful initialization */
return S_OK;
}
/**
* COM uninitializer.
*/
void VirtualSystemDescription::uninit()
{
delete m;
m = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// IVirtualSystemDescription public methods
//
////////////////////////////////////////////////////////////////////////////////
/**
* Public method implementation.
* @param
* @return
*/
{
if (!aCount)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
return S_OK;
}
/**
* Public method implementation.
* @return
*/
STDMETHODIMP VirtualSystemDescription::GetDescription(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
{
if (ComSafeArrayOutIsNull(aTypes) ||
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
)
return E_INVALIDARG;
size_t i = 0;
++it, ++i)
{
if (aEnabled[i])
{
}
else
}
return S_OK;
}
/**
* Public method implementation.
* @return
*/
{
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
size_t i = 0;
++it, ++i)
{
}
return S_OK;
}
/**
* Internal method; adds a new description item to the member list.
* @param aType Type of description for the new item.
* @param strRef Reference item; only used with hard disk controllers.
* @param aOrigValue Corresponding original value from OVF.
* @param aAutoValue Initial configuration value (can be overridden by caller with setFinalValues).
* @param strExtraConfig Extra configuration; meaning dependent on type.
*/
const Utf8Str &aOrigValue,
const Utf8Str &aAutoValue,
{
vsde.ulIndex = (uint32_t)m->descriptions.size(); // each entry gets an index so the client side can reference them
}
{
}
/**
* Private method; returns a list of description items containing all the items from the member
* description items of this virtual system that match the given type.
* @param aType
* @return
*/
std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::findByType(VirtualSystemDescriptionType_T aType)
{
++it)
{
}
return vsd;
}
/**
* Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
* the given reference ID. Useful when needing the controller for a particular
* virtual disk.
* @param id
* @return
*/
{
++it)
{
{
return &(*it);
break;
}
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// IMachine public methods
//
////////////////////////////////////////////////////////////////////////////////
// This code is here so we won't have to include the appliance headers in the
// IMachine implementation, and we also need to access private appliance data.
/**
* Public method implementation.
* @param appliance
* @return
*/
{
if (!appliance)
return E_POINTER;
AutoCaller autoCaller(this);
AutoReadLock alock(this);
try
{
// get name
// get description
// get guest OS
// CPU count
// memory size in MB
// VRAM size?
// BIOS settings?
// 3D acceleration enabled?
// hardware virtualization enabled?
// nested paging enabled?
// HWVirtExVPIDEnabled?
// PAEEnabled?
// snapshotFolder?
// VRDPServer?
// floppy
// CD-ROM ?!?
// ComPtr<IDVDDrive> pDVDDrive;
fDVDEnabled = 1;
// this is more tricky so use the COM method
// create a new virtual system
/* Guest OS type */
"",
/* VM name */
"",
/* CPU count*/
"",
/* Memory */
"",
// <const name="HardDiskControllerIDE" value="6" />
switch(ctlr)
{
}
{
pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE, strIdeControllerID, strVbox, "");
}
#ifdef VBOX_WITH_AHCI
// <const name="HardDiskControllerSATA" value="7" />
if (fSataEnabled)
{
pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSATA, strSataControllerID, strVbox, "");
}
#endif // VBOX_WITH_AHCI
// <const name="HardDiskControllerSCSI" value="8" />
// @todo
// <const name="HardDiskImage" value="9" />
// hardDiskAttachments
// mHDData->mAttachments @todo
++itA)
{
// get the attachment's data
"", // di.strHref,
"",
""); // strExtraConfig
}
/* Floppy Drive */
if (fFloppyEnabled)
/* CD Drive */
if (fDVDEnabled)
// <const name="LogicalNetwork" value="12" />
// <const name="NetworkAdapter" value="13" />
// <const name="USBController" value="14" />
// <const name="SoundCard" value="15" />
// finally, add the virtual system to the appliance
}
{
}
return rc;
}