VirtualBox

source: vbox/trunk/src/VBox/Main/xml/ovfreader.cpp@ 103288

Last change on this file since 103288 was 103288, checked in by vboxsync, 8 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: 50.5 KB
RevLine 
[16205]1/* $Id: ovfreader.cpp 103288 2024-02-09 10:55:37Z vboxsync $ */
2/** @file
[36527]3 * OVF reader declarations.
[16205]4 *
[36527]5 * Depends only on IPRT, including the RTCString and IPRT XML classes.
[16205]6 */
7
8/*
[98103]9 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
[16205]10 *
[96407]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
[16205]28 */
29
[68917]30#define LOG_GROUP LOG_GROUP_MAIN_APPLIANCE
[21588]31#include "ovfreader.h"
[68917]32#include <VBox/log.h>
33#include <vector>
[20081]34
[16205]35using namespace std;
[27908]36using namespace ovf;
[16205]37
[68917]38
39
[16205]40////////////////////////////////////////////////////////////////////////////////
[17417]41//
[33540]42// OVF reader implementation
[17417]43//
44////////////////////////////////////////////////////////////////////////////////
[16205]45
[27918]46/**
[78602]47 * Default Constructor.
48 * Should be used if you don't have an OVF file, but want to fill the data
49 * m_mapDisks, m_llVirtualSystems manually
50 */
[78604]51OVFReader::OVFReader()
[78602]52{
53}
54
55/**
[32565]56 * Constructor. This parses the given XML file out of the memory. Throws lots of exceptions
57 * on XML or OVF invalidity.
58 * @param pvBuf the memory buffer to parse
59 * @param cbSize the size of the memory buffer
60 * @param path path to a filename for error messages.
61 */
[36527]62OVFReader::OVFReader(const void *pvBuf, size_t cbSize, const RTCString &path)
[32565]63 : m_strPath(path)
64{
65 xml::XmlMemParser parser;
66 parser.read(pvBuf, cbSize,
67 m_strPath,
68 m_doc);
69 /* Start the parsing */
70 parse();
71}
72
73/**
[27918]74 * Constructor. This opens the given XML file and parses it. Throws lots of exceptions
75 * on XML or OVF invalidity.
76 * @param path
77 */
[36527]78OVFReader::OVFReader(const RTCString &path)
[21588]79 : m_strPath(path)
[16205]80{
[21588]81 xml::XmlFileParser parser;
[22173]82 parser.read(m_strPath,
[27918]83 m_doc);
[32565]84 /* Start the parsing */
85 parse();
86}
[16205]87
[32565]88void OVFReader::parse()
89{
[27918]90 const xml::ElementNode *pRootElem = m_doc.getRootElement();
[45227]91 const xml::AttributeNode *pTypeAttr;
92 const char *pcszTypeAttr = "";
[46169]93 RTCString pcszNamespaceURI;
[45227]94
[46169]95 if (!pRootElem || strcmp(pRootElem->getName(), "Envelope"))
[90438]96 throw OVFLogicError(N_("Root element in OVF file must be 'Envelope'."));
[16205]97
[46169]98 pcszNamespaceURI = pRootElem->getNamespaceURI();
[90438]99 if (pcszNamespaceURI.isEmpty())
[45227]100 {
[46169]101 throw OVFLogicError(N_("Error reading namespace URI in 'Envelope' element, line %d"), pRootElem->getLineNumber());
[45227]102 }
[46169]103
104 if (strncmp(ovf::OVF20_URI_string, pcszNamespaceURI.c_str(), pcszNamespaceURI.length()) == 0)
105 {
106 m_envelopeData.setOVFVersion(ovf::OVFVersion_2_0);
107 }
108 else if (strncmp(OVF10_URI_string, pcszNamespaceURI.c_str(), pcszNamespaceURI.length()) == 0)
109 {
110 m_envelopeData.setOVFVersion(ovf::OVFVersion_1_0);
111 }
[45227]112 else
113 {
[46169]114 m_envelopeData.setOVFVersion(ovf::OVFVersion_0_9);
115 }
116
[49028]117 if ((pTypeAttr = pRootElem->findAttribute("lang", "xml")))
[45227]118 {
[79677]119 pcszTypeAttr = pTypeAttr->getValueN(RT_XML_ATTR_TINY);
[45227]120 m_envelopeData.lang = pcszTypeAttr;
121 }
122
[21588]123 // OVF has the following rough layout:
124 /*
125 -- <References> .... files referenced from other parts of the file, such as VMDK images
126 -- Metadata, comprised of several section commands
127 -- virtual machines, either a single <VirtualSystem>, or a <VirtualSystemCollection>
128 -- optionally <Strings> for localization
129 */
[16205]130
[21588]131 // get all "File" child elements of "References" section so we can look up files easily;
132 // first find the "References" sections so we can look up files
133 xml::ElementNodesList listFileElements; // receives all /Envelope/References/File nodes
134 const xml::ElementNode *pReferencesElem;
135 if ((pReferencesElem = pRootElem->findChildElement("References")))
136 pReferencesElem->getChildElements(listFileElements, "File");
[16205]137
[21588]138 // now go though the sections
139 LoopThruSections(pReferencesElem, pRootElem);
[17580]140}
141
142/**
[16205]143 * Private helper method that goes thru the elements of the given "current" element in the OVF XML
144 * and handles the contained child elements (which can be "Section" or "Content" elements).
145 *
[65088]146 * @param pReferencesElem "References" element from OVF, for looking up file specifications;
147 * can be NULL if no such element is present.
[16205]148 * @param pCurElem Element whose children are to be analyzed here.
149 */
[21588]150void OVFReader::LoopThruSections(const xml::ElementNode *pReferencesElem,
151 const xml::ElementNode *pCurElem)
[16205]152{
153 xml::NodesLoop loopChildren(*pCurElem);
[17573]154 const xml::ElementNode *pElem;
[16205]155 while ((pElem = loopChildren.forAllNodes()))
156 {
157 const char *pcszElemName = pElem->getName();
[49029]158 const xml::AttributeNode *pTypeAttr = pElem->findAttribute("type");
[79677]159 const char *pcszTypeAttr = pTypeAttr ? pTypeAttr->getValueN(RT_XML_ATTR_TINY) : "";
[16205]160
[49029]161 if ( !strcmp(pcszElemName, "DiskSection")
162 || ( !strcmp(pcszElemName, "Section")
163 && !strcmp(pcszTypeAttr, "ovf:DiskSection_Type")
[16205]164 )
165 )
166 {
[21588]167 HandleDiskSection(pReferencesElem, pElem);
[16205]168 }
[49029]169 else if ( !strcmp(pcszElemName, "NetworkSection")
170 || ( !strcmp(pcszElemName, "Section")
171 && !strcmp(pcszTypeAttr, "ovf:NetworkSection_Type")
[16205]172 )
173 )
174 {
[21588]175 HandleNetworkSection(pElem);
[16205]176 }
[49029]177 else if ( !strcmp(pcszElemName, "DeploymentOptionSection"))
[16205]178 {
[63563]179 /// @todo
[16205]180 }
[49029]181 else if ( !strcmp(pcszElemName, "Info"))
[16205]182 {
183 // child of VirtualSystemCollection -- TODO
184 }
[49029]185 else if ( !strcmp(pcszElemName, "ResourceAllocationSection"))
[16205]186 {
187 // child of VirtualSystemCollection -- TODO
188 }
[49029]189 else if ( !strcmp(pcszElemName, "StartupSection"))
[16205]190 {
191 // child of VirtualSystemCollection -- TODO
192 }
[49029]193 else if ( !strcmp(pcszElemName, "VirtualSystem")
194 || ( !strcmp(pcszElemName, "Content")
195 && !strcmp(pcszTypeAttr, "ovf:VirtualSystem_Type")
[16205]196 )
197 )
198 {
[21588]199 HandleVirtualSystemContent(pElem);
[16205]200 }
[49029]201 else if ( !strcmp(pcszElemName, "VirtualSystemCollection")
202 || ( !strcmp(pcszElemName, "Content")
203 && !strcmp(pcszTypeAttr, "ovf:VirtualSystemCollection_Type")
[16205]204 )
205 )
206 {
[63563]207 /// @todo ResourceAllocationSection
[16205]208
209 // recurse for this, since it has VirtualSystem elements as children
[21588]210 LoopThruSections(pReferencesElem, pElem);
[16205]211 }
212 }
213}
214
215/**
216 * Private helper method that handles disk sections in the OVF XML.
[58132]217 *
[17099]218 * Gets called indirectly from IAppliance::read().
219 *
[58132]220 * @param pReferencesElem "References" element from OVF, for looking up file
221 * specifications; can be NULL if no such element is
222 * present.
223 * @param pSectionElem Section element for which this helper is getting called.
[16205]224 */
[21588]225void OVFReader::HandleDiskSection(const xml::ElementNode *pReferencesElem,
226 const xml::ElementNode *pSectionElem)
[16205]227{
228 // contains "Disk" child elements
229 xml::NodesLoop loopDisks(*pSectionElem, "Disk");
[17573]230 const xml::ElementNode *pelmDisk;
[16205]231 while ((pelmDisk = loopDisks.forAllNodes()))
232 {
233 DiskImage d;
234 const char *pcszBad = NULL;
[19519]235 const char *pcszDiskId;
236 const char *pcszFormat;
[79677]237 if (!pelmDisk->getAttributeValueN("diskId", pcszDiskId, RT_XML_ATTR_TINY))
[16205]238 pcszBad = "diskId";
[79677]239 else if (!pelmDisk->getAttributeValueN("format", pcszFormat, RT_XML_ATTR_SMALL))
[16205]240 pcszBad = "format";
[49029]241 else if (!pelmDisk->getAttributeValue("capacity", d.iCapacity))
[16205]242 pcszBad = "capacity";
243 else
244 {
[19519]245 d.strDiskId = pcszDiskId;
246 d.strFormat = pcszFormat;
247
[49029]248 if (!pelmDisk->getAttributeValue("populatedSize", d.iPopulatedSize))
[16205]249 // optional
250 d.iPopulatedSize = -1;
251
[28165]252 // optional vbox:uuid attribute (if OVF was exported by VirtualBox != 3.2)
[79677]253 pelmDisk->getAttributeValueN("uuid", d.uuidVBox, RT_XML_ATTR_TINY, "vbox");
[28165]254
[19519]255 const char *pcszFileRef;
[79677]256 if (pelmDisk->getAttributeValueN("fileRef", pcszFileRef, RT_XML_ATTR_SMALL)) // optional
[16205]257 {
258 // look up corresponding /References/File nodes (list built above)
[17573]259 const xml::ElementNode *pFileElem;
[16205]260 if ( pReferencesElem
[49029]261 && (pFileElem = pReferencesElem->findChildElementFromId(pcszFileRef)) != NULL
[16208]262 )
[16205]263 {
[46518]264
[16205]265 // copy remaining values from file node then
266 const char *pcszBadInFile = NULL;
[19519]267 const char *pcszHref;
[79677]268 if (!pFileElem->getAttributeValueN("href", pcszHref, RT_XML_ATTR_SMALL))
[16205]269 pcszBadInFile = "href";
[49029]270 else if (!pFileElem->getAttributeValue("size", d.iSize))
[16205]271 d.iSize = -1; // optional
[19519]272
273 d.strHref = pcszHref;
274
[16205]275 // if (!(pFileElem->getAttributeValue("size", d.iChunkSize))) TODO
276 d.iChunkSize = -1; // optional
[19519]277 const char *pcszCompression;
[79677]278 if (pFileElem->getAttributeValueN("compression", pcszCompression, RT_XML_ATTR_TINY))
[19519]279 d.strCompression = pcszCompression;
[16205]280
281 if (pcszBadInFile)
[21588]282 throw OVFLogicError(N_("Error reading \"%s\": missing or invalid attribute '%s' in 'File' element, line %d"),
283 m_strPath.c_str(),
284 pcszBadInFile,
285 pFileElem->getLineNumber());
[16205]286 }
287 else
[90438]288 throw OVFLogicError(N_("Error reading \"%s\": cannot find References/File element for ID \"%s\" referenced by 'Disk' element, line %d"),
[21588]289 m_strPath.c_str(),
290 pcszFileRef,
291 pelmDisk->getLineNumber());
[16205]292 }
293 }
294
295 if (pcszBad)
[21588]296 throw OVFLogicError(N_("Error reading \"%s\": missing or invalid attribute '%s' in 'DiskSection' element, line %d"),
297 m_strPath.c_str(),
298 pcszBad,
299 pelmDisk->getLineNumber());
[16205]300
[28165]301 // suggest a size in megabytes to help callers with progress reports
302 d.ulSuggestedSizeMB = 0;
303 if (d.iCapacity != -1)
[47924]304 d.ulSuggestedSizeMB = (uint32_t)(d.iCapacity / _1M);
[28165]305 else if (d.iPopulatedSize != -1)
[47924]306 d.ulSuggestedSizeMB = (uint32_t)(d.iPopulatedSize / _1M);
[28165]307 else if (d.iSize != -1)
[47924]308 d.ulSuggestedSizeMB = (uint32_t)(d.iSize / _1M);
[28165]309 if (d.ulSuggestedSizeMB == 0)
310 d.ulSuggestedSizeMB = 10000; // assume 10 GB, this is for the progress bar only anyway
311
[21588]312 m_mapDisks[d.strDiskId] = d;
[16205]313 }
314}
315
316/**
317 * Private helper method that handles network sections in the OVF XML.
[17099]318 * Gets called indirectly from IAppliance::read().
[16205]319 */
[21588]320void OVFReader::HandleNetworkSection(const xml::ElementNode * /* pSectionElem */)
[16205]321{
[17566]322 // we ignore network sections for now
[16205]323
[17566]324// xml::NodesLoop loopNetworks(*pSectionElem, "Network");
325// const xml::Node *pelmNetwork;
326// while ((pelmNetwork = loopNetworks.forAllNodes()))
327// {
328// Network n;
329// if (!(pelmNetwork->getAttributeValue("name", n.strNetworkName)))
330// return setError(VBOX_E_FILE_ERROR,
331// tr("Error reading \"%s\": missing 'name' attribute in 'Network', line %d"),
332// pcszPath,
333// pelmNetwork->getLineNumber());
334//
335// m->mapNetworks[n.strNetworkName] = n;
336// }
[16205]337}
338
339/**
340 * Private helper method that handles a "VirtualSystem" element in the OVF XML.
[17099]341 * Gets called indirectly from IAppliance::read().
[16205]342 *
[65088]343 * @param pelmVirtualSystem
[16205]344 */
[21588]345void OVFReader::HandleVirtualSystemContent(const xml::ElementNode *pelmVirtualSystem)
[16205]346{
[68917]347 /* Create a new virtual system and work directly on the list copy. */
348 m_llVirtualSystems.push_back(VirtualSystem());
349 VirtualSystem &vsys = m_llVirtualSystems.back();
[16205]350
[27918]351 // peek under the <VirtualSystem> node whether we have a <vbox:Machine> node;
352 // that case case, the caller can completely ignore the OVF but only load the VBox machine XML
[50196]353 vsys.pelmVBoxMachine = pelmVirtualSystem->findChildElementNS("vbox", "Machine");
[27918]354
355 // now look for real OVF
[17573]356 const xml::AttributeNode *pIdAttr = pelmVirtualSystem->findAttribute("id");
[16210]357 if (pIdAttr)
[79677]358 vsys.strName = pIdAttr->getValueN(RT_XML_ATTR_SMALL);
[16210]359
[16205]360 xml::NodesLoop loop(*pelmVirtualSystem); // all child elements
[17573]361 const xml::ElementNode *pelmThis;
[16205]362 while ((pelmThis = loop.forAllNodes()))
363 {
364 const char *pcszElemName = pelmThis->getName();
[29893]365 const char *pcszTypeAttr = "";
366 if (!strcmp(pcszElemName, "Section")) // OVF 0.9 used "Section" element always with a varying "type" attribute
367 {
[49029]368 const xml::AttributeNode *pTypeAttr = pelmThis->findAttribute("type");
[50148]369 if (pTypeAttr)
[79677]370 pcszTypeAttr = pTypeAttr->getValueN(RT_XML_ATTR_TINY);
[29893]371 else
[90438]372 throw OVFLogicError(N_("Error reading \"%s\": element 'Section' has no 'type' attribute, line %d"),
[29893]373 m_strPath.c_str(),
374 pelmThis->getLineNumber());
375 }
[16205]376
[49029]377 if ( !strcmp(pcszElemName, "EulaSection")
378 || !strcmp(pcszTypeAttr, "ovf:EulaSection_Type")
[18220]379 )
[16205]380 {
[16208]381 /* <EulaSection>
382 <Info ovf:msgid="6">License agreement for the Virtual System.</Info>
383 <License ovf:msgid="1">License terms can go in here.</License>
384 </EulaSection> */
385
[18376]386 const xml::ElementNode *pelmLicense;
387 if ((pelmLicense = pelmThis->findChildElement("License")))
[79677]388 vsys.strLicenseText = pelmLicense->getValueN(RT_XML_CONTENT_LARGE);
[16205]389 }
[49029]390 if ( !strcmp(pcszElemName, "ProductSection")
391 || !strcmp(pcszTypeAttr, "ovf:ProductSection_Type")
[18376]392 )
393 {
394 /* <Section ovf:required="false" xsi:type="ovf:ProductSection_Type">
395 <Info>Meta-information about the installed software</Info>
396 <Product>VAtest</Product>
397 <Vendor>SUN Microsystems</Vendor>
398 <Version>10.0</Version>
399 <ProductUrl>http://blogs.sun.com/VirtualGuru</ProductUrl>
400 <VendorUrl>http://www.sun.com</VendorUrl>
401 </Section> */
402 const xml::ElementNode *pelmProduct;
403 if ((pelmProduct = pelmThis->findChildElement("Product")))
[79677]404 vsys.strProduct = pelmProduct->getValueN(RT_XML_CONTENT_SMALL);
[18376]405 const xml::ElementNode *pelmVendor;
406 if ((pelmVendor = pelmThis->findChildElement("Vendor")))
[79677]407 vsys.strVendor = pelmVendor->getValueN(RT_XML_CONTENT_SMALL);
[18376]408 const xml::ElementNode *pelmVersion;
409 if ((pelmVersion = pelmThis->findChildElement("Version")))
[79677]410 vsys.strVersion = pelmVersion->getValueN(RT_XML_CONTENT_SMALL);
[18376]411 const xml::ElementNode *pelmProductUrl;
412 if ((pelmProductUrl = pelmThis->findChildElement("ProductUrl")))
[79677]413 vsys.strProductUrl = pelmProductUrl->getValueN(RT_XML_CONTENT_SMALL);
[18376]414 const xml::ElementNode *pelmVendorUrl;
415 if ((pelmVendorUrl = pelmThis->findChildElement("VendorUrl")))
[79677]416 vsys.strVendorUrl = pelmVendorUrl->getValueN(RT_XML_CONTENT_SMALL);
[18376]417 }
[49029]418 else if ( !strcmp(pcszElemName, "VirtualHardwareSection")
419 || !strcmp(pcszTypeAttr, "ovf:VirtualHardwareSection_Type")
[16205]420 )
421 {
[17573]422 const xml::ElementNode *pelmSystem, *pelmVirtualSystemType;
[16205]423 if ((pelmSystem = pelmThis->findChildElement("System")))
424 {
425 /* <System>
426 <vssd:Description>Description of the virtual hardware section.</vssd:Description>
427 <vssd:ElementName>vmware</vssd:ElementName>
428 <vssd:InstanceID>1</vssd:InstanceID>
429 <vssd:VirtualSystemIdentifier>MyLampService</vssd:VirtualSystemIdentifier>
430 <vssd:VirtualSystemType>vmx-4</vssd:VirtualSystemType>
431 </System>*/
432 if ((pelmVirtualSystemType = pelmSystem->findChildElement("VirtualSystemType")))
[79677]433 vsys.strVirtualSystemType = pelmVirtualSystemType->getValueN(RT_XML_CONTENT_SMALL);
[16205]434 }
435
[68917]436 /* Parse the items into the hardware item vector. */
[16205]437 {
[90438]438 std::map<RTCString, const VirtualHardwareItem *> mapHardwareItems;
[68917]439 xml::NodesLoop childrenIterator(*pelmThis);
[46518]440 const xml::ElementNode *pelmItem;
[68917]441 while ((pelmItem = childrenIterator.forAllNodes()) != NULL)
[46518]442 {
[68917]443 /* Parse according to type. */
444 VirtualHardwareItem *pItem;
445 const char *pszName = pelmItem->getName();
446 if (RTStrCmp(pszName, "Item") == 0)
447 pItem = new VirtualHardwareItem();
448 else if (RTStrCmp(pszName, "StorageItem") == 0)
449 pItem = new StorageItem();
450 else if (RTStrCmp(pszName, "EthernetPortItem") == 0)
451 pItem = new EthernetPortItem();
452 else
453 continue;
454 vsys.vecHardwareItems.push_back(pItem);
[85222]455 pItem->m_iLineNumber = pelmItem->getLineNumber();
[68917]456 pItem->fillItem(pelmItem);
[16205]457
[68917]458 /* validate */
[46518]459 try
[16205]460 {
[68917]461 pItem->checkConsistencyAndCompliance();
[16205]462 }
[46518]463 catch (OVFLogicError &e)
[29422]464 {
[68917]465 throw OVFLogicError(N_("Error reading \"%s\": \"%s\""), m_strPath.c_str(), e.what());
[29422]466 }
[46518]467
[68917]468 /* Add to mapping vector (for parent ID lookups) if it has a valid instance ID. */
[90438]469 if (!pItem->strInstanceID.isEmpty())
[46518]470 {
[90438]471 std::map<RTCString, const VirtualHardwareItem *>::const_iterator itDup;
472 itDup = mapHardwareItems.find(pItem->strInstanceID);
[68917]473 if (itDup == mapHardwareItems.end())
[90438]474 mapHardwareItems[pItem->strInstanceID] = pItem;
[68917]475 else
476#if 1
[90438]477 LogRel(("OVFREADER: Warning reading \"%s\": Duplicate InstanceID \"%s\" on line %d, previous at %d!\n",
478 m_strPath.c_str(), pItem->strInstanceID.c_str(), pItem->m_iLineNumber, itDup->second->m_iLineNumber));
[68917]479#else
[90438]480 throw OVFLogicError(N_("Error reading \"%s\": Duplicate InstanceID \"%s\" on line %d, previous at %d"),
481 m_strPath.c_str(), pItem->strInstanceID.c_str(),
[85222]482 pItem->m_iLineNumber, itDup->second->m_iLineNumber);
[68917]483#endif
[46518]484 }
[16205]485 }
486 }
487
[46518]488 HardDiskController *pPrimaryIDEController = NULL;// will be set once found
[29422]489
[18152]490 // now go thru all hardware items and handle them according to their type;
491 // in this first loop we handle all items _except_ hard disk images,
492 // which we'll handle in a second loop below
[68917]493 HardwareItemVector::const_iterator itH;
494 for (itH = vsys.vecHardwareItems.begin(); itH != vsys.vecHardwareItems.end(); ++itH)
[16205]495 {
[68917]496 const VirtualHardwareItem &i = **itH;
[16205]497
498 // do some analysis
499 switch (i.resourceType)
500 {
[27908]501 case ResourceType_Processor: // 3
[16205]502 /* <rasd:Caption>1 virtual CPU</rasd:Caption>
503 <rasd:Description>Number of virtual CPUs</rasd:Description>
504 <rasd:ElementName>virtual CPU</rasd:ElementName>
505 <rasd:InstanceID>1</rasd:InstanceID>
506 <rasd:ResourceType>3</rasd:ResourceType>
507 <rasd:VirtualQuantity>1</rasd:VirtualQuantity>*/
508 if (i.ullVirtualQuantity < UINT16_MAX)
[16495]509 vsys.cCPUs = (uint16_t)i.ullVirtualQuantity;
[16205]510 else
[21588]511 throw OVFLogicError(N_("Error reading \"%s\": CPU count %RI64 is larger than %d, line %d"),
512 m_strPath.c_str(),
513 i.ullVirtualQuantity,
514 UINT16_MAX,
[85222]515 i.m_iLineNumber);
[37869]516 break;
[16205]517
[27908]518 case ResourceType_Memory: // 4
[99604]519 /* It's alway stored in bytes in VSD according to the old internal agreement within the team */
[49029]520 if ( i.strAllocationUnits == "MegaBytes" // found in OVF created by OVF toolkit
521 || i.strAllocationUnits == "MB" // found in MS docs
522 || i.strAllocationUnits == "byte * 2^20" // suggested by OVF spec DSP0243 page 21
[16205]523 )
[99604]524 vsys.ullMemorySize = i.ullVirtualQuantity * _1M;
[99523]525 else if ( i.strAllocationUnits == "GigaBytes"
526 || i.strAllocationUnits == "GB"
527 || i.strAllocationUnits == "byte * 2^30"
528 )
[99604]529 vsys.ullMemorySize = i.ullVirtualQuantity * _1G;
[16205]530 else
[21588]531 throw OVFLogicError(N_("Error reading \"%s\": Invalid allocation unit \"%s\" specified with memory size item, line %d"),
532 m_strPath.c_str(),
533 i.strAllocationUnits.c_str(),
[85222]534 i.m_iLineNumber);
[37869]535 break;
[16205]536
[27908]537 case ResourceType_IDEController: // 5
[16228]538 {
539 /* <Item>
540 <rasd:Caption>ideController0</rasd:Caption>
541 <rasd:Description>IDE Controller</rasd:Description>
542 <rasd:InstanceId>5</rasd:InstanceId>
543 <rasd:ResourceType>5</rasd:ResourceType>
544 <rasd:Address>0</rasd:Address>
545 <rasd:BusNumber>0</rasd:BusNumber>
546 </Item> */
547 HardDiskController hdc;
[16495]548 hdc.system = HardDiskController::IDE;
[90438]549 hdc.strIdController = i.strInstanceID;
[18350]550 hdc.strControllerType = i.strResourceSubType;
[16228]551
[29422]552 hdc.lAddress = i.lAddress;
553
554 if (!pPrimaryIDEController)
555 // this is the first IDE controller found: then mark it as "primary"
556 hdc.fPrimary = true;
[28531]557 else
[29422]558 {
559 // this is the second IDE controller found: If VMware exports two
560 // IDE controllers, it seems that they are given an "Address" of 0
561 // an 1, respectively, so assume address=0 means primary controller
562 if ( pPrimaryIDEController->lAddress == 0
563 && hdc.lAddress == 1
564 )
565 {
566 pPrimaryIDEController->fPrimary = true;
567 hdc.fPrimary = false;
568 }
569 else if ( pPrimaryIDEController->lAddress == 1
570 && hdc.lAddress == 0
571 )
572 {
573 pPrimaryIDEController->fPrimary = false;
574 hdc.fPrimary = false;
575 }
576 else
577 // then we really can't tell, just hope for the best
578 hdc.fPrimary = false;
579 }
[28531]580
[90438]581 vsys.mapControllers[i.strInstanceID] = hdc;
[29422]582 if (!pPrimaryIDEController)
[90438]583 pPrimaryIDEController = &vsys.mapControllers[i.strInstanceID];
[37869]584 break;
[16228]585 }
586
[27908]587 case ResourceType_ParallelSCSIHBA: // 6 SCSI controller
[16205]588 {
589 /* <Item>
590 <rasd:Caption>SCSI Controller 0 - LSI Logic</rasd:Caption>
591 <rasd:Description>SCI Controller</rasd:Description>
592 <rasd:ElementName>SCSI controller</rasd:ElementName>
593 <rasd:InstanceID>4</rasd:InstanceID>
594 <rasd:ResourceSubType>LsiLogic</rasd:ResourceSubType>
595 <rasd:ResourceType>6</rasd:ResourceType>
596 </Item> */
597 HardDiskController hdc;
[16495]598 hdc.system = HardDiskController::SCSI;
[90438]599 hdc.strIdController = i.strInstanceID;
[16205]600 hdc.strControllerType = i.strResourceSubType;
601
[90438]602 vsys.mapControllers[i.strInstanceID] = hdc;
[37869]603 break;
[16205]604 }
605
[27908]606 case ResourceType_EthernetAdapter: // 10
[16205]607 {
608 /* <Item>
[17963]609 <rasd:Caption>Ethernet adapter on 'Bridged'</rasd:Caption>
610 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
611 <rasd:Connection>Bridged</rasd:Connection>
612 <rasd:InstanceID>6</rasd:InstanceID>
613 <rasd:ResourceType>10</rasd:ResourceType>
614 <rasd:ResourceSubType>E1000</rasd:ResourceSubType>
[16205]615 </Item>
616
617 OVF spec DSP 0243 page 21:
618 "For an Ethernet adapter, this specifies the abstract network connection name
619 for the virtual machine. All Ethernet adapters that specify the same abstract
620 network connection name within an OVF package shall be deployed on the same
621 network. The abstract network connection name shall be listed in the NetworkSection
622 at the outermost envelope level." */
623
[17566]624 // only store the name
[17963]625 EthernetAdapter ea;
626 ea.strAdapterType = i.strResourceSubType;
627 ea.strNetworkName = i.strConnection;
628 vsys.llEthernetAdapters.push_back(ea);
[37869]629 break;
[16205]630 }
631
[27908]632 case ResourceType_FloppyDrive: // 14
[16495]633 vsys.fHasFloppyDrive = true; // we have no additional information
[37869]634 break;
[16306]635
[27908]636 case ResourceType_CDDrive: // 15
[16306]637 /* <Item ovf:required="false">
638 <rasd:Caption>cdrom1</rasd:Caption>
639 <rasd:InstanceId>7</rasd:InstanceId>
640 <rasd:ResourceType>15</rasd:ResourceType>
641 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
642 <rasd:Parent>5</rasd:Parent>
643 <rasd:AddressOnParent>0</rasd:AddressOnParent>
644 </Item> */
645 // I tried to see what happens if I set an ISO for the CD-ROM in VMware Workstation,
646 // but then the ovftool dies with "Device backing not supported". So I guess if
647 // VMware can't export ISOs, then we don't need to be able to import them right now.
[16495]648 vsys.fHasCdromDrive = true; // we have no additional information
[37869]649 break;
[16306]650
[27908]651 case ResourceType_HardDisk: // 17
[18152]652 // handled separately in second loop below
[37869]653 break;
[16306]654
[101472]655 case ResourceType_OtherStorageDevice: // 20 SATA/Virtio-SCSI/NVMe controller
[17871]656 {
657 /* <Item>
658 <rasd:Description>SATA Controller</rasd:Description>
659 <rasd:Caption>sataController0</rasd:Caption>
660 <rasd:InstanceID>4</rasd:InstanceID>
661 <rasd:ResourceType>20</rasd:ResourceType>
662 <rasd:ResourceSubType>AHCI</rasd:ResourceSubType>
663 <rasd:Address>0</rasd:Address>
664 <rasd:BusNumber>0</rasd:BusNumber>
665 </Item> */
[60998]666 if ( i.strResourceSubType.compare("AHCI", RTCString::CaseInsensitive) == 0
[59553]667 || i.strResourceSubType.compare("vmware.sata.ahci", RTCString::CaseInsensitive) == 0)
[17871]668 {
669 HardDiskController hdc;
670 hdc.system = HardDiskController::SATA;
[90438]671 hdc.strIdController = i.strInstanceID;
[17871]672 hdc.strControllerType = i.strResourceSubType;
673
[90438]674 vsys.mapControllers[i.strInstanceID] = hdc;
[17871]675 }
[90438]676 else if ( i.strResourceSubType.compare("VirtioSCSI", RTCString::CaseInsensitive) == 0
677 || i.strResourceSubType.compare("virtio-scsi", RTCString::CaseInsensitive) == 0 )
[84532]678 {
679 HardDiskController hdc;
[101472]680 hdc.system = HardDiskController::VIRTIOSCSI;
[90438]681 hdc.strIdController = i.strInstanceID;
[84532]682 //<rasd:ResourceSubType>VirtioSCSI</rasd:ResourceSubType>
683 hdc.strControllerType = i.strResourceSubType;
[90438]684 vsys.mapControllers[i.strInstanceID] = hdc;
[84532]685 }
[101472]686 else if ( i.strResourceSubType.compare("NVMe", RTCString::CaseInsensitive) == 0
687 || i.strResourceSubType.compare("vmware.nvme.controller", RTCString::CaseInsensitive) == 0 )
688 {
689 HardDiskController hdc;
690 hdc.system = HardDiskController::NVMe;
691 hdc.strIdController = i.strInstanceID;
692 //<rasd:ResourceSubType>NVMe</rasd:ResourceSubType>
693 hdc.strControllerType = i.strResourceSubType;
694 vsys.mapControllers[i.strInstanceID] = hdc;
695 }
[17871]696 else
[101472]697 throw OVFLogicError(N_("Error reading \"%s\": Host resource of type \"Other Storage Device (%d)\" is supported with SATA AHCI or Virtio-SCSI or NVMe controllers only, line %d (subtype:%s)"),
[21588]698 m_strPath.c_str(),
[27908]699 ResourceType_OtherStorageDevice,
[85222]700 i.m_iLineNumber, i.strResourceSubType.c_str() );
[37869]701 break;
[17871]702 }
703
[27908]704 case ResourceType_USBController: // 23
[16306]705 /* <Item ovf:required="false">
706 <rasd:Caption>usb</rasd:Caption>
707 <rasd:Description>USB Controller</rasd:Description>
708 <rasd:InstanceId>3</rasd:InstanceId>
709 <rasd:ResourceType>23</rasd:ResourceType>
710 <rasd:Address>0</rasd:Address>
711 <rasd:BusNumber>0</rasd:BusNumber>
712 </Item> */
[16495]713 vsys.fHasUsbController = true; // we have no additional information
[37869]714 break;
[16306]715
[27908]716 case ResourceType_SoundCard: // 35
[16306]717 /* <Item ovf:required="false">
718 <rasd:Caption>sound</rasd:Caption>
719 <rasd:Description>Sound Card</rasd:Description>
720 <rasd:InstanceId>10</rasd:InstanceId>
721 <rasd:ResourceType>35</rasd:ResourceType>
722 <rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
723 <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
724 <rasd:AddressOnParent>3</rasd:AddressOnParent>
725 </Item> */
[16495]726 vsys.strSoundCardType = i.strResourceSubType;
[37869]727 break;
[16306]728
729 default:
[35536]730 {
731 /* If this unknown resource type isn't required, we simply skip it. */
732 if (i.fResourceRequired)
733 {
734 throw OVFLogicError(N_("Error reading \"%s\": Unknown resource type %d in hardware item, line %d"),
735 m_strPath.c_str(),
736 i.resourceType,
[85222]737 i.m_iLineNumber);
[35536]738 }
739 }
[18152]740 } // end switch
741 }
742
743 // now run through the items for a second time, but handle only
744 // hard disk images; otherwise the code would fail if a hard
745 // disk image appears in the OVF before its hard disk controller
[68917]746 for (itH = vsys.vecHardwareItems.begin(); itH != vsys.vecHardwareItems.end(); ++itH)
[18152]747 {
[68917]748 const VirtualHardwareItem &i = **itH;
[18152]749
750 // do some analysis
751 switch (i.resourceType)
752 {
[46068]753 case ResourceType_CDDrive: // 15
[46140]754 /* <Item ovf:required="false">
755 <rasd:Caption>cdrom1</rasd:Caption>
756 <rasd:InstanceId>7</rasd:InstanceId>
757 <rasd:ResourceType>15</rasd:ResourceType>
758 <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
759 <rasd:Parent>5</rasd:Parent>
760 <rasd:AddressOnParent>0</rasd:AddressOnParent>
761 </Item> */
[27908]762 case ResourceType_HardDisk: // 17
[18152]763 {
764 /* <Item>
765 <rasd:Caption>Harddisk 1</rasd:Caption>
766 <rasd:Description>HD</rasd:Description>
767 <rasd:ElementName>Hard Disk</rasd:ElementName>
768 <rasd:HostResource>ovf://disk/lamp</rasd:HostResource>
769 <rasd:InstanceID>5</rasd:InstanceID>
770 <rasd:Parent>4</rasd:Parent>
771 <rasd:ResourceType>17</rasd:ResourceType>
772 </Item> */
773
774 // look up the hard disk controller element whose InstanceID equals our Parent;
775 // this is how the connection is specified in OVF
[90438]776 ControllersMap::const_iterator it = vsys.mapControllers.find(i.strParent);
[18152]777 if (it == vsys.mapControllers.end())
[90438]778 throw OVFLogicError(N_("Error reading \"%s\": Disk item with instance ID \"%s\" specifies invalid parent \"%s\", line %d"),
[21588]779 m_strPath.c_str(),
[90438]780 i.strInstanceID.c_str(),
781 i.strParent.c_str(),
[85222]782 i.m_iLineNumber);
[18152]783
784 VirtualDisk vd;
[90438]785 vd.strIdController = i.strParent;
[18152]786 i.strAddressOnParent.toInt(vd.ulAddressOnParent);
787 // ovf://disk/lamp
788 // 123456789012345
[35566]789 if (i.strHostResource.startsWith("ovf://disk/"))
[18152]790 vd.strDiskId = i.strHostResource.substr(11);
[35566]791 else if (i.strHostResource.startsWith("ovf:/disk/"))
[21439]792 vd.strDiskId = i.strHostResource.substr(10);
[35566]793 else if (i.strHostResource.startsWith("/disk/"))
[18152]794 vd.strDiskId = i.strHostResource.substr(6);
795
[46140]796 //the error may be missed for CD, because CD can be empty
797 if ((vd.strDiskId.isEmpty() || (m_mapDisks.find(vd.strDiskId) == m_mapDisks.end()))
798 && i.resourceType == ResourceType_HardDisk)
[90438]799 throw OVFLogicError(N_("Error reading \"%s\": Disk item with instance ID \"%s\" specifies invalid host resource \"%s\", line %d"),
[46068]800 m_strPath.c_str(),
[90438]801 i.strInstanceID.c_str(),
[46068]802 i.strHostResource.c_str(),
[85222]803 i.m_iLineNumber);
[18152]804
805 vsys.mapVirtualDisks[vd.strDiskId] = vd;
[37869]806 break;
[18152]807 }
[37869]808 default:
809 break;
[16205]810 }
811 }
812 }
[49029]813 else if ( !strcmp(pcszElemName, "OperatingSystemSection")
814 || !strcmp(pcszTypeAttr, "ovf:OperatingSystemSection_Type")
[16205]815 )
816 {
817 uint64_t cimos64;
818 if (!(pelmThis->getAttributeValue("id", cimos64)))
[21588]819 throw OVFLogicError(N_("Error reading \"%s\": missing or invalid 'ovf:id' attribute in operating system section element, line %d"),
820 m_strPath.c_str(),
821 pelmThis->getLineNumber());
[16205]822
[16495]823 vsys.cimos = (CIMOSType_T)cimos64;
[18530]824 const xml::ElementNode *pelmCIMOSDescription;
825 if ((pelmCIMOSDescription = pelmThis->findChildElement("Description")))
[79677]826 vsys.strCimosDesc = pelmCIMOSDescription->getValueN(RT_XML_CONTENT_SMALL);
[34501]827
828 const xml::ElementNode *pelmVBoxOSType;
[49028]829 if ((pelmVBoxOSType = pelmThis->findChildElementNS("vbox", // namespace
830 "OSType"))) // element name
[79677]831 vsys.strTypeVBox = pelmVBoxOSType->getValueN(RT_XML_CONTENT_SMALL);
[16205]832 }
[18052]833 else if ( (!strcmp(pcszElemName, "AnnotationSection"))
834 || (!strcmp(pcszTypeAttr, "ovf:AnnotationSection_Type"))
835 )
836 {
837 const xml::ElementNode *pelmAnnotation;
838 if ((pelmAnnotation = pelmThis->findChildElement("Annotation")))
[79677]839 vsys.strDescription = pelmAnnotation->getValueN(RT_XML_CONTENT_SMALL);
[18052]840 }
[16205]841 }
842}
843
[46518]844void VirtualHardwareItem::fillItem(const xml::ElementNode *item)
845{
846 xml::NodesLoop loopItemChildren(*item);// all child elements
847 const xml::ElementNode *pelmItemChild;
848 while ((pelmItemChild = loopItemChildren.forAllNodes()))
849 {
850 const char *pcszItemChildName = pelmItemChild->getName();
851 if (!strcmp(pcszItemChildName, "Description"))
[79677]852 strDescription = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]853 else if (!strcmp(pcszItemChildName, "Caption"))
[79677]854 strCaption = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]855 else if (!strcmp(pcszItemChildName, "ElementName"))
[79677]856 strElementName = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[68917]857 else if ( !strcmp(pcszItemChildName, "InstanceID")
858 || !strcmp(pcszItemChildName, "InstanceId") )
[90438]859 strInstanceID = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]860 else if (!strcmp(pcszItemChildName, "HostResource"))
[79677]861 strHostResource = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]862 else if (!strcmp(pcszItemChildName, "ResourceType"))
863 {
864 uint32_t ulType;
865 pelmItemChild->copyValue(ulType);
[90438]866 if (ulType > 0xffff)
867 ulType = 0xffff;
[46518]868 resourceType = (ResourceType_T)ulType;
869 fResourceRequired = true;
870 const char *pcszAttValue;
[79677]871 if (item->getAttributeValueN("required", pcszAttValue, RT_XML_ATTR_TINY))
[46518]872 {
873 if (!strcmp(pcszAttValue, "false"))
874 fResourceRequired = false;
875 }
876 }
877 else if (!strcmp(pcszItemChildName, "OtherResourceType"))
[79677]878 strOtherResourceType = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]879 else if (!strcmp(pcszItemChildName, "ResourceSubType"))
[79677]880 strResourceSubType = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]881 else if (!strcmp(pcszItemChildName, "AutomaticAllocation"))
[79677]882 fAutomaticAllocation = (!strcmp(pelmItemChild->getValueN(RT_XML_CONTENT_SMALL), "true")) ? true : false;
[46518]883 else if (!strcmp(pcszItemChildName, "AutomaticDeallocation"))
[79677]884 fAutomaticDeallocation = (!strcmp(pelmItemChild->getValueN(RT_XML_CONTENT_SMALL), "true")) ? true : false;
[46518]885 else if (!strcmp(pcszItemChildName, "Parent"))
[90438]886 strParent = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]887 else if (!strcmp(pcszItemChildName, "Connection"))
[79677]888 strConnection = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]889 else if (!strcmp(pcszItemChildName, "Address"))
890 {
[79677]891 strAddress = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]892 pelmItemChild->copyValue(lAddress);
893 }
894 else if (!strcmp(pcszItemChildName, "AddressOnParent"))
[79677]895 strAddressOnParent = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]896 else if (!strcmp(pcszItemChildName, "AllocationUnits"))
[79677]897 strAllocationUnits = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]898 else if (!strcmp(pcszItemChildName, "VirtualQuantity"))
899 pelmItemChild->copyValue(ullVirtualQuantity);
900 else if (!strcmp(pcszItemChildName, "Reservation"))
901 pelmItemChild->copyValue(ullReservation);
902 else if (!strcmp(pcszItemChildName, "Limit"))
903 pelmItemChild->copyValue(ullLimit);
904 else if (!strcmp(pcszItemChildName, "Weight"))
905 pelmItemChild->copyValue(ullWeight);
906 else if (!strcmp(pcszItemChildName, "ConsumerVisibility"))
[79677]907 strConsumerVisibility = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]908 else if (!strcmp(pcszItemChildName, "MappingBehavior"))
[79677]909 strMappingBehavior = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]910 else if (!strcmp(pcszItemChildName, "PoolID"))
[79677]911 strPoolID = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]912 else if (!strcmp(pcszItemChildName, "BusNumber"))
913 pelmItemChild->copyValue(ulBusNumber);
914// else if (pelmItemChild->getPrefix() == NULL
915// || strcmp(pelmItemChild->getPrefix(), "vmw"))
[90438]916// throw OVFLogicError(N_("Unknown element '%s' under Item element, line %d"),
[46518]917// pcszItemChildName,
[85222]918// m_iLineNumber);
[46518]919 }
920}
921
[49029]922void VirtualHardwareItem::_checkConsistencyAndCompliance() RT_THROW(OVFLogicError)
[46518]923{
924 RTCString name = getItemName();
[103288]925 if (resourceType == ResourceType_Invalid)
[68917]926 throw OVFLogicError(N_("Empty element ResourceType under %s element, line %d. see DMTF Schema Documentation %s"),
[85222]927 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[68917]928
[90438]929 /* Don't be too uptight about the strInstanceID value. There are OVAs out
930 there which have InstanceID="%iid%" for memory for instance, which is
[68917]931 no good reason for not being able to process them. bugref:8997 */
[90438]932 if (strInstanceID.isEmpty())
[68917]933 {
934 if ( resourceType == ResourceType_IDEController
935 || resourceType == ResourceType_OtherStorageDevice
936 || resourceType == ResourceType_ParallelSCSIHBA
937 || resourceType == ResourceType_iSCSIHBA //??
938 || resourceType == ResourceType_IBHCA ) //??
939 throw OVFLogicError(N_("Element InstanceID is absent under %s element, line %d. see DMTF Schema Documentation %s"),
[85222]940 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[68917]941 else
[90438]942 LogRel(("OVFREADER: Warning: Ignoring missing or invalid InstanceID under element %s, line %u\n",
[85222]943 name.c_str(), m_iLineNumber));
[68917]944 }
[46518]945}
946
947void StorageItem::fillItem(const xml::ElementNode *item)
948{
949 VirtualHardwareItem::fillItem(item);
950
951 xml::NodesLoop loopItemChildren(*item);// all child elements
952 const xml::ElementNode *pelmItemChild;
953 while ((pelmItemChild = loopItemChildren.forAllNodes()))
954 {
955 const char *pcszItemChildName = pelmItemChild->getName();
956 if (!strcmp(pcszItemChildName, "HostExtentName"))
[79677]957 strHostExtentName = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]958 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameFormat"))
[79677]959 strOtherHostExtentNameFormat = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]960 else if (!strcmp(pcszItemChildName, "OtherHostExtentNameNamespace"))
[79677]961 strOtherHostExtentNameNamespace = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]962 else if (!strcmp(pcszItemChildName, "VirtualQuantityUnits"))
[79677]963 strVirtualQuantityUnits = pelmItemChild->getValueN(RT_XML_CONTENT_SMALL);
[46518]964 else if (!strcmp(pcszItemChildName, "Access"))
965 {
966 uint32_t temp;
967 pelmItemChild->copyValue(temp);
968 accessType = (StorageAccessType_T)temp;
969 }
970 else if (!strcmp(pcszItemChildName, "HostExtentNameFormat"))
971 {
972 }
973 else if (!strcmp(pcszItemChildName, "HostExtentNameNamespace"))
974 {
975 }
976 else if (!strcmp(pcszItemChildName, "HostExtentStartingAddress"))
977 {
978 }
979 else if (!strcmp(pcszItemChildName, "HostResourceBlockSize"))
980 {
981 int64_t temp;
982 pelmItemChild->copyValue(temp);
983 hostResourceBlockSize = temp;
984 }
985 else if (!strcmp(pcszItemChildName, "Limit"))
986 {
987 int64_t temp;
988 pelmItemChild->copyValue(temp);
989 limit = temp;
990 }
991 else if (!strcmp(pcszItemChildName, "Reservation"))
992 {
993 int64_t temp;
994 pelmItemChild->copyValue(temp);
995 reservation = temp;
996 }
997 else if (!strcmp(pcszItemChildName, "VirtualQuantity"))
998 {
999 int64_t temp;
1000 pelmItemChild->copyValue(temp);
1001 virtualQuantity = temp;
1002 }
1003 else if (!strcmp(pcszItemChildName, "VirtualResourceBlockSize"))
1004 {
1005 int64_t temp;
1006 pelmItemChild->copyValue(temp);
1007 virtualResourceBlockSize = temp;
1008 }
1009 }
1010}
1011
1012
[49029]1013void StorageItem::_checkConsistencyAndCompliance() RT_THROW(OVFLogicError)
[46518]1014{
1015 VirtualHardwareItem::_checkConsistencyAndCompliance();
1016
1017 RTCString name = getItemName();
1018
1019 if (accessType == StorageAccessType_Unknown)
1020 {
1021 //throw OVFLogicError(N_("Access type is unknown under %s element, line %d"),
[85222]1022 // name.c_str(), m_iLineNumber);
[46518]1023 }
1024
1025 if (hostResourceBlockSize <= 0 && reservation > 0)
1026 {
1027 throw OVFLogicError(N_("Element HostResourceBlockSize is absent under %s element, line %d. "
1028 "see DMTF Schema Documentation %s"),
[85222]1029 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[46518]1030 }
1031
1032 if (virtualResourceBlockSize <= 0 && virtualQuantity > 0)
1033 {
1034 throw OVFLogicError(N_("Element VirtualResourceBlockSize is absent under %s element, line %d. "
1035 "see DMTF Schema Documentation %s"),
[85222]1036 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[46518]1037 }
1038
1039 if (virtualQuantity > 0 && strVirtualQuantityUnits.isEmpty())
1040 {
1041 throw OVFLogicError(N_("Element VirtualQuantityUnits is absent under %s element, line %d. "
1042 "see DMTF Schema Documentation %s"),
[85222]1043 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[46518]1044 }
1045
1046 if (virtualResourceBlockSize <= 1 &&
1047 strVirtualQuantityUnits.compare(RTCString("count"), RTCString::CaseInsensitive) == 0
1048 )
1049 {
1050 throw OVFLogicError(N_("Element VirtualQuantityUnits is set to \"count\" "
1051 "while VirtualResourceBlockSize is set to 1. "
1052 "under %s element, line %d. "
1053 "It's needed to change on \"byte\". "
1054 "see DMTF Schema Documentation %s"),
[85222]1055 name.c_str(), m_iLineNumber, DTMF_SPECS_URI);
[46518]1056 }
1057}
1058
1059void EthernetPortItem::fillItem(const xml::ElementNode *item)
1060{
1061 VirtualHardwareItem::fillItem(item);
1062
1063 xml::NodesLoop loopItemChildren(*item);// all child elements
1064 const xml::ElementNode *pelmItemChild;
1065 while ((pelmItemChild = loopItemChildren.forAllNodes()))
1066 {
1067 }
1068}
1069
[49029]1070void EthernetPortItem::_checkConsistencyAndCompliance() RT_THROW(OVFLogicError)
[46518]1071{
1072 VirtualHardwareItem::_checkConsistencyAndCompliance();
1073}
1074
[17099]1075////////////////////////////////////////////////////////////////////////////////
1076//
[21588]1077// Errors
[17099]1078//
[16205]1079////////////////////////////////////////////////////////////////////////////////
1080
[21588]1081OVFLogicError::OVFLogicError(const char *aFormat, ...)
[16205]1082{
[21588]1083 char *pszNewMsg;
[18248]1084 va_list args;
[21588]1085 va_start(args, aFormat);
1086 RTStrAPrintfV(&pszNewMsg, aFormat, args);
1087 setWhat(pszNewMsg);
1088 RTStrFree(pszNewMsg);
[18248]1089 va_end(args);
[21599]1090}
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