VirtualBox

source: vbox/trunk/src/VBox/Main/include/ovfreader.h@ 45227

最後變更 在這個檔案從45227是 45227,由 vboxsync 提交於 12 年 前

Main: OVF 2.0 support. Part 1 - SHA256 digest is supported.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 19.4 KB
 
1/* $Id: ovfreader.h 45227 2013-03-28 12:22:11Z 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-2011 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.alldomusa.eu.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
26namespace ovf
27{
28
29////////////////////////////////////////////////////////////////////////////////
30//
31// Enumerations
32//
33////////////////////////////////////////////////////////////////////////////////
34
35enum CIMOSType_T
36{
37 CIMOSType_CIMOS_Unknown = 0,
38 CIMOSType_CIMOS_Other = 1,
39 CIMOSType_CIMOS_MACOS = 2,
40 CIMOSType_CIMOS_ATTUNIX = 3,
41 CIMOSType_CIMOS_DGUX = 4,
42 CIMOSType_CIMOS_DECNT = 5,
43 CIMOSType_CIMOS_Tru64UNIX = 6,
44 CIMOSType_CIMOS_OpenVMS = 7,
45 CIMOSType_CIMOS_HPUX = 8,
46 CIMOSType_CIMOS_AIX = 9,
47 CIMOSType_CIMOS_MVS = 10,
48 CIMOSType_CIMOS_OS400 = 11,
49 CIMOSType_CIMOS_OS2 = 12,
50 CIMOSType_CIMOS_JavaVM = 13,
51 CIMOSType_CIMOS_MSDOS = 14,
52 CIMOSType_CIMOS_WIN3x = 15,
53 CIMOSType_CIMOS_WIN95 = 16,
54 CIMOSType_CIMOS_WIN98 = 17,
55 CIMOSType_CIMOS_WINNT = 18,
56 CIMOSType_CIMOS_WINCE = 19,
57 CIMOSType_CIMOS_NCR3000 = 20,
58 CIMOSType_CIMOS_NetWare = 21,
59 CIMOSType_CIMOS_OSF = 22,
60 CIMOSType_CIMOS_DCOS = 23,
61 CIMOSType_CIMOS_ReliantUNIX = 24,
62 CIMOSType_CIMOS_SCOUnixWare = 25,
63 CIMOSType_CIMOS_SCOOpenServer = 26,
64 CIMOSType_CIMOS_Sequent = 27,
65 CIMOSType_CIMOS_IRIX = 28,
66 CIMOSType_CIMOS_Solaris = 29,
67 CIMOSType_CIMOS_SunOS = 30,
68 CIMOSType_CIMOS_U6000 = 31,
69 CIMOSType_CIMOS_ASERIES = 32,
70 CIMOSType_CIMOS_HPNonStopOS = 33,
71 CIMOSType_CIMOS_HPNonStopOSS = 34,
72 CIMOSType_CIMOS_BS2000 = 35,
73 CIMOSType_CIMOS_LINUX = 36,
74 CIMOSType_CIMOS_Lynx = 37,
75 CIMOSType_CIMOS_XENIX = 38,
76 CIMOSType_CIMOS_VM = 39,
77 CIMOSType_CIMOS_InteractiveUNIX = 40,
78 CIMOSType_CIMOS_BSDUNIX = 41,
79 CIMOSType_CIMOS_FreeBSD = 42,
80 CIMOSType_CIMOS_NetBSD = 43,
81 CIMOSType_CIMOS_GNUHurd = 44,
82 CIMOSType_CIMOS_OS9 = 45,
83 CIMOSType_CIMOS_MACHKernel = 46,
84 CIMOSType_CIMOS_Inferno = 47,
85 CIMOSType_CIMOS_QNX = 48,
86 CIMOSType_CIMOS_EPOC = 49,
87 CIMOSType_CIMOS_IxWorks = 50,
88 CIMOSType_CIMOS_VxWorks = 51,
89 CIMOSType_CIMOS_MiNT = 52,
90 CIMOSType_CIMOS_BeOS = 53,
91 CIMOSType_CIMOS_HPMPE = 54,
92 CIMOSType_CIMOS_NextStep = 55,
93 CIMOSType_CIMOS_PalmPilot = 56,
94 CIMOSType_CIMOS_Rhapsody = 57,
95 CIMOSType_CIMOS_Windows2000 = 58,
96 CIMOSType_CIMOS_Dedicated = 59,
97 CIMOSType_CIMOS_OS390 = 60,
98 CIMOSType_CIMOS_VSE = 61,
99 CIMOSType_CIMOS_TPF = 62,
100 CIMOSType_CIMOS_WindowsMe = 63,
101 CIMOSType_CIMOS_CalderaOpenUNIX = 64,
102 CIMOSType_CIMOS_OpenBSD = 65,
103 CIMOSType_CIMOS_NotApplicable = 66,
104 CIMOSType_CIMOS_WindowsXP = 67,
105 CIMOSType_CIMOS_zOS = 68,
106 CIMOSType_CIMOS_MicrosoftWindowsServer2003 = 69,
107 CIMOSType_CIMOS_MicrosoftWindowsServer2003_64 = 70,
108 CIMOSType_CIMOS_WindowsXP_64 = 71,
109 CIMOSType_CIMOS_WindowsXPEmbedded = 72,
110 CIMOSType_CIMOS_WindowsVista = 73,
111 CIMOSType_CIMOS_WindowsVista_64 = 74,
112 CIMOSType_CIMOS_WindowsEmbeddedforPointofService = 75,
113 CIMOSType_CIMOS_MicrosoftWindowsServer2008 = 76,
114 CIMOSType_CIMOS_MicrosoftWindowsServer2008_64 = 77,
115 CIMOSType_CIMOS_FreeBSD_64 = 78,
116 CIMOSType_CIMOS_RedHatEnterpriseLinux = 79,
117 CIMOSType_CIMOS_RedHatEnterpriseLinux_64 = 80,
118 CIMOSType_CIMOS_Solaris_64 = 81,
119 CIMOSType_CIMOS_SUSE = 82,
120 CIMOSType_CIMOS_SUSE_64 = 83,
121 CIMOSType_CIMOS_SLES = 84,
122 CIMOSType_CIMOS_SLES_64 = 85,
123 CIMOSType_CIMOS_NovellOES = 86,
124 CIMOSType_CIMOS_NovellLinuxDesktop = 87,
125 CIMOSType_CIMOS_SunJavaDesktopSystem = 88,
126 CIMOSType_CIMOS_Mandriva = 89,
127 CIMOSType_CIMOS_Mandriva_64 = 90,
128 CIMOSType_CIMOS_TurboLinux = 91,
129 CIMOSType_CIMOS_TurboLinux_64 = 92,
130 CIMOSType_CIMOS_Ubuntu = 93,
131 CIMOSType_CIMOS_Ubuntu_64 = 94,
132 CIMOSType_CIMOS_Debian = 95,
133 CIMOSType_CIMOS_Debian_64 = 96,
134 CIMOSType_CIMOS_Linux_2_4_x = 97,
135 CIMOSType_CIMOS_Linux_2_4_x_64 = 98,
136 CIMOSType_CIMOS_Linux_2_6_x = 99,
137 CIMOSType_CIMOS_Linux_2_6_x_64 = 100,
138 CIMOSType_CIMOS_Linux_64 = 101,
139 CIMOSType_CIMOS_Other_64 = 102,
140 // types added with CIM 2.25.0 follow:
141 CIMOSType_CIMOS_WindowsServer2008R2 = 103,
142 CIMOSType_CIMOS_VMwareESXi = 104,
143 CIMOSType_CIMOS_Windows7 = 105,
144 CIMOSType_CIMOS_CentOS = 106,
145 CIMOSType_CIMOS_CentOS_64 = 107,
146 CIMOSType_CIMOS_OracleEnterpriseLinux = 108,
147 CIMOSType_CIMOS_OracleEnterpriseLinux_64 = 109,
148 CIMOSType_CIMOS_eComStation = 110
149 // no new types added with CIM 2.26.0
150};
151
152enum OVFVersion_T
153{
154 OVFVersion_unknown,
155 OVFVersion_0_9,
156 OVFVersion_1_0,
157 OVFVersion_2_0
158};
159
160////////////////////////////////////////////////////////////////////////////////
161//
162// Envelope data
163//
164////////////////////////////////////////////////////////////////////////////////
165struct EnvelopeData
166{
167 RTCString version;//OVF standard version, it is used internally only by VirtualBox
168 RTCString lang;//language
169
170 OVFVersion_T getOVFVersion() const
171 {
172 if(version == "0.9")
173 return OVFVersion_0_9;
174 else if(version == "1.0")
175 return OVFVersion_1_0;
176 else if(version == "2.0")
177 return OVFVersion_2_0;
178 else
179 return OVFVersion_unknown;
180 }
181};
182
183////////////////////////////////////////////////////////////////////////////////
184//
185// Hardware definition structs
186//
187////////////////////////////////////////////////////////////////////////////////
188
189struct DiskImage
190{
191 // fields from /DiskSection/Disk
192 RTCString strDiskId; // value from DiskSection/Disk/@diskId
193 int64_t iCapacity; // value from DiskSection/Disk/@capacity;
194 // (maximum size for dynamic images, I guess; we always translate this to bytes)
195 int64_t iPopulatedSize; // optional value from DiskSection/Disk/@populatedSize
196 // (actual used size of disk, always in bytes; can be an estimate of used disk
197 // space, but cannot be larger than iCapacity; -1 if not set)
198 RTCString strFormat; // value from DiskSection/Disk/@format
199 // typically http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized
200 RTCString uuidVbox; // optional; if the file was exported by VirtualBox >= 3.2,
201 // then this has the UUID with which the disk was registered
202
203 // fields from /References/File; the spec says the file reference from disk can be empty,
204 // so in that case, strFilename will be empty, then a new disk should be created
205 RTCString strHref; // value from /References/File/@href (filename); if empty, then the remaining fields are ignored
206 int64_t iSize; // value from /References/File/@size (optional according to spec; then we set -1 here)
207 int64_t iChunkSize; // value from /References/File/@chunkSize (optional, unsupported)
208 RTCString strCompression; // value from /References/File/@compression (optional, can be "gzip" according to spec)
209
210 // additional field which has a descriptive size in megabytes derived from the above; this can be used for progress reports
211 uint32_t ulSuggestedSizeMB;
212};
213
214enum ResourceType_T
215{ ResourceType_Other = 1,
216 ResourceType_ComputerSystem = 2,
217 ResourceType_Processor = 3,
218 ResourceType_Memory = 4,
219 ResourceType_IDEController = 5,
220 ResourceType_ParallelSCSIHBA = 6,
221 ResourceType_FCHBA = 7,
222 ResourceType_iSCSIHBA = 8,
223 ResourceType_IBHCA = 9,
224 ResourceType_EthernetAdapter = 10,
225 ResourceType_OtherNetworkAdapter = 11,
226 ResourceType_IOSlot = 12,
227 ResourceType_IODevice = 13,
228 ResourceType_FloppyDrive = 14,
229 ResourceType_CDDrive = 15,
230 ResourceType_DVDDrive = 16,
231 ResourceType_HardDisk = 17,
232 ResourceType_OtherStorageDevice = 20,
233 ResourceType_USBController = 23,
234 ResourceType_SoundCard = 35
235};
236
237struct VirtualHardwareItem
238{
239 RTCString strDescription;
240 RTCString strCaption;
241 RTCString strElementName;
242
243 uint32_t ulInstanceID;
244 uint32_t ulParent;
245
246 ResourceType_T resourceType;
247 RTCString strOtherResourceType;
248 RTCString strResourceSubType;
249 bool fResourceRequired;
250
251 RTCString strHostResource; // "Abstractly specifies how a device shall connect to a resource on the deployment platform.
252 // Not all devices need a backing." Used with disk items, for which this references a virtual
253 // disk from the Disks section.
254 bool fAutomaticAllocation;
255 bool fAutomaticDeallocation;
256 RTCString strConnection; // "All Ethernet adapters that specify the same abstract network connection name within an OVF
257 // package shall be deployed on the same network. The abstract network connection name shall be
258 // listed in the NetworkSection at the outermost envelope level." We ignore this and only set up
259 // a network adapter depending on the network name.
260 RTCString strAddress; // "Device-specific. For an Ethernet adapter, this specifies the MAC address."
261 int32_t lAddress; // strAddress as an integer, if applicable.
262 RTCString strAddressOnParent; // "For a device, this specifies its location on the controller."
263 RTCString strAllocationUnits; // "Specifies the units of allocation used. For example, “byte * 2^20”."
264 uint64_t ullVirtualQuantity; // "Specifies the quantity of resources presented. For example, “256”."
265 uint64_t ullReservation; // "Specifies the minimum quantity of resources guaranteed to be available."
266 uint64_t ullLimit; // "Specifies the maximum quantity of resources that will be granted."
267 uint64_t ullWeight; // "Specifies a relative priority for this allocation in relation to other allocations."
268
269 RTCString strConsumerVisibility;
270 RTCString strMappingBehavior;
271 RTCString strPoolID;
272 uint32_t ulBusNumber; // seen with IDE controllers, but not listed in OVF spec
273
274 uint32_t ulLineNumber; // line number of <Item> element in XML source; cached for error messages
275
276 VirtualHardwareItem()
277 : ulInstanceID(0),
278 fAutomaticAllocation(false),
279 fAutomaticDeallocation(false),
280 ullVirtualQuantity(0),
281 ullReservation(0),
282 ullLimit(0),
283 ullWeight(0),
284 ulBusNumber(0),
285 ulLineNumber(0)
286 {};
287};
288
289typedef std::map<RTCString, DiskImage> DiskImagesMap;
290
291struct VirtualSystem;
292
293typedef std::map<uint32_t, VirtualHardwareItem> HardwareItemsMap;
294
295struct HardDiskController
296{
297 uint32_t idController; // instance ID (Item/InstanceId); this gets referenced from VirtualDisk
298
299 enum ControllerSystemType { IDE, SATA, SCSI };
300 ControllerSystemType system; // one of IDE, SATA, SCSI
301
302 RTCString strControllerType;
303 // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
304 // note that we treat LsiLogicSAS as a SCSI controller (system == SCSI) even though VirtualBox
305 // treats it as a fourth class besides IDE, SATA, SCSI
306
307 int32_t lAddress; // value from OVF "Address" element
308 bool fPrimary; // controller index; this is determined heuristically by the OVF reader and will
309 // be true for the first controller of this type (e.g. IDE primary ctler) or
310 // false for the next (e.g. IDE secondary ctler)
311
312 HardDiskController()
313 : idController(0),
314 lAddress(0),
315 fPrimary(true)
316 { }
317};
318
319typedef std::map<uint32_t, HardDiskController> ControllersMap;
320
321struct VirtualDisk
322{
323 uint32_t idController; // SCSI (or IDE) controller this disk is connected to;
324 // this must match HardDiskController.idController and
325 // points into VirtualSystem.mapControllers
326 uint32_t ulAddressOnParent; // parsed strAddressOnParent of hardware item; will be 0 or 1 for IDE
327 // and possibly higher for disks attached to SCSI controllers (untested)
328 RTCString strDiskId; // if the hard disk has an ovf:/disk/<id> reference,
329 // this receives the <id> component; points to one of the
330 // references in Appliance::Data.mapDisks
331};
332
333typedef std::map<RTCString, VirtualDisk> VirtualDisksMap;
334
335/**
336 * A list of EthernetAdapters is contained in VirtualSystem, representing the
337 * ethernet adapters in the virtual system.
338 */
339struct EthernetAdapter
340{
341 RTCString strAdapterType; // "PCNet32" or "E1000" or whatever; from <rasd:ResourceSubType>
342 RTCString strNetworkName; // from <rasd:Connection>
343};
344
345typedef std::list<EthernetAdapter> EthernetAdaptersList;
346
347/**
348 * A list of VirtualSystem structs is created by OVFReader::read(). Each refers to
349 * a <VirtualSystem> block in the OVF file.
350 */
351struct VirtualSystem
352{
353 RTCString strName; // copy of VirtualSystem/@id
354
355 RTCString strDescription; // copy of VirtualSystem/AnnotationSection content, if any
356
357 CIMOSType_T cimos;
358 RTCString strCimosDesc; // readable description of the cimos type in the case of cimos = 0/1/102
359 RTCString strTypeVbox; // optional type from @vbox:ostype attribute (VirtualBox 4.0 or higher)
360
361 RTCString strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
362 // VMware Workstation 6.5 is "vmx-07"
363
364 HardwareItemsMap mapHardwareItems; // map of virtual hardware items, sorted by unique instance ID
365
366 uint64_t ullMemorySize; // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
367 uint16_t cCPUs; // no. of CPUs, copied from llHardwareItems; default = 1
368
369 EthernetAdaptersList llEthernetAdapters; // (one for each VirtualSystem/Item[@ResourceType=10]element)
370
371 ControllersMap mapControllers;
372 // list of hard disk controllers
373 // (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
374
375 VirtualDisksMap mapVirtualDisks;
376 // (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
377
378 bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
379 bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
380 bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
381
382 RTCString strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
383 // VMware Workstation 6.5 uses "ensoniq1371" for example
384
385 RTCString strLicenseText; // license info if any; receives contents of VirtualSystem/EulaSection/License
386
387 RTCString strProduct; // product info if any; receives contents of VirtualSystem/ProductSection/Product
388 RTCString strVendor; // product info if any; receives contents of VirtualSystem/ProductSection/Vendor
389 RTCString strVersion; // product info if any; receives contents of VirtualSystem/ProductSection/Version
390 RTCString strProductUrl; // product info if any; receives contents of VirtualSystem/ProductSection/ProductUrl
391 RTCString strVendorUrl; // product info if any; receives contents of VirtualSystem/ProductSection/VendorUrl
392
393 const xml::ElementNode // pointer to <vbox:Machine> element under <VirtualSystem> element or NULL if not present
394 *pelmVboxMachine;
395
396 VirtualSystem()
397 : cimos(CIMOSType_CIMOS_Unknown),
398 ullMemorySize(0),
399 cCPUs(1),
400 fHasFloppyDrive(false),
401 fHasCdromDrive(false),
402 fHasUsbController(false),
403 pelmVboxMachine(NULL)
404 {
405 }
406};
407
408////////////////////////////////////////////////////////////////////////////////
409//
410// Class OVFReader
411//
412////////////////////////////////////////////////////////////////////////////////
413
414/**
415 * OVFReader attempts to open, read in and parse an OVF XML file. This is all done
416 * in the constructor; if there is any kind of error in the file -- filesystem error
417 * from IPRT, XML parsing errors from libxml, or OVF logical errors --, exceptions
418 * are thrown. These are all based on xml::Error.
419 *
420 * Hence, use this class as follows:
421<code>
422 OVFReader *pReader = NULL;
423 try
424 {
425 pReader = new("/path/to/file.ovf");
426 }
427 catch (xml::Error &e)
428 {
429 printf("A terrible thing happened: %s", e.what());
430 }
431 // now go look at pReader->m_llVirtualSystem and what's in there
432 if (pReader)
433 delete pReader;
434</code>
435 */
436
437class OVFReader
438{
439public:
440 OVFReader(const void *pvBuf, size_t cbSize, const RTCString &path);
441 OVFReader(const RTCString &path);
442
443 // Data fields
444 EnvelopeData m_envelopeData; //data of root element "Envelope"
445 RTCString m_strPath; // file name given to constructor
446 DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId
447 std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read()
448
449private:
450 xml::Document m_doc;
451
452 void parse();
453 void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem);
454 void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem);
455 void HandleNetworkSection(const xml::ElementNode *pSectionElem);
456 void HandleVirtualSystemContent(const xml::ElementNode *pContentElem);
457};
458
459////////////////////////////////////////////////////////////////////////////////
460//
461// Errors
462//
463////////////////////////////////////////////////////////////////////////////////
464
465/**
466 * Thrown by OVFReader for any kind of error that is not an XML error but
467 * still makes the OVF impossible to parse. Based on xml::LogicError so
468 * that one catch() for all xml::LogicError can handle all possible errors.
469 */
470
471class OVFLogicError : public xml::LogicError
472{
473public:
474 OVFLogicError(const char *aFormat, ...);
475};
476
477} // end namespace ovf
478
479#endif // ____H_OVFREADER
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette