VirtualBox

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

Last change on this file since 29945 was 29925, checked in by vboxsync, 15 years ago

OVF: respect override of import parameters (setFinalValues) also when vbox:Machine is present, first batch (everything except storage)

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

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