VirtualBox

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

Last change on this file since 75766 was 75766, checked in by vboxsync, 6 years ago

bugref:9152. Replaced the word "oci" by "cloud" in the names in the Appliance code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
Line 
1/* $Id: ApplianceImpl.h 75766 2018-11-27 11:00:10Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_APPLIANCEIMPL
19#define ____H_APPLIANCEIMPL
20
21/* VBox includes */
22#include "VirtualSystemDescriptionWrap.h"
23#include "ApplianceWrap.h"
24#include "MediumFormatImpl.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 "ovfreader.h"
30#include <set>
31
32/* VBox forward declarations */
33class Certificate;
34class Progress;
35class VirtualSystemDescription;
36struct VirtualSystemDescriptionEntry;
37struct LocationInfo;
38typedef struct VDINTERFACE *PVDINTERFACE;
39typedef struct VDINTERFACEIO *PVDINTERFACEIO;
40typedef struct SHASTORAGE *PSHASTORAGE;
41
42namespace ovf
43{
44 struct HardDiskController;
45 struct VirtualSystem;
46 class OVFReader;
47 struct DiskImage;
48 struct EnvelopeData;
49}
50
51namespace xml
52{
53 class Document;
54 class ElementNode;
55}
56
57namespace settings
58{
59 class MachineConfigFile;
60}
61
62class ATL_NO_VTABLE Appliance :
63 public ApplianceWrap
64{
65public:
66
67 DECLARE_EMPTY_CTOR_DTOR(Appliance)
68
69 HRESULT FinalConstruct();
70 void FinalRelease();
71
72
73 HRESULT init(VirtualBox *aVirtualBox);
74 void uninit();
75
76 /* public methods only for internal purposes */
77
78 static HRESULT i_setErrorStatic(HRESULT aResultCode,
79 const Utf8Str &aText)
80 {
81 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
82 }
83
84 /* private instance data */
85private:
86 // wrapped IAppliance properties
87 HRESULT getPath(com::Utf8Str &aPath);
88 HRESULT getDisks(std::vector<com::Utf8Str> &aDisks);
89 HRESULT getCertificate(ComPtr<ICertificate> &aCertificateInfo);
90 HRESULT getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions);
91 HRESULT getMachines(std::vector<com::Utf8Str> &aMachines);
92
93 // wrapped IAppliance methods
94 HRESULT read(const com::Utf8Str &aFile,
95 ComPtr<IProgress> &aProgress);
96 HRESULT interpret();
97 HRESULT importMachines(const std::vector<ImportOptions_T> &aOptions,
98 ComPtr<IProgress> &aProgress);
99 HRESULT createVFSExplorer(const com::Utf8Str &aURI,
100 ComPtr<IVFSExplorer> &aExplorer);
101 HRESULT write(const com::Utf8Str &aFormat,
102 const std::vector<ExportOptions_T> &aOptions,
103 const com::Utf8Str &aPath,
104 ComPtr<IProgress> &aProgress);
105 HRESULT getWarnings(std::vector<com::Utf8Str> &aWarnings);
106 HRESULT getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers);
107 HRESULT getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers);
108 HRESULT addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
109 const std::vector<com::Utf8Str> &aPasswords);
110
111 /** weak VirtualBox parent */
112 VirtualBox* const mVirtualBox;
113
114 struct ImportStack;
115 class TaskOVF;
116 class TaskOPC;
117 class TaskCloud;
118
119 struct Data; // opaque, defined in ApplianceImpl.cpp
120 Data *m;
121
122 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3, ExportCloud };
123
124 /** @name General stuff
125 * @{
126 */
127 bool i_isApplianceIdle();
128 HRESULT i_searchUniqueVMName(Utf8Str& aName) const;
129 HRESULT i_searchUniqueImageFilePath(const Utf8Str &aMachineFolder,
130 DeviceType_T aDeviceType,
131 Utf8Str &aName) const;
132 HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
133 const Utf8Str &strDescription,
134 SetUpProgressMode mode);
135 void i_addWarning(const char* aWarning, ...);
136 void i_disksWeight();
137 void i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
138
139 static void i_importOrExportThreadTask(TaskOVF *pTask);
140 static void i_exportOPCThreadTask(TaskOPC *pTask);
141 static void i_exportCloudThreadTask(TaskCloud *pTask);
142
143 HRESULT i_initBackendNames();
144
145 Utf8Str i_typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
146
147#if 0 /* unused */
148 std::set<Utf8Str> i_URIFromTypeOfVirtualDiskFormat(Utf8Str type);
149#endif
150
151 HRESULT i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
152
153 RTVFSIOSTREAM i_manifestSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry,
154 bool fRead = true);
155 /** @} */
156
157 /** @name Read stuff
158 * @{
159 */
160 void i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
161
162 HRESULT i_readFS(TaskOVF *pTask);
163 HRESULT i_readFSOVF(TaskOVF *pTask);
164 HRESULT i_readFSOVA(TaskOVF *pTask);
165 HRESULT i_readOVFFile(TaskOVF *pTask, RTVFSIOSTREAM hIosOvf, const char *pszManifestEntry);
166 HRESULT i_readManifestFile(TaskOVF *pTask, RTVFSIOSTREAM hIosMf, const char *pszSubFileNm);
167 HRESULT i_readSignatureFile(TaskOVF *pTask, RTVFSIOSTREAM hIosCert, const char *pszSubFileNm);
168 HRESULT i_readTailProcessing(TaskOVF *pTask);
169 /** @} */
170
171 /** @name Import stuff
172 * @}
173 */
174 HRESULT i_importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
175
176 HRESULT i_importFS(TaskOVF *pTask);
177 HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
178 HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase &rWriteLock);
179 HRESULT i_importDoIt(TaskOVF *pTask, AutoWriteLockBase &rWriteLock, RTVFSFSSTREAM hVfsFssOva = NIL_RTVFSFSSTREAM);
180
181 HRESULT i_verifyManifestFile(ImportStack &stack);
182
183 void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
184 uint32_t ulAddressOnParent,
185 Utf8Str &controllerName,
186 int32_t &lControllerPort,
187 int32_t &lDevice);
188
189 void i_importOneDiskImage(const ovf::DiskImage &di,
190 const Utf8Str &strDstPath,
191 ComObjPtr<Medium> &pTargetMedium,
192 ImportStack &stack);
193
194 void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
195 ComObjPtr<VirtualSystemDescription> &vsdescThis,
196 ComPtr<IMachine> &pNewMachine,
197 ImportStack &stack);
198 void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
199 ComPtr<IMachine> &pNewMachine,
200 ImportStack &stack);
201 void i_importMachines(ImportStack &stack);
202
203 HRESULT i_preCheckImageAvailability(ImportStack &stack);
204 bool i_importEnsureOvaLookAhead(ImportStack &stack);
205 RTVFSIOSTREAM i_importOpenSourceFile(ImportStack &stack, Utf8Str const &rstrSrcPath, const char *pszManifestEntry);
206 HRESULT i_importCreateAndWriteDestinationFile(Utf8Str const &rstrDstPath,
207 RTVFSIOSTREAM hVfsIosSrc, Utf8Str const &rstrSrcLogNm);
208
209 void i_importCopyFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
210 const char *pszManifestEntry);
211 void i_importDecompressFile(ImportStack &stack, Utf8Str const &rstrSrcPath, Utf8Str const &rstrDstPath,
212 const char *pszManifestEntry);
213 /** @} */
214
215 /** @name Write stuff
216 * @{
217 */
218 HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
219 HRESULT i_writeOPCImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
220 HRESULT i_writeCloudImpl(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_writeFSOPC(TaskOPC *pTask);
226 HRESULT i_writeFSCloud(TaskCloud *pTask);
227 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase &writeLock, RTVFSFSSTREAM hVfsFssDst);
228 HRESULT i_writeBufferToFile(RTVFSFSSTREAM hVfsFssDst, const char *pszFilename, const void *pvContent, size_t cbContent);
229
230 struct XMLStack;
231
232 void i_buildXML(AutoWriteLockBase& writeLock,
233 xml::Document &doc,
234 XMLStack &stack,
235 const Utf8Str &strPath,
236 ovf::OVFVersion_T enFormat);
237 void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
238 xml::ElementNode &elmToAddVirtualSystemsTo,
239 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
240 ComObjPtr<VirtualSystemDescription> &vsdescThis,
241 ovf::OVFVersion_T enFormat,
242 XMLStack &stack);
243 /** @} */
244
245 friend class Machine;
246 friend class Certificate;
247};
248
249void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
250
251struct VirtualSystemDescriptionEntry
252{
253 uint32_t ulIndex; ///< zero-based index of this entry within array
254 VirtualSystemDescriptionType_T type; ///< type of this entry
255 Utf8Str strRef; ///< reference number (hard disk controllers only)
256 Utf8Str strOvf; ///< original OVF value (type-dependent)
257 Utf8Str strVBoxSuggested; ///< configuration value (type-dependent); original value suggested by interpret()
258 Utf8Str strVBoxCurrent; ///< configuration value (type-dependent); current value, either from interpret() or setFinalValue()
259 Utf8Str strExtraConfigSuggested; ///< extra configuration key=value strings (type-dependent); original value suggested by interpret()
260 Utf8Str strExtraConfigCurrent; ///< extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
261
262 uint32_t ulSizeMB; ///< hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
263 bool skipIt; ///< used during export to skip some parts if it's needed
264};
265
266class ATL_NO_VTABLE VirtualSystemDescription :
267 public VirtualSystemDescriptionWrap
268{
269 friend class Appliance;
270
271public:
272
273 DECLARE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
274
275 HRESULT FinalConstruct();
276 void FinalRelease();
277
278 HRESULT init();
279 void uninit();
280
281 /* public methods only for internal purposes */
282 void i_addEntry(VirtualSystemDescriptionType_T aType,
283 const Utf8Str &strRef,
284 const Utf8Str &aOvfValue,
285 const Utf8Str &aVBoxValue,
286 uint32_t ulSizeMB = 0,
287 const Utf8Str &strExtraConfig = "");
288
289 std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
290 const VirtualSystemDescriptionEntry* i_findControllerFromID(uint32_t id);
291
292 void i_importVBoxMachineXML(const xml::ElementNode &elmMachine);
293 const settings::MachineConfigFile* i_getMachineConfig() const;
294
295 /* private instance data */
296private:
297
298 // wrapped IVirtualSystemDescription properties
299 HRESULT getCount(ULONG *aCount);
300
301 // wrapped IVirtualSystemDescription methods
302 HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
303 std::vector<com::Utf8Str> &aRefs,
304 std::vector<com::Utf8Str> &aOVFValues,
305 std::vector<com::Utf8Str> &aVBoxValues,
306 std::vector<com::Utf8Str> &aExtraConfigValues);
307 HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
308 std::vector<VirtualSystemDescriptionType_T> &aTypes,
309 std::vector<com::Utf8Str> &aRefs,
310 std::vector<com::Utf8Str> &aOVFValues,
311 std::vector<com::Utf8Str> &aVBoxValues,
312 std::vector<com::Utf8Str> &aExtraConfigValues);
313 HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
314 VirtualSystemDescriptionValueType_T aWhich,
315 std::vector<com::Utf8Str> &aValues);
316 HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
317 const std::vector<com::Utf8Str> &aVBoxValues,
318 const std::vector<com::Utf8Str> &aExtraConfigValues);
319 HRESULT addDescription(VirtualSystemDescriptionType_T aType,
320 const com::Utf8Str &aVBoxValue,
321 const com::Utf8Str &aExtraConfigValue);
322 void i_removeByType(VirtualSystemDescriptionType_T aType);
323
324 struct Data;
325 Data *m;
326
327 friend class Machine;
328};
329
330#endif // !____H_APPLIANCEIMPL
331/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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