VirtualBox

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

最後變更 在這個檔案從28205是 28165,由 vboxsync 提交於 15 年 前

Main/OVF: import vbox:machine with disks, the rest. Todo some bugfixing.

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

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