ApplianceImplPrivate.h revision 8ae161fca703d669e1306fafee128914f831f72b
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @file
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox Appliance private data definitions
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/*
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2006-2010 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsync *
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync#ifndef ____H_APPLIANCEIMPLPRIVATE
af062818b47340eef15700d2f0211576ba3506eevboxsync#define ____H_APPLIANCEIMPLPRIVATE
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncclass VirtualSystemDescription;
af062818b47340eef15700d2f0211576ba3506eevboxsync
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync#include "ovfreader.h"
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync////////////////////////////////////////////////////////////////////////////////
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync//
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync// Appliance data definition
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync//
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync////////////////////////////////////////////////////////////////////////////////
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsynctypedef std::pair<Utf8Str, Utf8Str> STRPAIR;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/* Describe a location for the import/export. The location could be a file on a
af062818b47340eef15700d2f0211576ba3506eevboxsync * local hard disk or a remote target based on the supported inet protocols. */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct LocationInfo
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync LocationInfo()
af062818b47340eef15700d2f0211576ba3506eevboxsync : storageType(VFSType_File) {}
af062818b47340eef15700d2f0211576ba3506eevboxsync VFSType_T storageType; /* Which type of storage should be handled */
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strPath; /* File path for the import/export */
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync// opaque private instance data of Appliance class
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct Appliance::Data
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync Data()
af062818b47340eef15700d2f0211576ba3506eevboxsync : state(ApplianceIdle)
af062818b47340eef15700d2f0211576ba3506eevboxsync , fManifest(true)
af062818b47340eef15700d2f0211576ba3506eevboxsync , pReader(NULL)
af062818b47340eef15700d2f0211576ba3506eevboxsync , ulWeightForXmlOperation(0)
af062818b47340eef15700d2f0211576ba3506eevboxsync , ulWeightForManifestOperation(0)
af062818b47340eef15700d2f0211576ba3506eevboxsync , ulTotalDisksMB(0)
af062818b47340eef15700d2f0211576ba3506eevboxsync , cDisks(0)
af062818b47340eef15700d2f0211576ba3506eevboxsync {
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync ~Data()
af062818b47340eef15700d2f0211576ba3506eevboxsync {
af062818b47340eef15700d2f0211576ba3506eevboxsync if (pReader)
af062818b47340eef15700d2f0211576ba3506eevboxsync {
af062818b47340eef15700d2f0211576ba3506eevboxsync delete pReader;
af062818b47340eef15700d2f0211576ba3506eevboxsync pReader = NULL;
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync }
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync ApplianceState state;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync LocationInfo locInfo; // location info for the currently processed OVF
af062818b47340eef15700d2f0211576ba3506eevboxsync bool fManifest; // Create a manifest file on export
af062818b47340eef15700d2f0211576ba3506eevboxsync RTCList<ImportOptions_T> optList;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync ovf::OVFReader *pReader;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync std::list< ComObjPtr<VirtualSystemDescription> >
af062818b47340eef15700d2f0211576ba3506eevboxsync virtualSystemDescriptions;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync std::list<Utf8Str> llWarnings;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG ulWeightForXmlOperation;
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG ulWeightForManifestOperation;
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG ulTotalDisksMB;
af062818b47340eef15700d2f0211576ba3506eevboxsync ULONG cDisks;
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strOVFSHA1Digest;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync std::list<Guid> llGuidsMachinesCreated;
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct Appliance::XMLStack
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
af062818b47340eef15700d2f0211576ba3506eevboxsync std::map<Utf8Str, bool> mapNetworks;
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct Appliance::TaskOVF
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync enum TaskType
af062818b47340eef15700d2f0211576ba3506eevboxsync {
af062818b47340eef15700d2f0211576ba3506eevboxsync Read,
af062818b47340eef15700d2f0211576ba3506eevboxsync Import,
af062818b47340eef15700d2f0211576ba3506eevboxsync Write
af062818b47340eef15700d2f0211576ba3506eevboxsync };
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync TaskOVF(Appliance *aThat,
af062818b47340eef15700d2f0211576ba3506eevboxsync TaskType aType,
af062818b47340eef15700d2f0211576ba3506eevboxsync LocationInfo aLocInfo,
af062818b47340eef15700d2f0211576ba3506eevboxsync ComObjPtr<Progress> &aProgress)
af062818b47340eef15700d2f0211576ba3506eevboxsync : pAppliance(aThat),
af062818b47340eef15700d2f0211576ba3506eevboxsync taskType(aType),
af062818b47340eef15700d2f0211576ba3506eevboxsync locInfo(aLocInfo),
af062818b47340eef15700d2f0211576ba3506eevboxsync pProgress(aProgress),
af062818b47340eef15700d2f0211576ba3506eevboxsync enFormat(unspecified),
af062818b47340eef15700d2f0211576ba3506eevboxsync rc(S_OK)
af062818b47340eef15700d2f0211576ba3506eevboxsync {}
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync static int updateProgress(unsigned uPercent, void *pvUser);
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync int startThread();
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync Appliance *pAppliance;
af062818b47340eef15700d2f0211576ba3506eevboxsync TaskType taskType;
af062818b47340eef15700d2f0211576ba3506eevboxsync const LocationInfo locInfo;
af062818b47340eef15700d2f0211576ba3506eevboxsync ComObjPtr<Progress> pProgress;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync OVFFormat enFormat;
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync HRESULT rc;
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct MyHardDiskAttachment
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync ComPtr<IMachine> pMachine;
af062818b47340eef15700d2f0211576ba3506eevboxsync Bstr controllerType;
af062818b47340eef15700d2f0211576ba3506eevboxsync int32_t lControllerPort; // 0-29 for SATA
af062818b47340eef15700d2f0211576ba3506eevboxsync int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
af062818b47340eef15700d2f0211576ba3506eevboxsync};
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync/**
af062818b47340eef15700d2f0211576ba3506eevboxsync * Used by Appliance::importMachineGeneric() to store
af062818b47340eef15700d2f0211576ba3506eevboxsync * input parameters and rollback information.
af062818b47340eef15700d2f0211576ba3506eevboxsync */
af062818b47340eef15700d2f0211576ba3506eevboxsyncstruct Appliance::ImportStack
af062818b47340eef15700d2f0211576ba3506eevboxsync{
af062818b47340eef15700d2f0211576ba3506eevboxsync // input pointers
af062818b47340eef15700d2f0211576ba3506eevboxsync const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strSourceDir; // directory where source files reside
af062818b47340eef15700d2f0211576ba3506eevboxsync const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
af062818b47340eef15700d2f0211576ba3506eevboxsync ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync // input parameters from VirtualSystemDescriptions
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strNameVBox; // VM name
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strDescription;
af062818b47340eef15700d2f0211576ba3506eevboxsync uint32_t cCPUs; // CPU count
af062818b47340eef15700d2f0211576ba3506eevboxsync bool fForceHWVirt; // if true, we force enabling hardware virtualization
af062818b47340eef15700d2f0211576ba3506eevboxsync bool fForceIOAPIC; // if true, we force enabling the IOAPIC
af062818b47340eef15700d2f0211576ba3506eevboxsync uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
af062818b47340eef15700d2f0211576ba3506eevboxsync#ifdef VBOX_WITH_USB
af062818b47340eef15700d2f0211576ba3506eevboxsync bool fUSBEnabled;
af062818b47340eef15700d2f0211576ba3506eevboxsync#endif
af062818b47340eef15700d2f0211576ba3506eevboxsync Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
af062818b47340eef15700d2f0211576ba3506eevboxsync // representation of the audio adapter (should always be "0" for AC97 presently)
af062818b47340eef15700d2f0211576ba3506eevboxsync
af062818b47340eef15700d2f0211576ba3506eevboxsync // session (not initially created)
af062818b47340eef15700d2f0211576ba3506eevboxsync ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
af062818b47340eef15700d2f0211576ba3506eevboxsync bool fSessionOpen; // true if the pSession is currently open and needs closing
af062818b47340eef15700d2f0211576ba3506eevboxsync
// a list of images that we created/imported; this is initially empty
// and will be cleaned up on errors
std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
std::list<STRPAIR> llSrcDisksDigest; // Digests of the source disks
ImportStack(const LocationInfo &aLocInfo,
const ovf::DiskImagesMap &aMapDisks,
ComObjPtr<Progress> &aProgress)
: locInfo(aLocInfo),
mapDisks(aMapDisks),
pProgress(aProgress),
cCPUs(1),
fForceHWVirt(false),
fForceIOAPIC(false),
ulMemorySizeMB(0),
fSessionOpen(false)
{
// disk images have to be on the same place as the OVF file. So
// strip the filename out of the full file path
strSourceDir = aLocInfo.strPath;
strSourceDir.stripFilename();
}
};
////////////////////////////////////////////////////////////////////////////////
//
// VirtualSystemDescription data definition
//
////////////////////////////////////////////////////////////////////////////////
struct VirtualSystemDescription::Data
{
std::list<VirtualSystemDescriptionEntry>
llDescriptions; // item descriptions
ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
settings::MachineConfigFile
*pConfig; // machine config created from <vbox:Machine> element if found (import only)
};
////////////////////////////////////////////////////////////////////////////////
//
// Internal helpers
//
////////////////////////////////////////////////////////////////////////////////
void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVbox);
Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
typedef struct SHA1STORAGE
{
PVDINTERFACE pVDImageIfaces;
bool fCreateDigest;
Utf8Str strDigest;
} SHA1STORAGE, *PSHA1STORAGE;
PVDINTERFACEIO Sha1CreateInterface();
PVDINTERFACEIO FileCreateInterface();
PVDINTERFACEIO TarCreateInterface();
int Sha1ReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, void *pvUser);
int Sha1WriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pCallbacks, void *pvUser);
#endif // ____H_APPLIANCEIMPLPRIVATE