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