VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImpl.h@ 49749

最後變更 在這個檔案從49749是 49749,由 vboxsync 提交於 11 年 前

pr7074. OVF import: Restoring original UUIDs of imported images in VM configuration settings in case of failure.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 13.0 KB
 
1/* $Id: ApplianceImpl.h 49749 2013-12-03 12:29:19Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2013 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.alldomusa.eu.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef ____H_APPLIANCEIMPL
21#define ____H_APPLIANCEIMPL
22
23/* VBox includes */
24#include <VBox/settings.h>
25#include "VirtualSystemDescriptionWrap.h"
26#include "ApplianceWrap.h"
27#include "MediumFormatImpl.h"
28
29/* Todo: This file needs massive cleanup. Split IAppliance in a public and
30 * private classes. */
31#include <iprt/tar.h>
32#include "ovfreader.h"
33#include <set>
34
35/* VBox forward declarations */
36class Progress;
37class VirtualSystemDescription;
38struct VirtualSystemDescriptionEntry;
39struct LocationInfo;
40typedef struct VDINTERFACE *PVDINTERFACE;
41typedef struct VDINTERFACEIO *PVDINTERFACEIO;
42typedef struct SHASTORAGE *PSHASTORAGE;
43
44typedef enum applianceIOName { applianceIOTar, applianceIOFile, applianceIOSha } APPLIANCEIONAME;
45
46namespace ovf
47{
48 struct HardDiskController;
49 struct VirtualSystem;
50 class OVFReader;
51 struct DiskImage;
52 struct EnvelopeData;
53}
54
55namespace xml
56{
57 class Document;
58 class ElementNode;
59}
60
61namespace settings
62{
63 class MachineConfigFile;
64}
65
66class ATL_NO_VTABLE Appliance :
67 public ApplianceWrap
68{
69public:
70
71 DECLARE_EMPTY_CTOR_DTOR(Appliance)
72
73 HRESULT FinalConstruct();
74 void FinalRelease();
75
76
77 HRESULT init(VirtualBox *aVirtualBox);
78 void uninit();
79
80 /* public methods only for internal purposes */
81
82 static HRESULT i_setErrorStatic(HRESULT aResultCode,
83 const Utf8Str &aText)
84 {
85 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
86 }
87
88 /* private instance data */
89private:
90 /** weak VirtualBox parent */
91 // wrapped IAppliance properties
92 HRESULT getPath(com::Utf8Str &aPath);
93 HRESULT getDisks(std::vector<com::Utf8Str> &aDisks);
94 HRESULT getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions);
95 HRESULT getMachines(std::vector<com::Utf8Str> &aMachines);
96
97 // wrapped IAppliance methods
98 HRESULT read(const com::Utf8Str &aFile,
99 ComPtr<IProgress> &aProgress);
100 HRESULT interpret();
101 HRESULT importMachines(const std::vector<ImportOptions_T> &aOptions,
102 ComPtr<IProgress> &aProgress);
103 HRESULT createVFSExplorer(const com::Utf8Str &aURI,
104 ComPtr<IVFSExplorer> &aExplorer);
105 HRESULT write(const com::Utf8Str &aFormat,
106 const std::vector<ExportOptions_T> &aOptions,
107 const com::Utf8Str &aPath,
108 ComPtr<IProgress> &aProgress);
109 HRESULT getWarnings(std::vector<com::Utf8Str> &aWarnings);
110
111
112 VirtualBox* const mVirtualBox;
113
114 struct ImportStack;
115 struct TaskOVF;
116 struct Data; // opaque, defined in ApplianceImpl.cpp
117 Data *m;
118
119 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
120
121 /*******************************************************************************
122 * General stuff
123 ******************************************************************************/
124
125 bool i_isApplianceIdle();
126 HRESULT i_searchUniqueVMName(Utf8Str& aName) const;
127 HRESULT i_searchUniqueDiskImageFilePath(Utf8Str& aName) const;
128 HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
129 const Bstr &bstrDescription,
130 SetUpProgressMode mode);
131 void i_waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
132 void i_addWarning(const char* aWarning, ...);
133 void i_disksWeight();
134 void i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
135
136 static DECLCALLBACK(int) i_taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
137
138 HRESULT i_initSetOfSupportedStandardsURI();
139
140 Utf8Str i_typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
141
142 std::set<Utf8Str> i_URIFromTypeOfVirtualDiskFormat(Utf8Str type);
143
144 HRESULT i_initApplianceIONameMap();
145
146 Utf8Str i_applianceIOName(APPLIANCEIONAME type) const;
147
148 HRESULT i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
149
150 /*******************************************************************************
151 * Read stuff
152 ******************************************************************************/
153
154 HRESULT i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
155
156 HRESULT i_readFS(TaskOVF *pTask);
157 HRESULT i_readFSOVF(TaskOVF *pTask);
158 HRESULT i_readFSOVA(TaskOVF *pTask);
159 HRESULT i_readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
160 HRESULT i_readS3(TaskOVF *pTask);
161
162 /*******************************************************************************
163 * Import stuff
164 ******************************************************************************/
165
166 HRESULT i_importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
167
168 HRESULT i_importFS(TaskOVF *pTask);
169 HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
170 HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
171 HRESULT i_importS3(TaskOVF *pTask);
172
173 HRESULT i_readFileToBuf(const Utf8Str &strFile,
174 void **ppvBuf,
175 size_t *pcbSize,
176 bool fCreateDigest,
177 PVDINTERFACEIO pCallbacks,
178 PSHASTORAGE pStorage);
179 HRESULT i_readTarFileToBuf(RTTAR tar,
180 const Utf8Str &strFile,
181 void **ppvBuf,
182 size_t *pcbSize,
183 bool fCreateDigest,
184 PVDINTERFACEIO pCallbacks,
185 PSHASTORAGE pStorage);
186 HRESULT i_verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
187
188 void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
189 uint32_t ulAddressOnParent,
190 Bstr &controllerType,
191 int32_t &lControllerPort,
192 int32_t &lDevice);
193
194 void i_importOneDiskImage(const ovf::DiskImage &di,
195 Utf8Str *strTargetPath,
196 ComObjPtr<Medium> &pTargetHD,
197 ImportStack &stack,
198 PVDINTERFACEIO pCallbacks,
199 PSHASTORAGE pStorage);
200
201 void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
202 ComObjPtr<VirtualSystemDescription> &vsdescThis,
203 ComPtr<IMachine> &pNewMachine,
204 ImportStack &stack,
205 PVDINTERFACEIO pCallbacks,
206 PSHASTORAGE pStorage);
207 void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
208 ComPtr<IMachine> &pNewMachine,
209 ImportStack &stack,
210 PVDINTERFACEIO pCallbacks,
211 PSHASTORAGE pStorage);
212 void i_importMachines(ImportStack &stack,
213 PVDINTERFACEIO pCallbacks,
214 PSHASTORAGE pStorage);
215
216 /*******************************************************************************
217 * Write stuff
218 ******************************************************************************/
219
220 HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
221
222 HRESULT i_writeFS(TaskOVF *pTask);
223 HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
224 HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
225 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
226 HRESULT i_writeS3(TaskOVF *pTask);
227
228 struct XMLStack;
229
230 void i_buildXML(AutoWriteLockBase& writeLock,
231 xml::Document &doc,
232 XMLStack &stack,
233 const Utf8Str &strPath,
234 ovf::OVFVersion_T enFormat);
235 void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
236 xml::ElementNode &elmToAddVirtualSystemsTo,
237 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
238 ComObjPtr<VirtualSystemDescription> &vsdescThis,
239 ovf::OVFVersion_T enFormat,
240 XMLStack &stack);
241
242 HRESULT i_preCheckImageAvailability(PSHASTORAGE pSHAStorage,
243 RTCString &availableImage);
244
245 friend class Machine;
246};
247
248void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
249
250struct VirtualSystemDescriptionEntry
251{
252 uint32_t ulIndex; // zero-based index of this entry within array
253 VirtualSystemDescriptionType_T type; // type of this entry
254 Utf8Str strRef; // reference number (hard disk controllers only)
255 Utf8Str strOvf; // original OVF value (type-dependent)
256 Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
257 Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
258 Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
259 Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
260
261 uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
262};
263
264class ATL_NO_VTABLE VirtualSystemDescription :
265 public VirtualSystemDescriptionWrap
266{
267 friend class Appliance;
268
269public:
270
271 DECLARE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
272
273 HRESULT FinalConstruct();
274 void FinalRelease();
275
276 HRESULT init();
277 void uninit();
278
279 /* public methods only for internal purposes */
280 void i_addEntry(VirtualSystemDescriptionType_T aType,
281 const Utf8Str &strRef,
282 const Utf8Str &aOvfValue,
283 const Utf8Str &aVboxValue,
284 uint32_t ulSizeMB = 0,
285 const Utf8Str &strExtraConfig = "");
286
287 std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
288 const VirtualSystemDescriptionEntry* i_findControllerFromID(uint32_t id);
289
290 void i_importVboxMachineXML(const xml::ElementNode &elmMachine);
291 const settings::MachineConfigFile* i_getMachineConfig() const;
292
293 /* private instance data */
294private:
295
296 // wrapped IVirtualSystemDescription properties
297 HRESULT getCount(ULONG *aCount);
298
299 // wrapped IVirtualSystemDescription methods
300 HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
301 std::vector<com::Utf8Str> &aRefs,
302 std::vector<com::Utf8Str> &aOVFValues,
303 std::vector<com::Utf8Str> &aVBoxValues,
304 std::vector<com::Utf8Str> &aExtraConfigValues);
305 HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
306 std::vector<VirtualSystemDescriptionType_T> &aTypes,
307 std::vector<com::Utf8Str> &aRefs,
308 std::vector<com::Utf8Str> &aOVFValues,
309 std::vector<com::Utf8Str> &aVBoxValues,
310 std::vector<com::Utf8Str> &aExtraConfigValues);
311 HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
312 VirtualSystemDescriptionValueType_T aWhich,
313 std::vector<com::Utf8Str> &aValues);
314 HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
315 const std::vector<com::Utf8Str> &aVBoxValues,
316 const std::vector<com::Utf8Str> &aExtraConfigValues);
317 HRESULT addDescription(VirtualSystemDescriptionType_T aType,
318 const com::Utf8Str &aVBoxValue,
319 const com::Utf8Str &aExtraConfigValue);
320 void i_removeByType(VirtualSystemDescriptionType_T aType);
321
322 struct Data;
323 Data *m;
324
325 friend class Machine;
326};
327
328#endif // ____H_APPLIANCEIMPL
329/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette