1 | /* $Id: ovfreader.h 62485 2016-07-22 18:36:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - OVF reader declarations.
|
---|
4 | *
|
---|
5 | * Depends only on IPRT, including the RTCString and IPRT XML classes.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2016 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef ____H_OVFREADER
|
---|
21 | #define ____H_OVFREADER
|
---|
22 |
|
---|
23 | #include "iprt/cpp/xml.h"
|
---|
24 | #include <map>
|
---|
25 |
|
---|
26 | namespace ovf
|
---|
27 | {
|
---|
28 |
|
---|
29 | ////////////////////////////////////////////////////////////////////////////////
|
---|
30 | //
|
---|
31 | // Errors
|
---|
32 | //
|
---|
33 | ////////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Thrown by OVFReader for any kind of error that is not an XML error but
|
---|
37 | * still makes the OVF impossible to parse. Based on xml::LogicError so
|
---|
38 | * that one catch() for all xml::LogicError can handle all possible errors.
|
---|
39 | */
|
---|
40 | class OVFLogicError : public xml::LogicError
|
---|
41 | {
|
---|
42 | public:
|
---|
43 | OVFLogicError(const char *aFormat, ...);
|
---|
44 | };
|
---|
45 |
|
---|
46 |
|
---|
47 | ////////////////////////////////////////////////////////////////////////////////
|
---|
48 | //
|
---|
49 | // Enumerations
|
---|
50 | //
|
---|
51 | ////////////////////////////////////////////////////////////////////////////////
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * CIM OS values.
|
---|
55 | *
|
---|
56 | * The OVF 1.10 spec refers to some CIM_OperatingSystem.mof doc. Could this be it:
|
---|
57 | * http://cvs.opengroup.org/cgi-bin/cvsweb.cgi/pegasus/Schemas/CIM231/DMTF/System/CIM_OperatingSystem.mof
|
---|
58 | *
|
---|
59 | * @todo r=bird: Why are the values are repeating 'CIMOS'. CIMOSType_T is also
|
---|
60 | * repeating it self, 'Type' and '_T'. Why not call it kCIOMOpSys,
|
---|
61 | * easier to read as well.
|
---|
62 | * Then also apply: s/CIMOSType_CIMOS_/kCIMOpSys_/g
|
---|
63 | */
|
---|
64 | enum CIMOSType_T
|
---|
65 | {
|
---|
66 | CIMOSType_CIMOS_Unknown = 0,
|
---|
67 | CIMOSType_CIMOS_Other = 1,
|
---|
68 | CIMOSType_CIMOS_MACOS = 2,
|
---|
69 | CIMOSType_CIMOS_ATTUNIX = 3,
|
---|
70 | CIMOSType_CIMOS_DGUX = 4,
|
---|
71 | CIMOSType_CIMOS_DECNT = 5,
|
---|
72 | CIMOSType_CIMOS_Tru64UNIX = 6,
|
---|
73 | CIMOSType_CIMOS_OpenVMS = 7,
|
---|
74 | CIMOSType_CIMOS_HPUX = 8,
|
---|
75 | CIMOSType_CIMOS_AIX = 9,
|
---|
76 | CIMOSType_CIMOS_MVS = 10,
|
---|
77 | CIMOSType_CIMOS_OS400 = 11,
|
---|
78 | CIMOSType_CIMOS_OS2 = 12,
|
---|
79 | CIMOSType_CIMOS_JavaVM = 13,
|
---|
80 | CIMOSType_CIMOS_MSDOS = 14,
|
---|
81 | CIMOSType_CIMOS_WIN3x = 15,
|
---|
82 | CIMOSType_CIMOS_WIN95 = 16,
|
---|
83 | CIMOSType_CIMOS_WIN98 = 17,
|
---|
84 | CIMOSType_CIMOS_WINNT = 18,
|
---|
85 | CIMOSType_CIMOS_WINCE = 19,
|
---|
86 | CIMOSType_CIMOS_NCR3000 = 20,
|
---|
87 | CIMOSType_CIMOS_NetWare = 21,
|
---|
88 | CIMOSType_CIMOS_OSF = 22,
|
---|
89 | CIMOSType_CIMOS_DCOS = 23,
|
---|
90 | CIMOSType_CIMOS_ReliantUNIX = 24,
|
---|
91 | CIMOSType_CIMOS_SCOUnixWare = 25,
|
---|
92 | CIMOSType_CIMOS_SCOOpenServer = 26,
|
---|
93 | CIMOSType_CIMOS_Sequent = 27,
|
---|
94 | CIMOSType_CIMOS_IRIX = 28,
|
---|
95 | CIMOSType_CIMOS_Solaris = 29,
|
---|
96 | CIMOSType_CIMOS_SunOS = 30,
|
---|
97 | CIMOSType_CIMOS_U6000 = 31,
|
---|
98 | CIMOSType_CIMOS_ASERIES = 32,
|
---|
99 | CIMOSType_CIMOS_HPNonStopOS = 33,
|
---|
100 | CIMOSType_CIMOS_HPNonStopOSS = 34,
|
---|
101 | CIMOSType_CIMOS_BS2000 = 35,
|
---|
102 | CIMOSType_CIMOS_LINUX = 36,
|
---|
103 | CIMOSType_CIMOS_Lynx = 37,
|
---|
104 | CIMOSType_CIMOS_XENIX = 38,
|
---|
105 | CIMOSType_CIMOS_VM = 39,
|
---|
106 | CIMOSType_CIMOS_InteractiveUNIX = 40,
|
---|
107 | CIMOSType_CIMOS_BSDUNIX = 41,
|
---|
108 | CIMOSType_CIMOS_FreeBSD = 42,
|
---|
109 | CIMOSType_CIMOS_NetBSD = 43,
|
---|
110 | CIMOSType_CIMOS_GNUHurd = 44,
|
---|
111 | CIMOSType_CIMOS_OS9 = 45,
|
---|
112 | CIMOSType_CIMOS_MACHKernel = 46,
|
---|
113 | CIMOSType_CIMOS_Inferno = 47,
|
---|
114 | CIMOSType_CIMOS_QNX = 48,
|
---|
115 | CIMOSType_CIMOS_EPOC = 49,
|
---|
116 | CIMOSType_CIMOS_IxWorks = 50,
|
---|
117 | CIMOSType_CIMOS_VxWorks = 51,
|
---|
118 | CIMOSType_CIMOS_MiNT = 52,
|
---|
119 | CIMOSType_CIMOS_BeOS = 53,
|
---|
120 | CIMOSType_CIMOS_HPMPE = 54,
|
---|
121 | CIMOSType_CIMOS_NextStep = 55,
|
---|
122 | CIMOSType_CIMOS_PalmPilot = 56,
|
---|
123 | CIMOSType_CIMOS_Rhapsody = 57,
|
---|
124 | CIMOSType_CIMOS_Windows2000 = 58,
|
---|
125 | CIMOSType_CIMOS_Dedicated = 59,
|
---|
126 | CIMOSType_CIMOS_OS390 = 60,
|
---|
127 | CIMOSType_CIMOS_VSE = 61,
|
---|
128 | CIMOSType_CIMOS_TPF = 62,
|
---|
129 | CIMOSType_CIMOS_WindowsMe = 63,
|
---|
130 | CIMOSType_CIMOS_CalderaOpenUNIX = 64,
|
---|
131 | CIMOSType_CIMOS_OpenBSD = 65,
|
---|
132 | CIMOSType_CIMOS_NotApplicable = 66,
|
---|
133 | CIMOSType_CIMOS_WindowsXP = 67,
|
---|
134 | CIMOSType_CIMOS_zOS = 68,
|
---|
135 | CIMOSType_CIMOS_MicrosoftWindowsServer2003 = 69,
|
---|
136 | CIMOSType_CIMOS_MicrosoftWindowsServer2003_64 = 70,
|
---|
137 | CIMOSType_CIMOS_WindowsXP_64 = 71,
|
---|
138 | CIMOSType_CIMOS_WindowsXPEmbedded = 72,
|
---|
139 | CIMOSType_CIMOS_WindowsVista = 73,
|
---|
140 | CIMOSType_CIMOS_WindowsVista_64 = 74,
|
---|
141 | CIMOSType_CIMOS_WindowsEmbeddedforPointofService = 75,
|
---|
142 | CIMOSType_CIMOS_MicrosoftWindowsServer2008 = 76,
|
---|
143 | CIMOSType_CIMOS_MicrosoftWindowsServer2008_64 = 77,
|
---|
144 | CIMOSType_CIMOS_FreeBSD_64 = 78,
|
---|
145 | CIMOSType_CIMOS_RedHatEnterpriseLinux = 79,
|
---|
146 | CIMOSType_CIMOS_RedHatEnterpriseLinux_64 = 80,
|
---|
147 | CIMOSType_CIMOS_Solaris_64 = 81,
|
---|
148 | CIMOSType_CIMOS_SUSE = 82,
|
---|
149 | CIMOSType_CIMOS_SUSE_64 = 83,
|
---|
150 | CIMOSType_CIMOS_SLES = 84,
|
---|
151 | CIMOSType_CIMOS_SLES_64 = 85,
|
---|
152 | CIMOSType_CIMOS_NovellOES = 86,
|
---|
153 | CIMOSType_CIMOS_NovellLinuxDesktop = 87,
|
---|
154 | CIMOSType_CIMOS_SunJavaDesktopSystem = 88,
|
---|
155 | CIMOSType_CIMOS_Mandriva = 89,
|
---|
156 | CIMOSType_CIMOS_Mandriva_64 = 90,
|
---|
157 | CIMOSType_CIMOS_TurboLinux = 91,
|
---|
158 | CIMOSType_CIMOS_TurboLinux_64 = 92,
|
---|
159 | CIMOSType_CIMOS_Ubuntu = 93,
|
---|
160 | CIMOSType_CIMOS_Ubuntu_64 = 94,
|
---|
161 | CIMOSType_CIMOS_Debian = 95,
|
---|
162 | CIMOSType_CIMOS_Debian_64 = 96,
|
---|
163 | CIMOSType_CIMOS_Linux_2_4_x = 97,
|
---|
164 | CIMOSType_CIMOS_Linux_2_4_x_64 = 98,
|
---|
165 | CIMOSType_CIMOS_Linux_2_6_x = 99,
|
---|
166 | CIMOSType_CIMOS_Linux_2_6_x_64 = 100,
|
---|
167 | CIMOSType_CIMOS_Linux_64 = 101,
|
---|
168 | CIMOSType_CIMOS_Other_64 = 102,
|
---|
169 | // types added with CIM 2.25.0 follow:
|
---|
170 | CIMOSType_CIMOS_WindowsServer2008R2 = 103,
|
---|
171 | CIMOSType_CIMOS_VMwareESXi = 104,
|
---|
172 | CIMOSType_CIMOS_Windows7 = 105,
|
---|
173 | CIMOSType_CIMOS_CentOS = 106,
|
---|
174 | CIMOSType_CIMOS_CentOS_64 = 107,
|
---|
175 | CIMOSType_CIMOS_OracleEnterpriseLinux = 108,
|
---|
176 | CIMOSType_CIMOS_OracleEnterpriseLinux_64 = 109,
|
---|
177 | CIMOSType_CIMOS_eComStation = 110
|
---|
178 | // no new types added with CIM 2.26.0
|
---|
179 | };
|
---|
180 |
|
---|
181 | enum OVFVersion_T
|
---|
182 | {
|
---|
183 | OVFVersion_unknown,
|
---|
184 | OVFVersion_0_9,
|
---|
185 | OVFVersion_1_0,
|
---|
186 | OVFVersion_2_0
|
---|
187 | };
|
---|
188 |
|
---|
189 | const char* const OVF09_URI_string = "http://www.vmware.com/schema/ovf/1/envelope";
|
---|
190 | const char* const OVF10_URI_string = "http://schemas.dmtf.org/ovf/envelope/1";
|
---|
191 | const char* const OVF20_URI_string = "http://schemas.dmtf.org/ovf/envelope/2";
|
---|
192 |
|
---|
193 | const char* const DTMF_SPECS_URI = "http://schemas.dmtf.org/wbem/cim-html/2/";
|
---|
194 |
|
---|
195 | ////////////////////////////////////////////////////////////////////////////////
|
---|
196 | //
|
---|
197 | // Envelope data
|
---|
198 | //
|
---|
199 | ////////////////////////////////////////////////////////////////////////////////
|
---|
200 | struct EnvelopeData
|
---|
201 | {
|
---|
202 | OVFVersion_T version;//OVF standard version, it is used internally only by VirtualBox
|
---|
203 | RTCString lang;//language
|
---|
204 |
|
---|
205 | OVFVersion_T getOVFVersion() const
|
---|
206 | {
|
---|
207 | return version;
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 | RTCString getStringOVFVersion() const
|
---|
212 | {
|
---|
213 | if (version == OVFVersion_0_9)
|
---|
214 | return "0.9";
|
---|
215 | else if (version == OVFVersion_1_0)
|
---|
216 | return "1.0";
|
---|
217 | else if (version == OVFVersion_2_0)
|
---|
218 | return "2.0";
|
---|
219 | else
|
---|
220 | return "";
|
---|
221 | }
|
---|
222 |
|
---|
223 | void setOVFVersion(OVFVersion_T v)
|
---|
224 | {
|
---|
225 | version = v;
|
---|
226 | }
|
---|
227 | };
|
---|
228 |
|
---|
229 |
|
---|
230 | struct FileReference
|
---|
231 | {
|
---|
232 | RTCString strHref; // value from /References/File/@href (filename)
|
---|
233 | RTCString strDiskId; // value from /References/File/@id ()
|
---|
234 | };
|
---|
235 |
|
---|
236 | typedef std::map<uint32_t, FileReference> FileReferenceMap;
|
---|
237 |
|
---|
238 | ////////////////////////////////////////////////////////////////////////////////
|
---|
239 | //
|
---|
240 | // Hardware definition structs
|
---|
241 | //
|
---|
242 | ////////////////////////////////////////////////////////////////////////////////
|
---|
243 |
|
---|
244 | struct DiskImage
|
---|
245 | {
|
---|
246 | // fields from /DiskSection/Disk
|
---|
247 | RTCString strDiskId; // value from DiskSection/Disk/@diskId
|
---|
248 | int64_t iCapacity; // value from DiskSection/Disk/@capacity;
|
---|
249 | // (maximum size for dynamic images, I guess; we always translate this to bytes)
|
---|
250 | int64_t iPopulatedSize; // optional value from DiskSection/Disk/@populatedSize
|
---|
251 | // (actual used size of disk, always in bytes; can be an estimate of used disk
|
---|
252 | // space, but cannot be larger than iCapacity; -1 if not set)
|
---|
253 | RTCString strFormat; // value from DiskSection/Disk/@format
|
---|
254 | // typically http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized
|
---|
255 | RTCString uuidVBox; // optional; if the file was exported by VirtualBox >= 3.2,
|
---|
256 | // then this has the UUID with which the disk was registered
|
---|
257 |
|
---|
258 | // fields from /References/File; the spec says the file reference from disk can be empty,
|
---|
259 | // so in that case, strFilename will be empty, then a new disk should be created
|
---|
260 | RTCString strHref; // value from /References/File/@href (filename); if empty, then the remaining fields are ignored
|
---|
261 | int64_t iSize; // value from /References/File/@size (optional according to spec; then we set -1 here)
|
---|
262 | int64_t iChunkSize; // value from /References/File/@chunkSize (optional, unsupported)
|
---|
263 | RTCString strCompression; // value from /References/File/@compression (optional, can be "gzip" according to spec)
|
---|
264 |
|
---|
265 | // additional field which has a descriptive size in megabytes derived from the above; this can be used for progress reports
|
---|
266 | uint32_t ulSuggestedSizeMB;
|
---|
267 | };
|
---|
268 |
|
---|
269 | enum ResourceType_T
|
---|
270 | { ResourceType_Other = 1,
|
---|
271 | ResourceType_ComputerSystem = 2,
|
---|
272 | ResourceType_Processor = 3,
|
---|
273 | ResourceType_Memory = 4,
|
---|
274 | ResourceType_IDEController = 5,
|
---|
275 | ResourceType_ParallelSCSIHBA = 6,
|
---|
276 | ResourceType_FCHBA = 7,
|
---|
277 | ResourceType_iSCSIHBA = 8,
|
---|
278 | ResourceType_IBHCA = 9,
|
---|
279 | ResourceType_EthernetAdapter = 10,
|
---|
280 | ResourceType_OtherNetworkAdapter = 11,
|
---|
281 | ResourceType_IOSlot = 12,
|
---|
282 | ResourceType_IODevice = 13,
|
---|
283 | ResourceType_FloppyDrive = 14,
|
---|
284 | ResourceType_CDDrive = 15,
|
---|
285 | ResourceType_DVDDrive = 16,
|
---|
286 | ResourceType_HardDisk = 17,
|
---|
287 | ResourceType_OtherStorageDevice = 20,
|
---|
288 | ResourceType_USBController = 23,
|
---|
289 | ResourceType_SoundCard = 35
|
---|
290 | };
|
---|
291 |
|
---|
292 |
|
---|
293 | enum StorageAccessType_T
|
---|
294 | { StorageAccessType_Unknown = 0,
|
---|
295 | StorageAccessType_Readable = 1,
|
---|
296 | StorageAccessType_Writeable = 2,
|
---|
297 | StorageAccessType_ReadWrite = 3
|
---|
298 | };
|
---|
299 |
|
---|
300 | enum ComplianceType_T
|
---|
301 | { ComplianceType_No = 0,
|
---|
302 | ComplianceType_Soft = 1,
|
---|
303 | ComplianceType_Medium = 2,
|
---|
304 | ComplianceType_Strong = 3
|
---|
305 | };
|
---|
306 |
|
---|
307 | class VirtualHardwareItem
|
---|
308 | {
|
---|
309 | public:
|
---|
310 | RTCString strDescription;
|
---|
311 | RTCString strCaption;
|
---|
312 | RTCString strElementName;
|
---|
313 |
|
---|
314 | uint32_t ulInstanceID;
|
---|
315 | uint32_t ulParent;
|
---|
316 |
|
---|
317 | ResourceType_T resourceType;
|
---|
318 | RTCString strOtherResourceType;
|
---|
319 | RTCString strResourceSubType;
|
---|
320 | bool fResourceRequired;
|
---|
321 |
|
---|
322 | RTCString strHostResource; // "Abstractly specifies how a device shall connect to a resource on the deployment platform.
|
---|
323 | // Not all devices need a backing." Used with disk items, for which this references a virtual
|
---|
324 | // disk from the Disks section.
|
---|
325 | bool fAutomaticAllocation;
|
---|
326 | bool fAutomaticDeallocation;
|
---|
327 | RTCString strConnection; // "All Ethernet adapters that specify the same abstract network connection name within an OVF
|
---|
328 | // package shall be deployed on the same network. The abstract network connection name shall be
|
---|
329 | // listed in the NetworkSection at the outermost envelope level." We ignore this and only set up
|
---|
330 | // a network adapter depending on the network name.
|
---|
331 | RTCString strAddress; // "Device-specific. For an Ethernet adapter, this specifies the MAC address."
|
---|
332 | int32_t lAddress; // strAddress as an integer, if applicable.
|
---|
333 | RTCString strAddressOnParent; // "For a device, this specifies its location on the controller."
|
---|
334 | RTCString strAllocationUnits; // "Specifies the units of allocation used. For example, “byte * 2^20”."
|
---|
335 | uint64_t ullVirtualQuantity; // "Specifies the quantity of resources presented. For example, “256”."
|
---|
336 | uint64_t ullReservation; // "Specifies the minimum quantity of resources guaranteed to be available."
|
---|
337 | uint64_t ullLimit; // "Specifies the maximum quantity of resources that will be granted."
|
---|
338 | uint64_t ullWeight; // "Specifies a relative priority for this allocation in relation to other allocations."
|
---|
339 |
|
---|
340 | RTCString strConsumerVisibility;
|
---|
341 | RTCString strMappingBehavior;
|
---|
342 | RTCString strPoolID;
|
---|
343 | uint32_t ulBusNumber; // seen with IDE controllers, but not listed in OVF spec
|
---|
344 |
|
---|
345 | uint32_t ulLineNumber; // line number of <Item> element in XML source; cached for error messages
|
---|
346 |
|
---|
347 | VirtualHardwareItem()
|
---|
348 | : ulInstanceID(0),
|
---|
349 | fAutomaticAllocation(false),
|
---|
350 | fAutomaticDeallocation(false),
|
---|
351 | ullVirtualQuantity(0),
|
---|
352 | ullReservation(0),
|
---|
353 | ullLimit(0),
|
---|
354 | ullWeight(0),
|
---|
355 | ulBusNumber(0),
|
---|
356 | ulLineNumber(0)
|
---|
357 | {
|
---|
358 | itemName = "Item";
|
---|
359 | };
|
---|
360 |
|
---|
361 | void fillItem(const xml::ElementNode *item);
|
---|
362 |
|
---|
363 | void setDefaultFlag()
|
---|
364 | {
|
---|
365 | fDefault = true;
|
---|
366 | }
|
---|
367 |
|
---|
368 | bool isThereDefaultValues() const
|
---|
369 | {
|
---|
370 | return fDefault;
|
---|
371 | }
|
---|
372 |
|
---|
373 | void checkConsistencyAndCompliance() RT_THROW(OVFLogicError)
|
---|
374 | {
|
---|
375 | _checkConsistencyAndCompliance();
|
---|
376 | }
|
---|
377 |
|
---|
378 | protected:
|
---|
379 | virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
|
---|
380 | virtual const RTCString& getItemName()
|
---|
381 | {
|
---|
382 | return _getItemName();
|
---|
383 | }
|
---|
384 |
|
---|
385 | private:
|
---|
386 | RTCString itemName;
|
---|
387 | bool fDefault;//true means that some fields were absent in the XML and some default values were assigned to.
|
---|
388 |
|
---|
389 | virtual const RTCString& _getItemName()
|
---|
390 | {
|
---|
391 | return itemName;
|
---|
392 | }
|
---|
393 | };
|
---|
394 |
|
---|
395 | class StorageItem: public VirtualHardwareItem
|
---|
396 | {
|
---|
397 | //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/
|
---|
398 | StorageAccessType_T accessType;
|
---|
399 | RTCString strHostExtentName;
|
---|
400 | int16_t hostExtentNameFormat;
|
---|
401 | int16_t hostExtentNameNamespace;
|
---|
402 | int64_t hostExtentStartingAddress;
|
---|
403 | int64_t hostResourceBlockSize;
|
---|
404 | int64_t limit;
|
---|
405 | RTCString strOtherHostExtentNameFormat;
|
---|
406 | RTCString strOtherHostExtentNameNamespace;
|
---|
407 | int64_t reservation;
|
---|
408 | int64_t virtualQuantity;
|
---|
409 | RTCString strVirtualQuantityUnits;
|
---|
410 | int64_t virtualResourceBlockSize;
|
---|
411 |
|
---|
412 | public:
|
---|
413 | StorageItem(): VirtualHardwareItem(),
|
---|
414 | accessType(StorageAccessType_Unknown),
|
---|
415 | hostExtentNameFormat(-1),
|
---|
416 | hostExtentNameNamespace(-1),
|
---|
417 | hostExtentStartingAddress(-1),
|
---|
418 | hostResourceBlockSize(-1),
|
---|
419 | limit(-1),
|
---|
420 | reservation(-1),
|
---|
421 | virtualQuantity(-1),
|
---|
422 | virtualResourceBlockSize(-1)
|
---|
423 | {
|
---|
424 | itemName = "StorageItem";
|
---|
425 | };
|
---|
426 |
|
---|
427 | void fillItem(const xml::ElementNode *item);
|
---|
428 |
|
---|
429 | protected:
|
---|
430 | virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
|
---|
431 | private:
|
---|
432 | RTCString itemName;
|
---|
433 |
|
---|
434 | virtual const RTCString& _getItemName()
|
---|
435 | {
|
---|
436 | return itemName;
|
---|
437 | }
|
---|
438 | };
|
---|
439 |
|
---|
440 |
|
---|
441 | class EthernetPortItem: public VirtualHardwareItem
|
---|
442 | {
|
---|
443 | //see DMTF Schema Documentation http://schemas.dmtf.org/wbem/cim-html/2/
|
---|
444 | uint16_t DefaultPortVID;
|
---|
445 | uint16_t DefaultPriority;
|
---|
446 | uint16_t DesiredVLANEndpointMode;
|
---|
447 | uint32_t GroupID;
|
---|
448 | uint32_t ManagerID;
|
---|
449 | RTCString strNetworkPortProfileID;
|
---|
450 | uint16_t NetworkPortProfileIDType;
|
---|
451 | RTCString strOtherEndpointMode;
|
---|
452 | RTCString strOtherNetworkPortProfileIDTypeInfo;
|
---|
453 | RTCString strPortCorrelationID;
|
---|
454 | uint16_t PortVID;
|
---|
455 | bool Promiscuous;
|
---|
456 | uint64_t ReceiveBandwidthLimit;
|
---|
457 | uint16_t ReceiveBandwidthReservation;
|
---|
458 | bool SourceMACFilteringEnabled;
|
---|
459 | uint32_t VSITypeID;
|
---|
460 | uint8_t VSITypeIDVersion;
|
---|
461 | uint16_t AllowedPriorities[256];
|
---|
462 | RTCString strAllowedToReceiveMACAddresses;
|
---|
463 | uint16_t AllowedToReceiveVLANs[256];
|
---|
464 | RTCString strAllowedToTransmitMACAddresses;
|
---|
465 | uint16_t AllowedToTransmitVLANs[256];
|
---|
466 |
|
---|
467 | public:
|
---|
468 | EthernetPortItem(): VirtualHardwareItem()
|
---|
469 | {
|
---|
470 | itemName = "EthernetPortItem";
|
---|
471 | };
|
---|
472 |
|
---|
473 | void fillItem(const xml::ElementNode *item);
|
---|
474 |
|
---|
475 | protected:
|
---|
476 | virtual void _checkConsistencyAndCompliance() RT_THROW(OVFLogicError);
|
---|
477 | private:
|
---|
478 | RTCString itemName;
|
---|
479 |
|
---|
480 | virtual const RTCString& _getItemName()
|
---|
481 | {
|
---|
482 | return itemName;
|
---|
483 | }
|
---|
484 | };
|
---|
485 |
|
---|
486 | typedef std::map<RTCString, DiskImage> DiskImagesMap;
|
---|
487 |
|
---|
488 | struct VirtualSystem;
|
---|
489 |
|
---|
490 | typedef std::map<uint32_t, VirtualHardwareItem> HardwareItemsMap;
|
---|
491 |
|
---|
492 | struct HardDiskController
|
---|
493 | {
|
---|
494 | uint32_t idController; // instance ID (Item/InstanceId); this gets referenced from VirtualDisk
|
---|
495 |
|
---|
496 | enum ControllerSystemType { IDE, SATA, SCSI };
|
---|
497 | ControllerSystemType system; // one of IDE, SATA, SCSI
|
---|
498 |
|
---|
499 | RTCString strControllerType;
|
---|
500 | // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
|
---|
501 | // note that we treat LsiLogicSAS as a SCSI controller (system == SCSI) even though VirtualBox
|
---|
502 | // treats it as a fourth class besides IDE, SATA, SCSI
|
---|
503 |
|
---|
504 | int32_t lAddress; // value from OVF "Address" element
|
---|
505 | bool fPrimary; // controller index; this is determined heuristically by the OVF reader and will
|
---|
506 | // be true for the first controller of this type (e.g. IDE primary ctler) or
|
---|
507 | // false for the next (e.g. IDE secondary ctler)
|
---|
508 |
|
---|
509 | HardDiskController()
|
---|
510 | : idController(0),
|
---|
511 | lAddress(0),
|
---|
512 | fPrimary(true)
|
---|
513 | { }
|
---|
514 | };
|
---|
515 |
|
---|
516 | typedef std::map<uint32_t, HardDiskController> ControllersMap;
|
---|
517 |
|
---|
518 | struct VirtualDisk
|
---|
519 | {
|
---|
520 | uint32_t idController;// SCSI (or IDE) controller this disk is connected to;
|
---|
521 | // this must match HardDiskController.idController and
|
---|
522 | // points into VirtualSystem.mapControllers
|
---|
523 | uint32_t ulAddressOnParent;// parsed strAddressOnParent of hardware item; will be 0 or 1 for IDE
|
---|
524 | // and possibly higher for disks attached to SCSI controllers (untested)
|
---|
525 | RTCString strDiskId;// if the hard disk has an ovf:/disk/<id> reference,
|
---|
526 | // this receives the <id> component; points to one of the
|
---|
527 | // references in Appliance::Data.mapDisks
|
---|
528 | bool fEmpty;//true - empty disk, e.g. the component <rasd:HostResource>...</rasd:HostResource> is absent.
|
---|
529 | };
|
---|
530 |
|
---|
531 | typedef std::map<RTCString, VirtualDisk> VirtualDisksMap;
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * A list of EthernetAdapters is contained in VirtualSystem, representing the
|
---|
535 | * ethernet adapters in the virtual system.
|
---|
536 | */
|
---|
537 | struct EthernetAdapter
|
---|
538 | {
|
---|
539 | RTCString strAdapterType; // "PCNet32" or "E1000" or whatever; from <rasd:ResourceSubType>
|
---|
540 | RTCString strNetworkName; // from <rasd:Connection>
|
---|
541 | };
|
---|
542 |
|
---|
543 | typedef std::list<EthernetAdapter> EthernetAdaptersList;
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * A list of VirtualSystem structs is created by OVFReader::read(). Each refers to
|
---|
547 | * a <VirtualSystem> block in the OVF file.
|
---|
548 | */
|
---|
549 | struct VirtualSystem
|
---|
550 | {
|
---|
551 | RTCString strName; // copy of VirtualSystem/@id
|
---|
552 |
|
---|
553 | RTCString strDescription; // copy of VirtualSystem/AnnotationSection content, if any
|
---|
554 |
|
---|
555 | CIMOSType_T cimos;
|
---|
556 | RTCString strCimosDesc; // readable description of the cimos type in the case of cimos = 0/1/102
|
---|
557 | RTCString strTypeVBox; // optional type from @vbox:ostype attribute (VirtualBox 4.0 or higher)
|
---|
558 |
|
---|
559 | RTCString strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
|
---|
560 | // VMware Workstation 6.5 is "vmx-07"
|
---|
561 |
|
---|
562 | HardwareItemsMap mapHardwareItems; // map of virtual hardware items, sorted by unique instance ID
|
---|
563 |
|
---|
564 | uint64_t ullMemorySize; // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
|
---|
565 | uint16_t cCPUs; // no. of CPUs, copied from llHardwareItems; default = 1
|
---|
566 |
|
---|
567 | EthernetAdaptersList llEthernetAdapters; // (one for each VirtualSystem/Item[@ResourceType=10]element)
|
---|
568 |
|
---|
569 | ControllersMap mapControllers;
|
---|
570 | // list of hard disk controllers
|
---|
571 | // (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
|
---|
572 |
|
---|
573 | VirtualDisksMap mapVirtualDisks;
|
---|
574 | // (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
|
---|
575 |
|
---|
576 | bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
|
---|
577 | bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
|
---|
578 | bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
|
---|
579 |
|
---|
580 | RTCString strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
|
---|
581 | // VMware Workstation 6.5 uses "ensoniq1371" for example
|
---|
582 |
|
---|
583 | RTCString strLicenseText; // license info if any; receives contents of VirtualSystem/EulaSection/License
|
---|
584 |
|
---|
585 | RTCString strProduct; // product info if any; receives contents of VirtualSystem/ProductSection/Product
|
---|
586 | RTCString strVendor; // product info if any; receives contents of VirtualSystem/ProductSection/Vendor
|
---|
587 | RTCString strVersion; // product info if any; receives contents of VirtualSystem/ProductSection/Version
|
---|
588 | RTCString strProductUrl; // product info if any; receives contents of VirtualSystem/ProductSection/ProductUrl
|
---|
589 | RTCString strVendorUrl; // product info if any; receives contents of VirtualSystem/ProductSection/VendorUrl
|
---|
590 |
|
---|
591 | const xml::ElementNode *pelmVBoxMachine; // pointer to <vbox:Machine> element under <VirtualSystem> element or NULL if not present
|
---|
592 |
|
---|
593 | VirtualSystem()
|
---|
594 | : cimos(CIMOSType_CIMOS_Unknown),
|
---|
595 | ullMemorySize(0),
|
---|
596 | cCPUs(1),
|
---|
597 | fHasFloppyDrive(false),
|
---|
598 | fHasCdromDrive(false),
|
---|
599 | fHasUsbController(false),
|
---|
600 | pelmVBoxMachine(NULL)
|
---|
601 | {
|
---|
602 | }
|
---|
603 | };
|
---|
604 |
|
---|
605 | ////////////////////////////////////////////////////////////////////////////////
|
---|
606 | //
|
---|
607 | // Class OVFReader
|
---|
608 | //
|
---|
609 | ////////////////////////////////////////////////////////////////////////////////
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * OVFReader attempts to open, read in and parse an OVF XML file. This is all done
|
---|
613 | * in the constructor; if there is any kind of error in the file -- filesystem error
|
---|
614 | * from IPRT, XML parsing errors from libxml, or OVF logical errors --, exceptions
|
---|
615 | * are thrown. These are all based on xml::Error.
|
---|
616 | *
|
---|
617 | * Hence, use this class as follows:
|
---|
618 | <code>
|
---|
619 | OVFReader *pReader = NULL;
|
---|
620 | try
|
---|
621 | {
|
---|
622 | pReader = new("/path/to/file.ovf");
|
---|
623 | }
|
---|
624 | catch (xml::Error &e)
|
---|
625 | {
|
---|
626 | printf("A terrible thing happened: %s", e.what());
|
---|
627 | }
|
---|
628 | // now go look at pReader->m_llVirtualSystem and what's in there
|
---|
629 | if (pReader)
|
---|
630 | delete pReader;
|
---|
631 | </code>
|
---|
632 | */
|
---|
633 | class OVFReader
|
---|
634 | {
|
---|
635 | public:
|
---|
636 | OVFReader(const void *pvBuf, size_t cbSize, const RTCString &path);
|
---|
637 | OVFReader(const RTCString &path);
|
---|
638 |
|
---|
639 | // Data fields
|
---|
640 | EnvelopeData m_envelopeData; //data of root element "Envelope"
|
---|
641 | RTCString m_strPath; // file name given to constructor
|
---|
642 | DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId
|
---|
643 | std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read()
|
---|
644 |
|
---|
645 | private:
|
---|
646 | xml::Document m_doc;
|
---|
647 |
|
---|
648 | void parse();
|
---|
649 | void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem);
|
---|
650 | void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem);
|
---|
651 | void HandleNetworkSection(const xml::ElementNode *pSectionElem);
|
---|
652 | void HandleVirtualSystemContent(const xml::ElementNode *pContentElem);
|
---|
653 | };
|
---|
654 |
|
---|
655 | } // end namespace ovf
|
---|
656 |
|
---|
657 | #endif // !____H_OVFREADER
|
---|
658 |
|
---|