VirtualBox

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

Last change on this file since 75267 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

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