1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Appliance private data definitions
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ____H_APPLIANCEIMPLPRIVATE
|
---|
19 | #define ____H_APPLIANCEIMPLPRIVATE
|
---|
20 |
|
---|
21 | class VirtualSystemDescription;
|
---|
22 |
|
---|
23 | #include "ovfreader.h"
|
---|
24 |
|
---|
25 | ////////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // Appliance data definition
|
---|
28 | //
|
---|
29 | ////////////////////////////////////////////////////////////////////////////////
|
---|
30 |
|
---|
31 | typedef std::pair<Utf8Str, Utf8Str> STRPAIR;
|
---|
32 |
|
---|
33 | /* Describe a location for the import/export. The location could be a file on a
|
---|
34 | * local hard disk or a remote target based on the supported inet protocols. */
|
---|
35 | struct LocationInfo
|
---|
36 | {
|
---|
37 | LocationInfo()
|
---|
38 | : storageType(VFSType_File) {}
|
---|
39 | VFSType_T storageType; /* Which type of storage should be handled */
|
---|
40 | Utf8Str strPath; /* File path for the import/export */
|
---|
41 | Utf8Str strHostname; /* Hostname on remote storage locations (could be empty) */
|
---|
42 | Utf8Str strUsername; /* Username on remote storage locations (could be empty) */
|
---|
43 | Utf8Str strPassword; /* Password on remote storage locations (could be empty) */
|
---|
44 | };
|
---|
45 |
|
---|
46 | // opaque private instance data of Appliance class
|
---|
47 | struct Appliance::Data
|
---|
48 | {
|
---|
49 | enum ApplianceState { ApplianceIdle, ApplianceImporting, ApplianceExporting };
|
---|
50 | enum digest_T {SHA1, SHA256};
|
---|
51 |
|
---|
52 | Data()
|
---|
53 | : state(ApplianceIdle)
|
---|
54 | , fManifest(true)
|
---|
55 | , fSha256(false)
|
---|
56 | , pReader(NULL)
|
---|
57 | , ulWeightForXmlOperation(0)
|
---|
58 | , ulWeightForManifestOperation(0)
|
---|
59 | , ulTotalDisksMB(0)
|
---|
60 | , cDisks(0)
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | ~Data()
|
---|
65 | {
|
---|
66 | if (pReader)
|
---|
67 | {
|
---|
68 | delete pReader;
|
---|
69 | pReader = NULL;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | ApplianceState state;
|
---|
74 |
|
---|
75 | LocationInfo locInfo; // location info for the currently processed OVF
|
---|
76 | bool fManifest; // Create a manifest file on export
|
---|
77 | bool fSha256; // true = SHA256 (OVF 2.0), false = SHA1 (OVF 1.0)
|
---|
78 | Utf8Str strOVFSHADigest;//SHA digest of OVf file. It is stored here after reading OVF file (before import)
|
---|
79 |
|
---|
80 | RTCList<ImportOptions_T> optList;
|
---|
81 |
|
---|
82 | ovf::OVFReader *pReader;
|
---|
83 |
|
---|
84 | std::list< ComObjPtr<VirtualSystemDescription> >
|
---|
85 | virtualSystemDescriptions;
|
---|
86 |
|
---|
87 | std::list<Utf8Str> llWarnings;
|
---|
88 |
|
---|
89 | ULONG ulWeightForXmlOperation;
|
---|
90 | ULONG ulWeightForManifestOperation;
|
---|
91 | ULONG ulTotalDisksMB;
|
---|
92 | ULONG cDisks;
|
---|
93 |
|
---|
94 | std::list<Guid> llGuidsMachinesCreated;
|
---|
95 | };
|
---|
96 |
|
---|
97 | struct Appliance::XMLStack
|
---|
98 | {
|
---|
99 | std::map<Utf8Str, const VirtualSystemDescriptionEntry*> mapDisks;
|
---|
100 | std::map<Utf8Str, bool> mapNetworks;
|
---|
101 | };
|
---|
102 |
|
---|
103 | struct Appliance::TaskOVF
|
---|
104 | {
|
---|
105 | enum TaskType
|
---|
106 | {
|
---|
107 | Read,
|
---|
108 | Import,
|
---|
109 | Write
|
---|
110 | };
|
---|
111 |
|
---|
112 | TaskOVF(Appliance *aThat,
|
---|
113 | TaskType aType,
|
---|
114 | LocationInfo aLocInfo,
|
---|
115 | ComObjPtr<Progress> &aProgress)
|
---|
116 | : pAppliance(aThat),
|
---|
117 | taskType(aType),
|
---|
118 | locInfo(aLocInfo),
|
---|
119 | pProgress(aProgress),
|
---|
120 | enFormat(ovf::OVFVersion_unknown),
|
---|
121 | rc(S_OK)
|
---|
122 | {}
|
---|
123 |
|
---|
124 | static int updateProgress(unsigned uPercent, void *pvUser);
|
---|
125 |
|
---|
126 | int startThread();
|
---|
127 |
|
---|
128 | Appliance *pAppliance;
|
---|
129 | TaskType taskType;
|
---|
130 | const LocationInfo locInfo;
|
---|
131 | ComObjPtr<Progress> pProgress;
|
---|
132 |
|
---|
133 | ovf::OVFVersion_T enFormat;
|
---|
134 |
|
---|
135 | HRESULT rc;
|
---|
136 | };
|
---|
137 |
|
---|
138 | struct MyHardDiskAttachment
|
---|
139 | {
|
---|
140 | ComPtr<IMachine> pMachine;
|
---|
141 | Bstr controllerType;
|
---|
142 | int32_t lControllerPort; // 0-29 for SATA
|
---|
143 | int32_t lDevice; // IDE: 0 or 1, otherwise 0 always
|
---|
144 | };
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Used by Appliance::importMachineGeneric() to store
|
---|
148 | * input parameters and rollback information.
|
---|
149 | */
|
---|
150 | struct Appliance::ImportStack
|
---|
151 | {
|
---|
152 | // input pointers
|
---|
153 | const LocationInfo &locInfo; // ptr to location info from Appliance::importFS()
|
---|
154 | Utf8Str strSourceDir; // directory where source files reside
|
---|
155 | const ovf::DiskImagesMap &mapDisks; // ptr to disks map in OVF
|
---|
156 | ComObjPtr<Progress> &pProgress; // progress object passed into Appliance::importFS()
|
---|
157 |
|
---|
158 | // input parameters from VirtualSystemDescriptions
|
---|
159 | Utf8Str strNameVBox; // VM name
|
---|
160 | Utf8Str strMachineFolder; // FQ host folder where the VirtualBox machine would be created
|
---|
161 | Utf8Str strOsTypeVBox; // VirtualBox guest OS type as string
|
---|
162 | Utf8Str strDescription;
|
---|
163 | uint32_t cCPUs; // CPU count
|
---|
164 | bool fForceHWVirt; // if true, we force enabling hardware virtualization
|
---|
165 | bool fForceIOAPIC; // if true, we force enabling the IOAPIC
|
---|
166 | uint32_t ulMemorySizeMB; // virtual machine RAM in megabytes
|
---|
167 | #ifdef VBOX_WITH_USB
|
---|
168 | bool fUSBEnabled;
|
---|
169 | #endif
|
---|
170 | Utf8Str strAudioAdapter; // if not empty, then the guest has audio enabled, and this is the decimal
|
---|
171 | // representation of the audio adapter (should always be "0" for AC97 presently)
|
---|
172 |
|
---|
173 | // session (not initially created)
|
---|
174 | ComPtr<ISession> pSession; // session opened in Appliance::importFS() for machine manipulation
|
---|
175 | bool fSessionOpen; // true if the pSession is currently open and needs closing
|
---|
176 |
|
---|
177 | // a list of images that we created/imported; this is initially empty
|
---|
178 | // and will be cleaned up on errors
|
---|
179 | std::list<MyHardDiskAttachment> llHardDiskAttachments; // disks that were attached
|
---|
180 | std::list<STRPAIR> llSrcDisksDigest; // Digests of the source disks
|
---|
181 |
|
---|
182 | ImportStack(const LocationInfo &aLocInfo,
|
---|
183 | const ovf::DiskImagesMap &aMapDisks,
|
---|
184 | ComObjPtr<Progress> &aProgress)
|
---|
185 | : locInfo(aLocInfo),
|
---|
186 | mapDisks(aMapDisks),
|
---|
187 | pProgress(aProgress),
|
---|
188 | cCPUs(1),
|
---|
189 | fForceHWVirt(false),
|
---|
190 | fForceIOAPIC(false),
|
---|
191 | ulMemorySizeMB(0),
|
---|
192 | fSessionOpen(false)
|
---|
193 | {
|
---|
194 | // disk images have to be on the same place as the OVF file. So
|
---|
195 | // strip the filename out of the full file path
|
---|
196 | strSourceDir = aLocInfo.strPath;
|
---|
197 | strSourceDir.stripFilename();
|
---|
198 | }
|
---|
199 | };
|
---|
200 |
|
---|
201 | ////////////////////////////////////////////////////////////////////////////////
|
---|
202 | //
|
---|
203 | // VirtualSystemDescription data definition
|
---|
204 | //
|
---|
205 | ////////////////////////////////////////////////////////////////////////////////
|
---|
206 |
|
---|
207 | struct VirtualSystemDescription::Data
|
---|
208 | {
|
---|
209 | std::list<VirtualSystemDescriptionEntry>
|
---|
210 | llDescriptions; // item descriptions
|
---|
211 |
|
---|
212 | ComPtr<Machine> pMachine; // VirtualBox machine this description was exported from (export only)
|
---|
213 |
|
---|
214 | settings::MachineConfigFile
|
---|
215 | *pConfig; // machine config created from <vbox:Machine> element if found (import only)
|
---|
216 | };
|
---|
217 |
|
---|
218 | ////////////////////////////////////////////////////////////////////////////////
|
---|
219 | //
|
---|
220 | // Internal helpers
|
---|
221 | //
|
---|
222 | ////////////////////////////////////////////////////////////////////////////////
|
---|
223 |
|
---|
224 | void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr);
|
---|
225 |
|
---|
226 | ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode);
|
---|
227 |
|
---|
228 | Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type);
|
---|
229 |
|
---|
230 | bool checkComplianceDigestAndOVFVersion(bool digestType, ovf::OVFVersion_T ovfVersion);
|
---|
231 |
|
---|
232 | typedef struct SHASTORAGE
|
---|
233 | {
|
---|
234 | PVDINTERFACE pVDImageIfaces;
|
---|
235 | bool fCreateDigest;
|
---|
236 | bool fSha256; /* false = SHA1 (OVF 1.x), true = SHA256 (OVF 2.0) */
|
---|
237 | Utf8Str strDigest;
|
---|
238 | } SHASTORAGE, *PSHASTORAGE;
|
---|
239 |
|
---|
240 | PVDINTERFACEIO ShaCreateInterface();
|
---|
241 | PVDINTERFACEIO FileCreateInterface();
|
---|
242 | PVDINTERFACEIO TarCreateInterface();
|
---|
243 | int ShaReadBuf(const char *pcszFilename, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
244 | int ShaWriteBuf(const char *pcszFilename, void *pvBuf, size_t cbSize, PVDINTERFACEIO pIfIo, void *pvUser);
|
---|
245 |
|
---|
246 | #endif // !____H_APPLIANCEIMPLPRIVATE
|
---|
247 |
|
---|