VirtualBox

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

Last change on this file was 103288, checked in by vboxsync, 3 months ago

Main/ovfreader: Introduce ResourceType_Invalid for 0 and check against it instead of 0, bugref:3409

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

© 2023 Oracle
ContactPrivacy policyTerms of Use