VirtualBox

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

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

bugref:9416. Added new API function \'IAppliance::createVirtualSystemDescriptions\'

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