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