VirtualBox

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

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

pr7072. Search an appropriate medium format using, firstly, URL given in the OVF description file and, secondly, using an image extension.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 13.6 KB
 
1/* $Id: ApplianceImpl.h 49620 2013-11-22 10:37:17Z 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 "VirtualBoxBase.h"
25#include "MediumFormatImpl.h"
26
27/* Todo: This file needs massive cleanup. Split IAppliance in a public and
28 * private classes. */
29#include <iprt/tar.h>
30#include <iprt/circbuf.h>
31#include <VBox/vd.h>
32#include <iprt/sha.h>
33
34#include "ovfreader.h"
35#include <set>
36
37/* VBox forward declarations */
38class Progress;
39class VirtualSystemDescription;
40struct VirtualSystemDescriptionEntry;
41struct LocationInfo;
42typedef struct VDINTERFACE *PVDINTERFACE;
43typedef struct VDINTERFACEIO *PVDINTERFACEIO;
44typedef struct SHASTORAGE *PSHASTORAGE;
45
46typedef enum applianceIOName { applianceIOTar, applianceIOFile, applianceIOSha } APPLIANCEIONAME;
47
48namespace ovf
49{
50 struct HardDiskController;
51 struct VirtualSystem;
52 class OVFReader;
53 struct DiskImage;
54 struct EnvelopeData;
55}
56
57namespace xml
58{
59 class Document;
60 class ElementNode;
61}
62
63namespace settings
64{
65 class MachineConfigFile;
66}
67
68class ATL_NO_VTABLE Appliance :
69 public VirtualBoxBase,
70 VBOX_SCRIPTABLE_IMPL(IAppliance)
71{
72public:
73 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Appliance, IAppliance)
74
75 DECLARE_NOT_AGGREGATABLE(Appliance)
76
77 DECLARE_PROTECT_FINAL_CONSTRUCT()
78
79 BEGIN_COM_MAP(Appliance)
80 VBOX_DEFAULT_INTERFACE_ENTRIES(IAppliance)
81 END_COM_MAP()
82
83 DECLARE_EMPTY_CTOR_DTOR (Appliance)
84
85
86
87 // public initializer/uninitializer for internal purposes only
88 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
89 void FinalRelease() { uninit(); BaseFinalRelease(); }
90
91 HRESULT init(VirtualBox *aVirtualBox);
92 void uninit();
93
94 /* IAppliance properties */
95 STDMETHOD(COMGETTER(Path))(BSTR *aPath);
96 STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
97 STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
98 STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
99
100 /* IAppliance methods */
101 /* Import methods */
102 STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
103 STDMETHOD(Interpret)(void);
104 STDMETHOD(ImportMachines)(ComSafeArrayIn(ImportOptions_T, options), IProgress **aProgress);
105 /* Export methods */
106 STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
107 STDMETHOD(Write)(IN_BSTR format, ComSafeArrayIn(ExportOptions_T, options), IN_BSTR path, IProgress **aProgress);
108
109 STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
110
111 /* public methods only for internal purposes */
112
113 static HRESULT setErrorStatic(HRESULT aResultCode,
114 const Utf8Str &aText)
115 {
116 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
117 }
118
119 /* private instance data */
120private:
121 /** weak VirtualBox parent */
122 VirtualBox* const mVirtualBox;
123
124 struct ImportStack;
125 struct TaskOVF;
126 struct Data; // opaque, defined in ApplianceImpl.cpp
127 Data *m;
128
129 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
130
131 /*******************************************************************************
132 * General stuff
133 ******************************************************************************/
134
135 bool isApplianceIdle();
136 HRESULT searchUniqueVMName(Utf8Str& aName) const;
137 HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
138 HRESULT setUpProgress(ComObjPtr<Progress> &pProgress,
139 const Bstr &bstrDescription,
140 SetUpProgressMode mode);
141 void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
142 void addWarning(const char* aWarning, ...);
143 void disksWeight();
144 void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
145
146 static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
147
148 HRESULT initSetOfSupportedStandardsURI();
149
150 Utf8Str typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
151
152 std::set<Utf8Str> URIFromTypeOfVirtualDiskFormat(Utf8Str type);
153
154 HRESULT initApplianceIONameMap();
155
156 Utf8Str applianceIOName(APPLIANCEIONAME type) const;
157
158 HRESULT findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
159
160 /*******************************************************************************
161 * Read stuff
162 ******************************************************************************/
163
164 HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
165
166 HRESULT readFS(TaskOVF *pTask);
167 HRESULT readFSOVF(TaskOVF *pTask);
168 HRESULT readFSOVA(TaskOVF *pTask);
169 HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
170 HRESULT readS3(TaskOVF *pTask);
171
172 /*******************************************************************************
173 * Import stuff
174 ******************************************************************************/
175
176 HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
177
178 HRESULT importFS(TaskOVF *pTask);
179 HRESULT importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
180 HRESULT importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
181 HRESULT importS3(TaskOVF *pTask);
182
183 HRESULT readFileToBuf(const Utf8Str &strFile,
184 void **ppvBuf,
185 size_t *pcbSize,
186 bool fCreateDigest,
187 PVDINTERFACEIO pCallbacks,
188 PSHASTORAGE pStorage);
189 HRESULT readTarFileToBuf(RTTAR tar,
190 const Utf8Str &strFile,
191 void **ppvBuf,
192 size_t *pcbSize,
193 bool fCreateDigest,
194 PVDINTERFACEIO pCallbacks,
195 PSHASTORAGE pStorage);
196 HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
197
198 void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
199 uint32_t ulAddressOnParent,
200 Bstr &controllerType,
201 int32_t &lControllerPort,
202 int32_t &lDevice);
203
204 void importOneDiskImage(const ovf::DiskImage &di,
205 Utf8Str *strTargetPath,
206 ComObjPtr<Medium> &pTargetHD,
207 ImportStack &stack,
208 PVDINTERFACEIO pCallbacks,
209 PSHASTORAGE pStorage);
210
211 void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
212 ComObjPtr<VirtualSystemDescription> &vsdescThis,
213 ComPtr<IMachine> &pNewMachine,
214 ImportStack &stack,
215 PVDINTERFACEIO pCallbacks,
216 PSHASTORAGE pStorage);
217 void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
218 ComPtr<IMachine> &pNewMachine,
219 ImportStack &stack,
220 PVDINTERFACEIO pCallbacks,
221 PSHASTORAGE pStorage);
222 void importMachines(ImportStack &stack,
223 PVDINTERFACEIO pCallbacks,
224 PSHASTORAGE pStorage);
225
226 /*******************************************************************************
227 * Write stuff
228 ******************************************************************************/
229
230 HRESULT writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
231
232 HRESULT writeFS(TaskOVF *pTask);
233 HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
234 HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
235 HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
236 HRESULT writeS3(TaskOVF *pTask);
237
238 struct XMLStack;
239
240 void buildXML(AutoWriteLockBase& writeLock,
241 xml::Document &doc,
242 XMLStack &stack,
243 const Utf8Str &strPath,
244 ovf::OVFVersion_T enFormat);
245 void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
246 xml::ElementNode &elmToAddVirtualSystemsTo,
247 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
248 ComObjPtr<VirtualSystemDescription> &vsdescThis,
249 ovf::OVFVersion_T enFormat,
250 XMLStack &stack);
251
252 HRESULT preCheckImageAvailability(PSHASTORAGE pSHAStorage,
253 RTCString &availableImage);
254
255 friend class Machine;
256};
257
258void parseURI(Utf8Str strUri, LocationInfo &locInfo);
259
260struct VirtualSystemDescriptionEntry
261{
262 uint32_t ulIndex; // zero-based index of this entry within array
263 VirtualSystemDescriptionType_T type; // type of this entry
264 Utf8Str strRef; // reference number (hard disk controllers only)
265 Utf8Str strOvf; // original OVF value (type-dependent)
266 Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
267 Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
268 Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
269 Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
270
271 uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
272};
273
274class ATL_NO_VTABLE VirtualSystemDescription :
275 public VirtualBoxBase,
276 VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
277{
278 friend class Appliance;
279
280public:
281 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
282
283 DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
284
285 DECLARE_PROTECT_FINAL_CONSTRUCT()
286
287 BEGIN_COM_MAP(VirtualSystemDescription)
288 VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualSystemDescription)
289 END_COM_MAP()
290
291 DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
292
293 // public initializer/uninitializer for internal purposes only
294 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
295 void FinalRelease() { uninit(); BaseFinalRelease(); }
296
297 HRESULT init();
298 void uninit();
299
300 /* IVirtualSystemDescription properties */
301 STDMETHOD(COMGETTER(Count))(ULONG *aCount);
302
303 /* IVirtualSystemDescription methods */
304 STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
305 ComSafeArrayOut(BSTR, aRefs),
306 ComSafeArrayOut(BSTR, aOvfValues),
307 ComSafeArrayOut(BSTR, aVboxValues),
308 ComSafeArrayOut(BSTR, aExtraConfigValues));
309
310 STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
311 ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
312 ComSafeArrayOut(BSTR, aRefs),
313 ComSafeArrayOut(BSTR, aOvfValues),
314 ComSafeArrayOut(BSTR, aVboxValues),
315 ComSafeArrayOut(BSTR, aExtraConfigValues));
316
317 STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
318 VirtualSystemDescriptionValueType_T aWhich,
319 ComSafeArrayOut(BSTR, aValues));
320
321 STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
322 ComSafeArrayIn(IN_BSTR, aVboxValues),
323 ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
324
325 STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
326 IN_BSTR aVboxValue,
327 IN_BSTR aExtraConfigValue);
328
329 /* public methods only for internal purposes */
330
331 void addEntry(VirtualSystemDescriptionType_T aType,
332 const Utf8Str &strRef,
333 const Utf8Str &aOvfValue,
334 const Utf8Str &aVboxValue,
335 uint32_t ulSizeMB = 0,
336 const Utf8Str &strExtraConfig = "");
337
338 std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
339 const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
340
341 void importVboxMachineXML(const xml::ElementNode &elmMachine);
342 const settings::MachineConfigFile* getMachineConfig() const;
343
344 void removeByType(VirtualSystemDescriptionType_T aType);
345
346 /* private instance data */
347private:
348 struct Data;
349 Data *m;
350
351 friend class Machine;
352};
353
354#endif // ____H_APPLIANCEIMPL
355/* 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