ApplianceImplExport.cpp revision 850262fbdae881e26aeadf833fa389ed6d6a7b8e
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * IAppliance and IVirtualSystem COM class implementations.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Copyright (C) 2008-2010 Oracle Corporation
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * This file is part of VirtualBox Open Source Edition (OSE), as
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * available from http://www.virtualbox.org. This file is free software;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * you can redistribute it and/or modify it under the terms of the GNU
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * General Public License (GPL) as published by the Free Software
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Foundation, in version 2 as it comes in the "COPYING" file of the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomeusing namespace std;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// IMachine public methods
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// This code is here so we won't have to include the appliance headers in the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// IMachine implementation, and we also need to access private appliance data.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* Public method implementation.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome* @param appliance
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeSTDMETHODIMP Machine::Export(IAppliance *aAppliance, IVirtualSystemDescription **aDescription)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (FAILED(autoCaller.rc())) return autoCaller.rc();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // create a new virtual system to store in the appliance
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // store the machine object so we can dump the XML in Appliance::Write()
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // now fill it with description items
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // first, call the COM methods, as they request locks
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = COMGETTER(USBController)(pUsbController.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pUsbController->COMGETTER(Enabled)(&fUSBEnabled);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // request the machine lock while acessing internal members
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoReadLock alock1(this COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pAudioAdapter->COMGETTER(Enabled)(&fAudioEnabled);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pAudioAdapter->COMGETTER(AudioController)(&audioController);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // get description
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strDescription = mUserData->s.strDescription;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // get guest OS
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strOsTypeVBox = mUserData->s.strOsType;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // CPU count
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // memory size in MB
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // VRAM size?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // BIOS settings?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // 3D acceleration enabled?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // hardware virtualization enabled?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // nested paging enabled?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // HWVirtExVPIDEnabled?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // PAEEnabled?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // snapshotFolder?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // VRDPServer?
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Guest OS type */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ovf::CIMOSType_T cim = convertVBoxOSType2CIMOSType(strOsTypeVBox.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_OS,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* VM name */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_Name,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // description
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_Description,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* CPU count*/
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strCpuCount = Utf8StrFmt("%RI32", cCPUs);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_CPU,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Memory */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strMemory = Utf8StrFmt("%RI64", (uint64_t)ulMemSizeMB * _1M);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_Memory,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // the one VirtualBox IDE controller has two channels with two ports each, which is
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // considered two IDE controllers with two ports each by OVF, so export it as two
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Fetch all available storage controllers */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome com::SafeIfaceArray<IStorageController> nwControllers;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(nwControllers));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome for (size_t j = 0; j < nwControllers.size(); ++j)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="HardDiskControllerIDE" value="6" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pIDEController->COMGETTER(ControllerType)(&ctlr);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case StorageControllerType_PIIX3: strVbox = "PIIX3"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case StorageControllerType_PIIX4: strVbox = "PIIX4"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case StorageControllerType_ICH6: strVbox = "ICH6"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lIDEControllerPrimaryIndex = (int32_t)pNewDesc->m->llDescriptions.size();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8StrFmt("%d", lIDEControllerPrimaryIndex), // strRef
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lIDEControllerSecondaryIndex = lIDEControllerPrimaryIndex + 1;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerIDE,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8StrFmt("%d", lIDEControllerSecondaryIndex),
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="HardDiskControllerSATA" value="7" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lSATAControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSATA,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="HardDiskControllerSCSI" value="8" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pSCSIController->COMGETTER(ControllerType)(&ctlr);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strVbox = "LsiLogic"; // the default in VBox
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case StorageControllerType_LsiLogic: strVbox = "LsiLogic"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case StorageControllerType_BusLogic: strVbox = "BusLogic"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lSCSIControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSCSI,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // VirtualBox considers the SAS controller a class of its own but in OVF
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // it should be a SCSI controller
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lSCSIControllerIndex = (int32_t)pNewDesc->m->llDescriptions.size();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskControllerSAS,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="HardDiskImage" value="9" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="Floppy" value="18" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="CDROM" value="19" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // the attachment's data
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pHDA->COMGETTER(Controller)(controllerName.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = GetStorageControllerByName(controllerName.raw(), ctl.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pHDA->COMGETTER(Medium)(pMedium.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // find the source's base medium for two things:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // 1) we'll use its name to determine the name of the target disk, which is readable,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // as opposed to the UUID filename of a differencing image, if pMedium is one
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // 2) we need the size of the base image so we can give it to addEntry(), and later
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // on export, the progress will be based on that (and not the diff image)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pMedium->COMGETTER(Base)(pBaseMedium.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // returns pMedium if there are no diff images
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pBaseMedium->COMGETTER(Name)(bstrBaseName.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // force reading state, or else size will be returned as 0
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // and how this translates to the virtual system
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // this is the exact reverse to what we're doing in Appliance::taskThreadImportMachines,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // and it must be updated when that is changed!
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Before 3.2 we exported one IDE controller with channel 0-3, but we now maintain
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // compatibility with what VMware does and export two IDE controllers with two channels each
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (lChannel == 0 && lDevice == 0) // primary master
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (lChannel == 0 && lDevice == 1) // primary slave
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (lChannel == 1 && lDevice == 0) // secondary master; by default this is the CD-ROM but as of VirtualBox 3.1 that can change
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lControllerVsys = lIDEControllerSecondaryIndex;
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe else if (lChannel == 1 && lDevice == 1) // secondary slave
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lControllerVsys = lIDEControllerSecondaryIndex;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Cannot handle medium attachment: channel is %d, device is %d"), lChannel, lDevice);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lChannelVsys = lChannel; // should be between 0 and 29
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lChannelVsys = lChannel; // should be between 0 and 15
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Cannot handle medium attachment: storageBus is %d, channel is %d, device is %d"), storageBus, lChannel, lDevice);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8StrFmt strExtra("controller=%RI32;channel=%RI32", lControllerVsys, lChannelVsys);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Log(("Adding VirtualSystemDescriptionType_HardDiskImage, disk size: %RI64\n", llSize));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strTargetVmdkName, // disk ID: let's use the name
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_CDROM,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_Floppy,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="NetworkAdapter" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = GetNetworkAdapter((ULONG)a, pNetworkAdapter.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Enable the network card & set the adapter type */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pNetworkAdapter->COMGETTER(Enabled)(&fEnabled);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_NetworkAdapter,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8StrFmt("%RI32", (uint32_t)adapterType), // conf
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8StrFmt("type=%s", strAttachmentType.c_str())); // extra conf
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="USBController" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_USBController, "", "", "");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome#endif /* VBOX_WITH_USB */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// <const name="SoundCard" />
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pNewDesc->addEntry(VirtualSystemDescriptionType_SoundCard,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome "ensoniq1371", // this is what OVFTool writes and VMware supports
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // finally, add the virtual system to the appliance
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Appliance *pAppliance = static_cast<Appliance*>(aAppliance);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (FAILED(autoCaller1.rc())) return autoCaller1.rc();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* We return the new description to the caller */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ComPtr<IVirtualSystemDescription> copy(pNewDesc);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoWriteLock alock(pAppliance COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pAppliance->m->virtualSystemDescriptions.push_back(pNewDesc);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// IAppliance public methods
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Public method implementation.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param format
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param path
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param aProgress
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeSTDMETHODIMP Appliance::Write(IN_BSTR format, BOOL fManifest, IN_BSTR path, IProgress **aProgress)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (FAILED(autoCaller.rc())) return autoCaller.rc();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // do not allow entering this method if the appliance is busy reading or writing
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // see if we can handle this file; for now we insist it has an ".ovf" extension
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (!( strPath.endsWith(".ovf", Utf8Str::CaseInsensitive)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome || strPath.endsWith(".ova", Utf8Str::CaseInsensitive)))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Appliance file must have .ovf or .ova extension"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Invalid format \"%s\" specified"), strFormat.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Parse all necessary info out of the URI */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Return progress to the caller */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome// Appliance private methods
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome////////////////////////////////////////////////////////////////////////////////
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Implementation for writing out the OVF to disk. This starts a new thread which will call
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Appliance::taskThreadWriteOVF().
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * This is in a separate private method because it is used from two locations:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * 1) from the public Appliance::Write().
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * 2) in a second worker thread; in that case, Appliance::Write() called Appliance::writeImpl(), which
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * called Appliance::writeFSOVA(), which called Appliance::writeImpl(), which then called this again.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * 3) from Appliance::writeS3(), which got called from a previous instance of Appliance::taskThreadWriteOVF().
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param aFormat
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param aLocInfo
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param aProgress
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeHRESULT Appliance::writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome BstrFmt(tr("Export appliance '%s'"), aLocInfo.strPath.c_str()),
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome (aLocInfo.storageType == VFSType_File) ? WriteFile : WriteS3);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Initialize our worker task */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::auto_ptr<TaskOVF> task(new TaskOVF(this, TaskOVF::Write, aLocInfo, aProgress));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* The OVF version to write */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Don't destruct on success */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Called from Appliance::writeFS() for creating a XML document for this
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Appliance.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param writeLock The current write lock.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param doc The xml document to fill.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param stack Structure for temporary private
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * data shared with caller.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param strPath Path to the target OVF.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * instance for which to write XML.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param enFormat OVF format (0.9 or 1.0).
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid Appliance::buildXML(AutoWriteLockBase& writeLock,
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe xml::ElementNode *pelmRoot = doc.createRootElement("Envelope");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("ovf:version", (enFormat == OVF_1_0) ? "1.0" : "0.9");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ? "http://www.vmware.com/schema/ovf/1/envelope" // 0.9
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : "http://schemas.dmtf.org/ovf/envelope/1"; // 1.0
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("xmlns:ovf", strNamespace);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // pelmRoot->setAttribute("xmlns:ovfstr", "http://schema.dmtf.org/ovf/strings/1");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmRoot->setAttribute("xmlns:vbox", "http://www.virtualbox.org/ovf/machine");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // pelmRoot->setAttribute("xsi:schemaLocation", "http://schemas.dmtf.org/ovf/envelope/1 ../ovf-envelope.xsd");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Envelope>/<References>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmReferences = pelmRoot->createChild("References"); // 0.9 and 1.0
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Envelope>/<DiskSection>:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <DiskSection>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info>List of the virtual disks used in the package</Info>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Disk ovf:capacity="4294967296" ovf:diskId="lamp" ovf:format="..." ovf:populatedSize="1924967692"/>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </DiskSection> */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Section xsi:type="ovf:DiskSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDiskSection = pelmRoot->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDiskSection->setAttribute("xsi:type", "ovf:DiskSection_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDiskSection = pelmRoot->createChild("DiskSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmDiskSectionInfo = pelmDiskSection->createChild("Info");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDiskSectionInfo->addContent("List of the virtual disks used in the package");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Envelope>/<NetworkSection>:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <NetworkSection>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info>Logical networks used in the package</Info>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Network ovf:name="VM Network">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Description>The network that the LAMP Service will be available on</Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </NetworkSection> */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Section xsi:type="ovf:NetworkSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetworkSection = pelmRoot->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetworkSection->setAttribute("xsi:type", "ovf:NetworkSection_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetworkSection = pelmRoot->createChild("NetworkSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmNetworkSectionInfo = pelmNetworkSection->createChild("Info");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetworkSectionInfo->addContent("Logical networks used in the package");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // and here come the virtual systems:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // write a collection if we have more than one virtual system _and_ we're
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // writing OVF 1.0; otherwise fail since ovftool can't import more than
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // one machine, it seems
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Cannot export more than one virtual system with OVF 0.9, use OVF 1.0"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmToAddVirtualSystemsTo = pelmRoot->createChild("VirtualSystemCollection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmToAddVirtualSystemsTo->setAttribute("ovf:name", "ExportedVirtualBoxMachines"); // whatever
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmToAddVirtualSystemsTo = pelmRoot; // add virtual system directly under root element
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // this list receives pointers to the XML elements in the machine XML which
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // might have UUIDs that need fixing after we know the UUIDs of the exported images
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<xml::ElementNode*> llElementsWithUuidAttributes;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Iterate throughs all virtual systems of that appliance */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome for (it = m->virtualSystemDescriptions.begin();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ComObjPtr<VirtualSystemDescription> vsdescThis = *it;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // now, fill in the network section we set up empty above according
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // to the networks we found with the hardware items
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmNetwork = pelmNetworkSection->createChild("Network");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetwork->setAttribute("ovf:name", strNetwork.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmNetwork->createChild("Description")->addContent("Logical network used by this appliance.");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Finally, write out the disk info
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome map<Utf8Str, const VirtualSystemDescriptionEntry*>::const_iterator itS;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const VirtualSystemDescriptionEntry *pDiskEntry = itS->second;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // source path: where the VBox image is
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const Utf8Str &strSrcFilePath = pDiskEntry->strVboxCurrent;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Do NOT check here whether the file exists. FindMedium will figure
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // that out, and filesystem-based tests are simply wrong in the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // general case (think of iSCSI).
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // We need some info from the source disks
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw()));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome HRESULT rc = mVirtualBox->FindMedium(bstrSrcFilePath.raw(), DeviceType_HardDisk, pSourceDisk.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pSourceDisk->COMGETTER(Id)(uuidSource.asOutParam());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // output filename
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // target path needs to be composed from where the output OVF is
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strTargetFilePath.append(strTargetFileNameOnly);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // We are always exporting to VMDK stream optimized for now
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome LONG64 cbCapacity = 0; // size reported to guest
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pSourceDisk->COMGETTER(LogicalSize)(&cbCapacity);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Todo r=poetzsch: wrong it is reported in bytes ...
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // capacity is reported in megabytes, so...
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome //cbCapacity *= _1M;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Guid guidTarget; /* Creates a new uniq number for the target disk. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // now handle the XML for the disk:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <File ovf:href="WindowsXpProfessional-disk1.vmdk" ovf:id="file1" ovf:size="1710381056"/>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmFile = pelmReferences->createChild("File");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmFile->setAttribute("ovf:href", strTargetFileNameOnly);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Todo: the actual size is not available at this point of time,
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // cause the disk will be compressed. The 1.0 standard says this is
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // optional! 1.1 isn't fully clear if the "gzip" format is used.
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // Need to be checked. */
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // pelmFile->setAttribute("ovf:size", Utf8StrFmt("%RI64", cbFile).c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // add disk to XML Disks section
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Disk ovf:capacity="8589934592" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="..."/>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmDisk = pelmDiskSection->createChild("Disk");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDisk->setAttribute("ovf:capacity", Utf8StrFmt("%RI64", cbCapacity).c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDisk->setAttribute("ovf:diskId", strDiskID);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDisk->setAttribute("ovf:fileRef", strFileRef);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ? "http://www.vmware.com/specifications/vmdk.html#sparse" // must be sparse or ovftool chokes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // correct string as communicated to us by VMware (public bug #6612)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // add the UUID of the newly target image to the OVF disk element, but in the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // vbox: namespace since it's not part of the standard
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmDisk->setAttribute("vbox:uuid", Utf8StrFmt("%RTuuid", guidTarget.raw()).c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // now, we might have other XML elements from vbox:Machine pointing to this image,
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // but those would refer to the UUID of the _source_ image (which we created the
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // export image from); those UUIDs need to be fixed to the export image
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe Utf8Str strGuidSourceCurly = guidSource.toStringCurly();
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe for (std::list<xml::ElementNode*>::iterator eit = llElementsWithUuidAttributes.begin();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // overwrite existing uuid attribute
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pelmImage->setAttribute("uuid", guidTarget.toStringCurly());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Called from Appliance::buildXML() for each virtual system (machine) that
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * needs XML written out.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param writeLock The current write lock.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param elmToAddVirtualSystemsTo XML element to append elements to.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param pllElementsWithUuidAttributes out: list of XML elements produced here
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe * with UUID attributes for quick
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * fixing by caller later
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param vsdescThis The IVirtualSystemDescription
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe * instance for which to write XML.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param enFormat OVF format (0.9 or 1.0).
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param stack Structure for temporary private
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * data shared with caller.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soomevoid Appliance::buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ComObjPtr<VirtualSystemDescription> &vsdescThis,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Section xsi:type="ovf:NetworkSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualSystem = elmToAddVirtualSystemsTo.createChild("Content");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualSystem->setAttribute("xsi:type", "ovf:VirtualSystem_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualSystem = elmToAddVirtualSystemsTo.createChild("VirtualSystem");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /*xml::ElementNode *pelmVirtualSystemInfo =*/ pelmVirtualSystem->createChild("Info")->addContent("A virtual machine");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str &strVMName = llName.front()->strVboxCurrent;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualSystem->setAttribute("ovf:id", strVMName);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // product info
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llProduct = vsdescThis->findByType(VirtualSystemDescriptionType_Product);
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe std::list<VirtualSystemDescriptionEntry*> llProductUrl = vsdescThis->findByType(VirtualSystemDescriptionType_ProductUrl);
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe std::list<VirtualSystemDescriptionEntry*> llVendor = vsdescThis->findByType(VirtualSystemDescriptionType_Vendor);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llVendorUrl = vsdescThis->findByType(VirtualSystemDescriptionType_VendorUrl);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llVersion = vsdescThis->findByType(VirtualSystemDescriptionType_Version);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome bool fProduct = llProduct.size() && !llProduct.front()->strVboxCurrent.isEmpty();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome bool fProductUrl = llProductUrl.size() && !llProductUrl.front()->strVboxCurrent.isEmpty();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome bool fVendor = llVendor.size() && !llVendor.front()->strVboxCurrent.isEmpty();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome bool fVendorUrl = llVendorUrl.size() && !llVendorUrl.front()->strVboxCurrent.isEmpty();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome bool fVersion = llVersion.size() && !llVersion.front()->strVboxCurrent.isEmpty();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info>Meta-information about the installed software</Info>
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe <Product>VAtest</Product>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Vendor>SUN Microsystems</Vendor>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Version>10.0</Version>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <ProductUrl>http://blogs.sun.com/VirtualGuru</ProductUrl>
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe <VendorUrl>http://www.sun.com</VendorUrl>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </Section> */
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->setAttribute("xsi:type", "ovf:ProductSection_Type");
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pelmAnnotationSection = pelmVirtualSystem->createChild("ProductSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Info")->addContent("Meta-information about the installed software");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Product")->addContent(llProduct.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Vendor")->addContent(llVendor.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Version")->addContent(llVersion.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("ProductUrl")->addContent(llProductUrl.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("VendorUrl")->addContent(llVendorUrl.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // description
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llDescription = vsdescThis->findByType(VirtualSystemDescriptionType_Description);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome !llDescription.front()->strVboxCurrent.isEmpty())
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info>A human-readable annotation</Info>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Annotation>Plan 9</Annotation>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </Section> */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <Section ovf:required="false" xsi:type="ovf:AnnotationSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection = pelmVirtualSystem->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->setAttribute("xsi:type", "ovf:AnnotationSection_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection = pelmVirtualSystem->createChild("AnnotationSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Info")->addContent("A human-readable annotation");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmAnnotationSection->createChild("Annotation")->addContent(llDescription.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llLicense = vsdescThis->findByType(VirtualSystemDescriptionType_License);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <EulaSection>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info ovf:msgid="6">License agreement for the Virtual System.</Info>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <License ovf:msgid="1">License terms can go in here.</License>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </EulaSection> */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmEulaSection = pelmVirtualSystem->createChild("Section");
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pelmEulaSection->setAttribute("xsi:type", "ovf:EulaSection_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmEulaSection = pelmVirtualSystem->createChild("EulaSection");
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome pelmEulaSection->createChild("Info")->addContent("License agreement for the virtual system");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmEulaSection->createChild("License")->addContent(llLicense.front()->strVboxCurrent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // operating system
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome std::list<VirtualSystemDescriptionEntry*> llOS = vsdescThis->findByType(VirtualSystemDescriptionType_OS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <OperatingSystemSection ovf:id="82">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Info>Guest Operating System</Info>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <Description>Linux 2.6.x</Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </OperatingSystemSection> */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection = pelmVirtualSystem->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection->setAttribute("xsi:type", "ovf:OperatingSystemSection_Type");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection = pelmVirtualSystem->createChild("OperatingSystemSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection->setAttribute("ovf:id", llOS.front()->strOvf);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection->createChild("Info")->addContent("The kind of installed guest operating system");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome convertCIMOSType2VBoxOSType(strOSDesc, (ovf::CIMOSType_T)llOS.front()->strOvf.toInt32(), "");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmOperatingSystemSection->createChild("Description")->addContent(strOSDesc);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <VirtualHardwareSection ovf:id="hw1" ovf:transport="iso">
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // <Section xsi:type="ovf:VirtualHardwareSection_Type">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualHardwareSection = pelmVirtualSystem->createChild("Section");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualHardwareSection->setAttribute("xsi:type", "ovf:VirtualHardwareSection_Type");
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pelmVirtualHardwareSection = pelmVirtualSystem->createChild("VirtualHardwareSection");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVirtualHardwareSection->createChild("Info")->addContent("Virtual hardware requirements for a virtual machine");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <vssd:Description>Description of the virtual hardware section.</vssd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <vssd:ElementName>vmware</vssd:ElementName>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <vssd:InstanceID>1</vssd:InstanceID>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <vssd:VirtualSystemIdentifier>MyLampService</vssd:VirtualSystemIdentifier>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome </System> */
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe xml::ElementNode *pelmSystem = pelmVirtualHardwareSection->createChild("System");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmSystem->createChild("vssd:ElementName")->addContent("Virtual Hardware Family"); // required OVF 1.0
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <vssd:InstanceId>0</vssd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmSystem->createChild("vssd:InstanceId")->addContent("0");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else // capitalization changed...
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmSystem->createChild("vssd:InstanceID")->addContent("0");
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe // <vssd:VirtualSystemIdentifier>VAtest</vssd:VirtualSystemIdentifier>
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe pelmSystem->createChild("vssd:VirtualSystemIdentifier")->addContent(strVMName);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // pretend to be vmware compatible then
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmSystem->createChild("vssd:VirtualSystemType")->addContent(pcszHardware);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // loop thru all description entries twice; once to write out all
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // devices _except_ disk images, and a second time to assign the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // disk images; this is because disk images need to reference
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // IDE controllers, and we can't know their instance IDs without
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // assigning them first
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome list<VirtualSystemDescriptionEntry>::const_iterator itD;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome for (itD = vsdescThis->m->llDescriptions.begin();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const VirtualSystemDescriptionEntry &desc = *itD;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome LogFlowFunc(("Loop %u: handling description entry ulIndex=%u, type=%s, strRef=%s, strOvf=%s, strVbox=%s, strExtraConfig=%s\n",
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ( desc.type == VirtualSystemDescriptionType_HardDiskControllerIDE ? "HardDiskControllerIDE"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : desc.type == VirtualSystemDescriptionType_HardDiskControllerSATA ? "HardDiskControllerSATA"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : desc.type == VirtualSystemDescriptionType_HardDiskControllerSCSI ? "HardDiskControllerSCSI"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : desc.type == VirtualSystemDescriptionType_HardDiskControllerSAS ? "HardDiskControllerSAS"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome : desc.type == VirtualSystemDescriptionType_HardDiskImage ? "HardDiskImage"
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome ovf::ResourceType_T type = (ovf::ResourceType_T)0; // if this becomes != 0 then we do stuff
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strDescription; // results in <rasd:Description>...</rasd:Description> block
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strCaption; // results in <rasd:Caption>...</rasd:Caption> block
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome int32_t lAutomaticAllocation = -1; // 0 means "false", 1 means "true"
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe Utf8Str strConnection; // results in <rasd:Connection>...</rasd:Connection> block
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>1 virtual CPU</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>Number of virtual CPUs</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ElementName>virtual CPU</rasd:ElementName>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceID>1</rasd:InstanceID>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>3</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = Utf8StrFmt("%d virtual CPU", lVirtualQuantity); // without this ovftool won't eat the item
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>256 MB of memory</rasd:Caption>
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe <rasd:Description>Memory Size</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ElementName>Memory</rasd:ElementName>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceID>2</rasd:InstanceID>
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe <rasd:ResourceType>4</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:VirtualQuantity>256</rasd:VirtualQuantity>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = Utf8StrFmt("%d MB of memory", lVirtualQuantity); // without this ovftool won't eat the item
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe case VirtualSystemDescriptionType_HardDiskControllerIDE:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>ideController1</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>IDE Controller</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>5</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>5</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Address>1</rasd:Address>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:BusNumber>1</rasd:BusNumber>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // first IDE controller:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // remember this ID
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // second IDE controller:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // remember this ID
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_HardDiskControllerSATA:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>sataController0</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>SATA Controller</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>4</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>20</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceSubType>ahci</rasd:ResourceSubType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Address>0</rasd:Address>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:BusNumber>0</rasd:BusNumber>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome type = ovf::ResourceType_OtherStorageDevice; // 20
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // it seems that OVFTool always writes these two, and since we can only
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // have one SATA controller, we'll use this as well
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if ( desc.strVboxCurrent.isEmpty() // AHCI is the default in VirtualBox
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome || (!desc.strVboxCurrent.compare("ahci", Utf8Str::CaseInsensitive))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Invalid config string \"%s\" in SATA controller"), desc.strVboxCurrent.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // remember this ID
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_HardDiskControllerSCSI:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_HardDiskControllerSAS:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>scsiController0</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>SCSI Controller</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>4</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>6</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceSubType>buslogic</rasd:ResourceSubType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Address>0</rasd:Address>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:BusNumber>0</rasd:BusNumber>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // it seems that OVFTool always writes these two, and since we can only
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // have one SATA controller, we'll use this as well
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if ( desc.strVboxCurrent.isEmpty() // LsiLogic is the default in VirtualBox
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome || (!desc.strVboxCurrent.compare("lsilogic", Utf8Str::CaseInsensitive))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (!desc.strVboxCurrent.compare("buslogic", Utf8Str::CaseInsensitive))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (!desc.strVboxCurrent.compare("lsilogicsas", Utf8Str::CaseInsensitive))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Invalid config string \"%s\" in SCSI/SAS controller"), desc.strVboxCurrent.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // remember this ID
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_HardDiskImage:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>disk1</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>8</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>17</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:HostResource>/disk/vmdisk1</rasd:HostResource>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Parent>4</rasd:Parent>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:AddressOnParent>0</rasd:AddressOnParent>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome Utf8Str strDiskID = Utf8StrFmt("vmdisk%RI32", ++cDisks);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = Utf8StrFmt("disk%RI32", cDisks); // this is not used for anything else
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // the following references the "<Disks>" XML block
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strHostResource = Utf8StrFmt("/disk/%s", strDiskID.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // controller=<index>;channel=<c>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome size_t pos1 = desc.strExtraConfigCurrent.find("controller=");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome size_t pos2 = desc.strExtraConfigCurrent.find("channel=");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos1 + 11, NULL, 0, &lControllerIndex);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (lControllerIndex == lIDEPrimaryControllerIndex)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (lControllerIndex == lIDESecondaryControllerIndex)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (lControllerIndex == lSCSIControllerIndex)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome else if (lControllerIndex == lSATAControllerIndex)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome RTStrToInt32Ex(desc.strExtraConfigCurrent.c_str() + pos2 + 8, NULL, 0, &lAddressOnParent);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome LogFlowFunc(("HardDiskImage details: pos1=%d, pos2=%d, lControllerIndex=%d, lIDEPrimaryControllerIndex=%d, lIDESecondaryControllerIndex=%d, ulParent=%d, lAddressOnParent=%d\n",
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pos1, pos2, lControllerIndex, lIDEPrimaryControllerIndex, lIDESecondaryControllerIndex, ulParent, lAddressOnParent));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Missing or bad extra config string in hard disk image: \"%s\""), desc.strExtraConfigCurrent.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = "floppy0"; // this is what OVFTool writes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lAddressOnParent = 0; // this is what OVFTool writes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // we can't have a CD without an IDE controller
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome tr("Can't have CD-ROM without secondary IDE controller"));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = "cdrom1"; // this is what OVFTool writes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lAddressOnParent = 0; // this is what OVFTool writes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_NetworkAdapter:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>Ethernet adapter on 'VM Network'</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Connection>VM Network</rasd:Connection>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ElementName>VM network</rasd:ElementName>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceID>3</rasd:InstanceID>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>10</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strCaption = Utf8StrFmt("Ethernet adapter on '%s'", desc.strOvf.c_str());
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome type = ovf::ResourceType_EthernetAdapter; // 10
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Set the hardware type to something useful.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * To be compatible with vmware & others we set
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * PCNet32 for our PCNet types & E1000 for the
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * E1000 cards. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case NetworkAdapterType_Am79C973: strResourceSubType = "PCNet32"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case NetworkAdapterType_I82543GC: strResourceSubType = "E1000"; break;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome#endif /* VBOX_WITH_E1000 */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome case VirtualSystemDescriptionType_USBController:
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Item ovf:required="false">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>usb</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>USB Controller</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>3</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>23</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Address>0</rasd:Address>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:BusNumber>0</rasd:BusNumber>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* <Item ovf:required="false">
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Caption>sound</rasd:Caption>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:Description>Sound Card</rasd:Description>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:InstanceId>10</rasd:InstanceId>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceType>35</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome <rasd:AddressOnParent>3</rasd:AddressOnParent>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome strResourceSubType = desc.strOvf; // e.g. ensoniq1371
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome lAddressOnParent = 3; // what gives? this is what OVFTool writes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem = pelmVirtualHardwareSection->createChild("Item");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // NOTE: DO NOT CHANGE THE ORDER of these items! The OVF standards prescribes that
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // the elements from the rasd: namespace must be sorted by letter, and VMware
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // actually requires this as well (see public bug #6612)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:Address")->addContent(Utf8StrFmt("%d", lAddress));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:AddressOnParent")->addContent(Utf8StrFmt("%d", lAddressOnParent));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:AllocationUnits")->addContent(strAllocationUnits);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:AutomaticAllocation")->addContent( (lAutomaticAllocation) ? "true" : "false" );
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (enFormat == OVF_0_9) // BusNumber is invalid OVF 1.0 so only write it in 0.9 mode for OVFTool compatibility
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:BusNumber")->addContent(Utf8StrFmt("%d", lBusNumber));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:Caption")->addContent(strCaption);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:Connection")->addContent(strConnection);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:Description")->addContent(strDescription);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:ElementName")->addContent(strCaption);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:HostResource")->addContent(strHostResource);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <rasd:InstanceID>1</rasd:InstanceID>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmInstanceID = pItem->createChild("rasd:InstanceId");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmInstanceID = pItem->createChild("rasd:InstanceID"); // capitalization changed...
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmInstanceID->addContent(Utf8StrFmt("%d", ulInstanceID++));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:Parent")->addContent(Utf8StrFmt("%d", ulParent));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:ResourceSubType")->addContent(strResourceSubType);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <rasd:ResourceType>3</rasd:ResourceType>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:ResourceType")->addContent(Utf8StrFmt("%d", type));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // <rasd:VirtualQuantity>1</rasd:VirtualQuantity>
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pItem->createChild("rasd:VirtualQuantity")->addContent(Utf8StrFmt("%d", lVirtualQuantity));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome } // for (size_t uLoop = 1; uLoop <= 2; ++uLoop)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // now that we're done with the official OVF <Item> tags under <VirtualSystem>, write out VirtualBox XML
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // under the vbox: namespace
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome xml::ElementNode *pelmVBoxMachine = pelmVirtualSystem->createChild("vbox:Machine");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // ovf:required="false" tells other OVF parsers that they can ignore this thing
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVBoxMachine->setAttribute("ovf:required", "false");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // ovf:Info element is required or VMware will bail out on the vbox:Machine element
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome pelmVBoxMachine->createChild("ovf:Info")->addContent("Complete VirtualBox machine configuration in VirtualBox format");
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // create an empty machine config
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome settings::MachineConfigFile *pConfig = new settings::MachineConfigFile(NULL);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoWriteLock machineLock(vsdescThis->m->pMachine COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // fill the machine config
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome vsdescThis->m->pMachine->copyMachineDataToSettings(*pConfig);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // write the machine config to the vbox:Machine element
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome settings::MachineConfigFile::BuildMachineXML_WriteVboxVersionAttribute
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome | settings::MachineConfigFile::BuildMachineXML_SkipRemovableMedia,
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // but not BuildMachineXML_IncludeSnapshots nor BuildMachineXML_MediaRegistry
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * Actual worker code for writing out OVF/OVA to disk. This is called from Appliance::taskThreadWriteOVF()
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * and therefore runs on the OVF/OVA write worker thread. This runs in two contexts:
cda73f64f20b8a0afc4909f5ea1f055ec7913856Toomas Soome * 1) in a first worker thread; in that case, Appliance::Write() called Appliance::writeImpl();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * 2) in a second worker thread; in that case, Appliance::Write() called Appliance::writeImpl(), which
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * called Appliance::writeS3(), which called Appliance::writeImpl(), which then called this. In other
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * words, to write to the cloud, the first worker thread first starts a second worker thread to create
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * temporary files and then uploads them to the S3 cloud server.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome * @param pTask
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (FAILED(autoCaller.rc())) return autoCaller.rc();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Lock the media tree early to make sure nobody else tries to make changes
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // to the tree. Also lock the IAppliance object for writing.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoMultiWriteLock2 multiLock(&mVirtualBox->getMediaTreeLockHandle(), this->lockHandle() COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Additional protect the IAppliance object, cause we leave the lock
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // when starting the disk export and we don't won't block other
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // callers on this lengthy operations.
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome if (pTask->locInfo.strPath.endsWith(".ovf", Utf8Str::CaseInsensitive))
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // reset the state so others can call methods again
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeHRESULT Appliance::writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome int vrc = VDInterfaceAdd(&VDInterfaceIO, "Appliance::IORTFile",
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = writeFSImpl(pTask, writeLock, pSha1Callbacks, &storage);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Cleanup */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeHRESULT Appliance::writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome int vrc = RTTarOpen(&tar, pTask->locInfo.strPath.c_str(), RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome vrc = VDInterfaceAdd(&VDInterfaceIO, "Appliance::IORTTar",
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = writeFSImpl(pTask, writeLock, pSha1Callbacks, &storage);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Cleanup */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Delete ova file on error */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas SoomeHRESULT Appliance::writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHA1STORAGE pStorage)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // the XML stack contains two maps for disks and networks, which allows us to
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // a) have a list of unique disk names (to make sure the same disk name is only added once)
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // and b) keep a list of all networks
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Scope this to free the memory as soon as this is finished
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Create a xml document
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Now fully build a valid ovf document in memory
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome buildXML(writeLock, doc, stack, pTask->locInfo.strPath, pTask->enFormat);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Create a memory buffer containing the XML. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Extract the path */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Remove the extension and add ovf. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome /* Write the ovf file to disk. */
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome vrc = Sha1WriteBuf(tmpPath.c_str(), pvBuf, cbSize, pCallbacks, pStorage);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome fileList.push_back(STRPAIR(tmpPath, pStorage->strDigest));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // We need a proper format description
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Scope for the AutoReadLock
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome SystemProperties *pSysProps = mVirtualBox->getSystemProperties();
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome AutoReadLock propsLock(pSysProps COMMA_LOCKVAL_SRC_POS);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // We are always exporting to VMDK stream optimized for now
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Finally, write out the disks!
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome map<Utf8Str, const VirtualSystemDescriptionEntry*>::const_iterator itS;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const VirtualSystemDescriptionEntry *pDiskEntry = itS->second;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // source path: where the VBox image is
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome const Utf8Str &strSrcFilePath = pDiskEntry->strVboxCurrent;
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // Do NOT check here whether the file exists. findHardDisk will
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // figure that out, and filesystem-based tests are simply wrong
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // in the general case (think of iSCSI).
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome // clone the disk:
c1de7575521deda5ee777b8054a9c5b12f15b1eeRichard Lowe Log(("Finding source disk \"%s\"\n", strSrcFilePath.c_str()));
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = mVirtualBox->findHardDiskByLocation(strSrcFilePath, true, &pSourceDisk);
5ffb0c9b03b5149ff4f5821a62be4a52408ada2aToomas Soome rc = pSourceDisk->COMGETTER(Id)(uuidSource.asOutParam());
rc = pProgress2->init(mVirtualBox, static_cast<IAppliance*>(this), BstrFmt(tr("Creating medium '%s'"), strTargetFilePath.c_str()).raw(), TRUE);
pTask->pProgress->SetNextOperation(BstrFmt(tr("Exporting to disk image '%s'"), RTPathFilename(strTargetFilePath.c_str())).raw(),
rc = pSourceDisk->exportFile(strTargetFilePath.c_str(), format, MediumVariant_VmdkStreamOptimized, pCallbacks, pStorage, pProgress2);
throw rc3;
if (m->fManifest)
.stripPath();
pTask->pProgress->SetNextOperation(BstrFmt(tr("Creating manifest file '%s'"), strMfFileName.c_str()).raw(),
size_t i = 0;
++it1, ++i)
void *pvBuf;
vrc = RTManifestWriteFilesBuf(&pvBuf, &cbSize, ppManifestFiles, ppManifestDigests, fileList.size());
x.what());
++it1)
return rc;
char *pszTmpDir;
filesList.push_back(pair<Utf8Str, ULONG>(strTmpOvf, m->ulWeightForXmlOperation)); /* Use 1% of the total for the OVF file upload */
if (m->fManifest)
filesList.push_back(pair<Utf8Str, ULONG>(strMfFile , m->ulWeightForXmlOperation)); /* Use 1% of the total for the manifest file upload */
++it)
std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskImage);
++itH)
vrc = RTS3Create(&hS3, pTask->locInfo.strUsername.c_str(), pTask->locInfo.strPassword.c_str(), pTask->locInfo.strHostname.c_str(), "virtualbox-agent/"VBOX_VERSION_STRING);
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
pTask->pProgress->SetNextOperation(BstrFmt(tr("Uploading file '%s'"), pszFilename).raw(), s.second);
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);
for (list< pair<Utf8Str, ULONG> >::const_iterator it1 = filesList.begin(); it1 != filesList.end(); ++it1)
if (pszTmpDir)
return rc;