VirtualBox

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

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

Main/OVF: add c++ ovf namespace

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.8 KB
Line 
1/* $Id: ovfreader.h 27908 2010-03-31 14:32:46Z 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.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 * 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 iprt::MiniString strDiskId; // value from DiskSection/Disk/@diskId
155 int64_t iCapacity; // value from DiskSection/Disk/@capacity;
156 // (maximum size for dynamic images, I guess; we always translate this to bytes)
157 int64_t iPopulatedSize; // optional value from DiskSection/Disk/@populatedSize
158 // (actual used size of disk, always in bytes; can be an estimate of used disk
159 // space, but cannot be larger than iCapacity; -1 if not set)
160 iprt::MiniString strFormat; // value from DiskSection/Disk/@format
161 // typically http://www.vmware.com/specifications/vmdk.html#sparse
162
163 // fields from /References/File; the spec says the file reference from disk can be empty,
164 // so in that case, strFilename will be empty, then a new disk should be created
165 iprt::MiniString strHref; // value from /References/File/@href (filename); if empty, then the remaining fields are ignored
166 int64_t iSize; // value from /References/File/@size (optional according to spec; then we set -1 here)
167 int64_t iChunkSize; // value from /References/File/@chunkSize (optional, unsupported)
168 iprt::MiniString strCompression; // value from /References/File/@compression (optional, can be "gzip" according to spec)
169};
170
171enum ResourceType_T
172{ ResourceType_Other = 1,
173 ResourceType_ComputerSystem = 2,
174 ResourceType_Processor = 3,
175 ResourceType_Memory = 4,
176 ResourceType_IDEController = 5,
177 ResourceType_ParallelSCSIHBA = 6,
178 ResourceType_FCHBA = 7,
179 ResourceType_iSCSIHBA = 8,
180 ResourceType_IBHCA = 9,
181 ResourceType_EthernetAdapter = 10,
182 ResourceType_OtherNetworkAdapter = 11,
183 ResourceType_IOSlot = 12,
184 ResourceType_IODevice = 13,
185 ResourceType_FloppyDrive = 14,
186 ResourceType_CDDrive = 15,
187 ResourceType_DVDDrive = 16,
188 ResourceType_HardDisk = 17,
189 ResourceType_OtherStorageDevice = 20,
190 ResourceType_USBController = 23,
191 ResourceType_SoundCard = 35
192};
193
194struct VirtualHardwareItem
195{
196 iprt::MiniString strDescription;
197 iprt::MiniString strCaption;
198 iprt::MiniString strElementName;
199
200 uint32_t ulInstanceID;
201 uint32_t ulParent;
202
203 ResourceType_T resourceType;
204 iprt::MiniString strOtherResourceType;
205 iprt::MiniString strResourceSubType;
206
207 iprt::MiniString strHostResource; // "Abstractly specifies how a device shall connect to a resource on the deployment platform.
208 // Not all devices need a backing." Used with disk items, for which this references a virtual
209 // disk from the Disks section.
210 bool fAutomaticAllocation;
211 bool fAutomaticDeallocation;
212 iprt::MiniString strConnection; // "All Ethernet adapters that specify the same abstract network connection name within an OVF
213 // package shall be deployed on the same network. The abstract network connection name shall be
214 // listed in the NetworkSection at the outermost envelope level." We ignore this and only set up
215 // a network adapter depending on the network name.
216 iprt::MiniString strAddress; // "Device-specific. For an Ethernet adapter, this specifies the MAC address."
217 iprt::MiniString strAddressOnParent; // "For a device, this specifies its location on the controller."
218 iprt::MiniString strAllocationUnits; // "Specifies the units of allocation used. For example, “byte * 2^20”."
219 uint64_t ullVirtualQuantity; // "Specifies the quantity of resources presented. For example, “256”."
220 uint64_t ullReservation; // "Specifies the minimum quantity of resources guaranteed to be available."
221 uint64_t ullLimit; // "Specifies the maximum quantity of resources that will be granted."
222 uint64_t ullWeight; // "Specifies a relative priority for this allocation in relation to other allocations."
223
224 iprt::MiniString strConsumerVisibility;
225 iprt::MiniString strMappingBehavior;
226 iprt::MiniString strPoolID;
227 uint32_t ulBusNumber; // seen with IDE controllers, but not listed in OVF spec
228
229 uint32_t ulLineNumber; // line number of <Item> element in XML source; cached for error messages
230
231 VirtualHardwareItem()
232 : ulInstanceID(0), fAutomaticAllocation(false), fAutomaticDeallocation(false), ullVirtualQuantity(0), ullReservation(0), ullLimit(0), ullWeight(0), ulBusNumber(0), ulLineNumber(0)
233 {};
234};
235
236typedef std::map<iprt::MiniString, DiskImage> DiskImagesMap;
237
238struct VirtualSystem;
239
240typedef std::map<uint32_t, VirtualHardwareItem> HardwareItemsMap;
241
242struct HardDiskController
243{
244 uint32_t idController; // instance ID (Item/InstanceId); this gets referenced from HardDisk
245 enum ControllerSystemType { IDE, SATA, SCSI };
246 ControllerSystemType system; // one of IDE, SATA, SCSI
247 iprt::MiniString strControllerType; // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
248 iprt::MiniString strAddress; // for IDE
249 uint32_t ulBusNumber; // for IDE
250
251 HardDiskController()
252 : idController(0),
253 ulBusNumber(0)
254 {
255 }
256};
257
258typedef std::map<uint32_t, HardDiskController> ControllersMap;
259
260struct VirtualDisk
261{
262 uint32_t idController; // SCSI (or IDE) controller this disk is connected to;
263 // points into VirtualSystem.mapControllers
264 uint32_t ulAddressOnParent; // parsed strAddressOnParent of hardware item; will be 0 or 1 for IDE
265 // and possibly higher for disks attached to SCSI controllers (untested)
266 iprt::MiniString strDiskId; // if the hard disk has an ovf:/disk/<id> reference,
267 // this receives the <id> component; points to one of the
268 // references in Appliance::Data.mapDisks
269};
270
271typedef std::map<iprt::MiniString, VirtualDisk> VirtualDisksMap;
272
273/**
274 * A list of EthernetAdapters is contained in VirtualSystem, representing the
275 * ethernet adapters in the virtual system.
276 */
277struct EthernetAdapter
278{
279 iprt::MiniString strAdapterType; // "PCNet32" or "E1000" or whatever; from <rasd:ResourceSubType>
280 iprt::MiniString strNetworkName; // from <rasd:Connection>
281};
282
283typedef std::list<EthernetAdapter> EthernetAdaptersList;
284
285/**
286 * A list of VirtualSystem structs is created by OVFReader::read(). Each refers to
287 * a <VirtualSystem> block in the OVF file.
288 */
289struct VirtualSystem
290{
291 iprt::MiniString strName; // copy of VirtualSystem/@id
292
293 iprt::MiniString strDescription; // copy of VirtualSystem/Info content
294
295 CIMOSType_T cimos;
296 iprt::MiniString strCimosDesc; // readable description of the cimos type in the case of cimos = 0/1/102
297 iprt::MiniString strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
298 // VMware Workstation 6.5 is "vmx-07"
299
300 HardwareItemsMap mapHardwareItems; // map of virtual hardware items, sorted by unique instance ID
301
302 uint64_t ullMemorySize; // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
303 uint16_t cCPUs; // no. of CPUs, copied from llHardwareItems; default = 1
304
305 EthernetAdaptersList llEthernetAdapters; // (one for each VirtualSystem/Item[@ResourceType=10]element)
306
307 ControllersMap mapControllers;
308 // list of hard disk controllers
309 // (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
310
311 VirtualDisksMap mapVirtualDisks;
312 // (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
313
314 bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
315 bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
316 bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
317
318 iprt::MiniString strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
319 // VMware Workstation 6.5 uses "ensoniq1371" for example
320
321 iprt::MiniString strLicenseText; // license info if any; receives contents of VirtualSystem/EulaSection/License
322
323 iprt::MiniString strProduct; // product info if any; receives contents of VirtualSystem/ProductSection/Product
324 iprt::MiniString strVendor; // product info if any; receives contents of VirtualSystem/ProductSection/Vendor
325 iprt::MiniString strVersion; // product info if any; receives contents of VirtualSystem/ProductSection/Version
326 iprt::MiniString strProductUrl; // product info if any; receives contents of VirtualSystem/ProductSection/ProductUrl
327 iprt::MiniString strVendorUrl; // product info if any; receives contents of VirtualSystem/ProductSection/VendorUrl
328
329 VirtualSystem()
330 : ullMemorySize(0), cCPUs(1), fHasFloppyDrive(false), fHasCdromDrive(false), fHasUsbController(false)
331 {
332 }
333};
334
335////////////////////////////////////////////////////////////////////////////////
336//
337// Class OVFReader
338//
339////////////////////////////////////////////////////////////////////////////////
340
341/**
342 * OVFReader attempts to open, read in and parse an OVF XML file. This is all done
343 * in the constructor; if there is any kind of error in the file -- filesystem error
344 * from IPRT, XML parsing errors from libxml, or OVF logical errors --, exceptions
345 * are thrown. These are all based on xml::Error.
346 *
347 * Hence, use this class as follows:
348<code>
349 OVFReader *pReader = NULL;
350 try
351 {
352 pReader = new("/path/to/file.ovf");
353 }
354 catch (xml::Error &e)
355 {
356 printf("A terrible thing happened: %s", e.what());
357 }
358 // now go look at pReader->m_llVirtualSystem and what's in there
359 if (pReader)
360 delete pReader;
361</code>
362 */
363
364class OVFReader
365{
366public:
367 OVFReader(const iprt::MiniString &path);
368 ~OVFReader();
369
370 void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem);
371 void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem);
372 void HandleNetworkSection(const xml::ElementNode *pSectionElem);
373 void HandleVirtualSystemContent(const xml::ElementNode *pContentElem);
374
375 // Data fields
376 iprt::MiniString m_strPath; // file name given to constructor
377 DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId
378 std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read()
379};
380
381////////////////////////////////////////////////////////////////////////////////
382//
383// Errors
384//
385////////////////////////////////////////////////////////////////////////////////
386
387/**
388 * Thrown by OVFReader for any kind of error that is not an XML error but
389 * still makes the OVF impossible to parse. Based on xml::LogicError so
390 * that one catch() for all xml::LogicError can handle all possible errors.
391 */
392
393class OVFLogicError : public xml::LogicError
394{
395public:
396 OVFLogicError(const char *aFormat, ...);
397};
398
399} // end namespace ovf
400
401#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