VirtualBox

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

Last change on this file since 106515 was 106515, checked in by vboxsync, 7 weeks ago

Main/ovfreader.h: Tried to fix botched copy constructor suppression in HardwareItemVector only to find that it is required for a default (empty) VirtualSystem() instance that gets push_back() onto some list. So, added a restricted copy constructor that asserts if the list isn't empty. Untested! jiraref:VBP-1171

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.0 KB
Line 
1/* $Id: ovfreader.h 106515 2024-10-20 02:00:07Z 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-2024 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 /* We only support copying if the vector is empty, we'd need something like
563 shared_ptr for dealing with a populated list. (Problem found by VS 2022.) */
564 HardwareItemVector(const HardwareItemVector &a_rThat)
565 : std::vector<VirtualHardwareItem *>()
566 {
567 Assert(a_rThat.begin() == a_rThat.end());
568 }
569
570private:
571#if RT_CPLUSPLUS_PREREQ(201100) /* VC2022: No copy assignment operator (see copy constructor). */
572 HardwareItemVector &operator=(const HardwareItemVector &) = delete;
573#else
574 HardwareItemVector &operator=(const HardwareItemVector &);
575#endif
576};
577
578struct HardDiskController
579{
580 RTCString strIdController; // instance ID (Item/InstanceId); this gets referenced from VirtualDisk
581
582 enum ControllerSystemType { IDE, SATA, SCSI, VIRTIOSCSI, NVMe };
583 ControllerSystemType system; // one of IDE, SATA, SCSI, VIRTIOSCSI, NVMe
584
585 RTCString strControllerType;
586 // controller subtype (Item/ResourceSubType); e.g. "LsiLogic"; can be empty (esp. for IDE)
587 // note that we treat LsiLogicSAS as a SCSI controller (system == SCSI) even though VirtualBox
588 // treats it as a fourth class besides IDE, SATA, SCSI
589
590 int32_t lAddress; // value from OVF "Address" element
591 bool fPrimary; // controller index; this is determined heuristically by the OVF reader and will
592 // be true for the first controller of this type (e.g. IDE primary ctler) or
593 // false for the next (e.g. IDE secondary ctler)
594
595 HardDiskController()
596 : lAddress(0),
597 fPrimary(true)
598 { }
599};
600
601typedef std::map<RTCString, HardDiskController> ControllersMap;
602
603struct VirtualDisk
604{
605 RTCString strIdController; // SCSI (or IDE) controller this disk is connected to;
606 // this must match HardDiskController.strIdController and
607 // points into VirtualSystem.mapControllers
608 uint32_t ulAddressOnParent; // parsed strAddressOnParent of hardware item; will be 0 or 1 for IDE
609 // and possibly higher for disks attached to SCSI controllers (untested)
610 RTCString strDiskId; // if the hard disk has an ovf:/disk/<id> reference,
611 // this receives the <id> component; points to one of the
612 // references in Appliance::Data.mapDisks
613 bool fEmpty; //true - empty disk, e.g. the component <rasd:HostResource>...</rasd:HostResource> is absent.
614};
615
616typedef std::map<RTCString, VirtualDisk> VirtualDisksMap;
617
618/**
619 * A list of EthernetAdapters is contained in VirtualSystem, representing the
620 * ethernet adapters in the virtual system.
621 */
622struct EthernetAdapter
623{
624 RTCString strAdapterType; // "PCNet32" or "E1000" or whatever; from <rasd:ResourceSubType>
625 RTCString strNetworkName; // from <rasd:Connection>
626};
627
628typedef std::list<EthernetAdapter> EthernetAdaptersList;
629
630/**
631 * A list of VirtualSystem structs is created by OVFReader::read(). Each refers to
632 * a \<VirtualSystem\> block in the OVF file.
633 */
634struct VirtualSystem
635{
636 RTCString strName; // copy of VirtualSystem/@id
637
638 RTCString strDescription; // copy of VirtualSystem/AnnotationSection content, if any
639
640 CIMOSType_T cimos;
641 RTCString strCimosDesc; // readable description of the cimos type in the case of cimos = 0/1/102
642 RTCString strTypeVBox; // optional type from @vbox:ostype attribute (VirtualBox 4.0 or higher)
643
644 RTCString strVirtualSystemType; // generic hardware description; OVF says this can be something like "vmx-4" or "xen";
645 // VMware Workstation 6.5 is "vmx-07"
646
647 HardwareItemVector vecHardwareItems; //< vector containing all virtual hardware items in parsing order.
648
649 uint64_t ullMemorySize; // always in bytes, copied from llHardwareItems; default = 0 (unspecified)
650 uint16_t cCPUs; // no. of CPUs, copied from llHardwareItems; default = 1
651
652 EthernetAdaptersList llEthernetAdapters; // (one for each VirtualSystem/Item[@ResourceType=10]element)
653
654 ControllersMap mapControllers;
655 // list of hard disk controllers
656 // (one for each VirtualSystem/Item[@ResourceType=6] element with accumulated data from children)
657
658 VirtualDisksMap mapVirtualDisks;
659 // (one for each VirtualSystem/Item[@ResourceType=17] element with accumulated data from children)
660
661 bool fHasFloppyDrive; // true if there's a floppy item in mapHardwareItems
662 bool fHasCdromDrive; // true if there's a CD-ROM item in mapHardwareItems; ISO images are not yet supported by OVFtool
663 bool fHasUsbController; // true if there's a USB controller item in mapHardwareItems
664
665 RTCString strSoundCardType; // if not empty, then the system wants a soundcard; this then specifies the hardware;
666 // VMware Workstation 6.5 uses "ensoniq1371" for example
667
668 RTCString strLicenseText; // license info if any; receives contents of VirtualSystem/EulaSection/License
669
670 RTCString strProduct; // product info if any; receives contents of VirtualSystem/ProductSection/Product
671 RTCString strVendor; // product info if any; receives contents of VirtualSystem/ProductSection/Vendor
672 RTCString strVersion; // product info if any; receives contents of VirtualSystem/ProductSection/Version
673 RTCString strProductUrl; // product info if any; receives contents of VirtualSystem/ProductSection/ProductUrl
674 RTCString strVendorUrl; // product info if any; receives contents of VirtualSystem/ProductSection/VendorUrl
675
676 const xml::ElementNode *pelmVBoxMachine; // pointer to <vbox:Machine> element under <VirtualSystem> element or NULL if not present
677
678 VirtualSystem()
679 : cimos(CIMOSType_CIMOS_Unknown)
680 , ullMemorySize(0)
681 , cCPUs(1)
682 , fHasFloppyDrive(false)
683 , fHasCdromDrive(false)
684 , fHasUsbController(false)
685 , pelmVBoxMachine(NULL)
686 {
687 }
688
689#if RT_CPLUSPLUS_PREREQ(201100) /* VC2022: Excplit default copy constructor and copy assignment operator to avoid warnings. */
690 /* Note! HardwareItemVector only allow copying if it's empty. */
691 VirtualSystem(VirtualSystem const &) = default;
692 VirtualSystem &operator=(VirtualSystem const &) = delete;
693#endif
694};
695
696////////////////////////////////////////////////////////////////////////////////
697//
698// Class OVFReader
699//
700////////////////////////////////////////////////////////////////////////////////
701
702/**
703 * OVFReader attempts to open, read in and parse an OVF XML file. This is all done
704 * in the constructor; if there is any kind of error in the file -- filesystem error
705 * from IPRT, XML parsing errors from libxml, or OVF logical errors --, exceptions
706 * are thrown. These are all based on xml::Error.
707 *
708 * Hence, use this class as follows:
709<code>
710 OVFReader *pReader = NULL;
711 try
712 {
713 pReader = new("/path/to/file.ovf");
714 }
715 catch (xml::Error &e)
716 {
717 printf("A terrible thing happened: %s", e.what());
718 }
719 // now go look at pReader->m_llVirtualSystem and what's in there
720 if (pReader)
721 delete pReader;
722</code>
723 */
724class OVFReader
725{
726public:
727 OVFReader();
728 OVFReader(const void *pvBuf, size_t cbSize, const RTCString &path);
729 OVFReader(const RTCString &path);
730
731 // Data fields
732 EnvelopeData m_envelopeData; //data of root element "Envelope"
733 RTCString m_strPath; // file name given to constructor
734 DiskImagesMap m_mapDisks; // map of DiskImage structs, sorted by DiskImage.strDiskId
735 std::list<VirtualSystem> m_llVirtualSystems; // list of virtual systems, created by and valid after read()
736
737private:
738 xml::Document m_doc;
739
740 void parse();
741 void LoopThruSections(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pCurElem);
742 void HandleDiskSection(const xml::ElementNode *pReferencesElem, const xml::ElementNode *pSectionElem);
743 void HandleNetworkSection(const xml::ElementNode *pSectionElem);
744 void HandleVirtualSystemContent(const xml::ElementNode *pContentElem);
745};
746
747} // end namespace ovf
748
749#endif /* !MAIN_INCLUDED_ovfreader_h */
750
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