1 | /* $Id: ApplianceImpl.cpp 91416 2021-09-28 06:15:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IAppliance and IVirtualSystem COM class implementations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2020 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 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_MAIN_APPLIANCE
|
---|
23 | #include <iprt/path.h>
|
---|
24 | #include <iprt/cpp/path.h>
|
---|
25 | #include <iprt/cpp/utils.h>
|
---|
26 | #include <VBox/com/array.h>
|
---|
27 | #include <map>
|
---|
28 |
|
---|
29 | #include "ApplianceImpl.h"
|
---|
30 | #include "VFSExplorerImpl.h"
|
---|
31 | #include "VirtualBoxImpl.h"
|
---|
32 | #include "GuestOSTypeImpl.h"
|
---|
33 | #include "Global.h"
|
---|
34 | #include "ProgressImpl.h"
|
---|
35 | #include "MachineImpl.h"
|
---|
36 | #include "SystemPropertiesImpl.h"
|
---|
37 | #include "AutoCaller.h"
|
---|
38 | #include "LoggingNew.h"
|
---|
39 | #include "CertificateImpl.h"
|
---|
40 |
|
---|
41 | #include "ApplianceImplPrivate.h"
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 |
|
---|
46 | /*********************************************************************************************************************************
|
---|
47 | * Global Variables *
|
---|
48 | *********************************************************************************************************************************/
|
---|
49 | static const char * const g_pszISOURI = "http://www.ecma-international.org/publications/standards/Ecma-119.htm";
|
---|
50 | static const char * const g_pszVMDKStreamURI = "http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized";
|
---|
51 | static const char * const g_pszVMDKSparseURI = "http://www.vmware.com/specifications/vmdk.html#sparse";
|
---|
52 | static const char * const g_pszVMDKCompressedURI = "http://www.vmware.com/specifications/vmdk.html#compressed";
|
---|
53 | static const char * const g_pszVMDKCompressedURI2 = "http://www.vmware.com/interfaces/specifications/vmdk.html#compressed";
|
---|
54 | static const char * const g_pszrVHDURI = "http://go.microsoft.com/fwlink/?LinkId=137171";
|
---|
55 | static char g_szIsoBackend[128];
|
---|
56 | static char g_szVmdkBackend[128];
|
---|
57 | static char g_szVhdBackend[128];
|
---|
58 | /** Set after the g_szXxxxBackend variables has been initialized. */
|
---|
59 | static bool volatile g_fInitializedBackendNames = false;
|
---|
60 |
|
---|
61 | static struct
|
---|
62 | {
|
---|
63 | const char *pszUri, *pszBackend;
|
---|
64 | } const g_aUriToBackend[] =
|
---|
65 | {
|
---|
66 | { g_pszISOURI, g_szIsoBackend },
|
---|
67 | { g_pszVMDKStreamURI, g_szVmdkBackend },
|
---|
68 | { g_pszVMDKSparseURI, g_szVmdkBackend },
|
---|
69 | { g_pszVMDKCompressedURI, g_szVmdkBackend },
|
---|
70 | { g_pszVMDKCompressedURI2, g_szVmdkBackend },
|
---|
71 | { g_pszrVHDURI, g_szVhdBackend },
|
---|
72 | };
|
---|
73 |
|
---|
74 | static std::map<Utf8Str, Utf8Str> supportedStandardsURI;
|
---|
75 |
|
---|
76 | static struct
|
---|
77 | {
|
---|
78 | ovf::CIMOSType_T cim;
|
---|
79 | VBOXOSTYPE osType;
|
---|
80 | } const g_aOsTypes[] =
|
---|
81 | {
|
---|
82 | { ovf::CIMOSType_CIMOS_Unknown, VBOXOSTYPE_Unknown },
|
---|
83 | { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2 },
|
---|
84 | { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp3 },
|
---|
85 | { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp4 },
|
---|
86 | { ovf::CIMOSType_CIMOS_OS2, VBOXOSTYPE_OS2Warp45 },
|
---|
87 | { ovf::CIMOSType_CIMOS_MSDOS, VBOXOSTYPE_DOS },
|
---|
88 | { ovf::CIMOSType_CIMOS_WIN3x, VBOXOSTYPE_Win31 },
|
---|
89 | { ovf::CIMOSType_CIMOS_WIN95, VBOXOSTYPE_Win95 },
|
---|
90 | { ovf::CIMOSType_CIMOS_WIN98, VBOXOSTYPE_Win98 },
|
---|
91 | { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT },
|
---|
92 | { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT4 },
|
---|
93 | { ovf::CIMOSType_CIMOS_WINNT, VBOXOSTYPE_WinNT3x },
|
---|
94 | { ovf::CIMOSType_CIMOS_NetWare, VBOXOSTYPE_Netware },
|
---|
95 | { ovf::CIMOSType_CIMOS_NovellOES, VBOXOSTYPE_Netware },
|
---|
96 | { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_Solaris },
|
---|
97 | { ovf::CIMOSType_CIMOS_SunOS, VBOXOSTYPE_Solaris },
|
---|
98 | { ovf::CIMOSType_CIMOS_FreeBSD, VBOXOSTYPE_FreeBSD },
|
---|
99 | { ovf::CIMOSType_CIMOS_NetBSD, VBOXOSTYPE_NetBSD },
|
---|
100 | { ovf::CIMOSType_CIMOS_QNX, VBOXOSTYPE_QNX },
|
---|
101 | { ovf::CIMOSType_CIMOS_Windows2000, VBOXOSTYPE_Win2k },
|
---|
102 | { ovf::CIMOSType_CIMOS_WindowsMe, VBOXOSTYPE_WinMe },
|
---|
103 | { ovf::CIMOSType_CIMOS_OpenBSD, VBOXOSTYPE_OpenBSD },
|
---|
104 | { ovf::CIMOSType_CIMOS_WindowsXP, VBOXOSTYPE_WinXP },
|
---|
105 | { ovf::CIMOSType_CIMOS_WindowsXPEmbedded, VBOXOSTYPE_WinXP },
|
---|
106 | { ovf::CIMOSType_CIMOS_WindowsEmbeddedforPointofService, VBOXOSTYPE_WinXP },
|
---|
107 | { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003, VBOXOSTYPE_Win2k3 },
|
---|
108 | { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2003_64, VBOXOSTYPE_Win2k3_x64 },
|
---|
109 | { ovf::CIMOSType_CIMOS_WindowsXP_64, VBOXOSTYPE_WinXP_x64 },
|
---|
110 | { ovf::CIMOSType_CIMOS_WindowsVista, VBOXOSTYPE_WinVista },
|
---|
111 | { ovf::CIMOSType_CIMOS_WindowsVista_64, VBOXOSTYPE_WinVista_x64 },
|
---|
112 | { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008, VBOXOSTYPE_Win2k8 },
|
---|
113 | { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008_64, VBOXOSTYPE_Win2k8_x64 },
|
---|
114 | { ovf::CIMOSType_CIMOS_FreeBSD_64, VBOXOSTYPE_FreeBSD_x64 },
|
---|
115 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS },
|
---|
116 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS_x64 }, // there is no CIM 64-bit type for this
|
---|
117 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106 },
|
---|
118 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106_x64 },
|
---|
119 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS107_x64 },
|
---|
120 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS108_x64 },
|
---|
121 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS109_x64 },
|
---|
122 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1010_x64 },
|
---|
123 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1011_x64 },
|
---|
124 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1012_x64 },
|
---|
125 | { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS1013_x64 },
|
---|
126 |
|
---|
127 | // Linuxes
|
---|
128 | { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux, VBOXOSTYPE_RedHat },
|
---|
129 | { ovf::CIMOSType_CIMOS_RedHatEnterpriseLinux_64, VBOXOSTYPE_RedHat_x64 },
|
---|
130 | { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_Solaris_x64 },
|
---|
131 | { ovf::CIMOSType_CIMOS_SUSE, VBOXOSTYPE_OpenSUSE },
|
---|
132 | { ovf::CIMOSType_CIMOS_SLES, VBOXOSTYPE_OpenSUSE },
|
---|
133 | { ovf::CIMOSType_CIMOS_NovellLinuxDesktop, VBOXOSTYPE_OpenSUSE },
|
---|
134 | { ovf::CIMOSType_CIMOS_SUSE_64, VBOXOSTYPE_OpenSUSE_x64 },
|
---|
135 | { ovf::CIMOSType_CIMOS_SLES_64, VBOXOSTYPE_OpenSUSE_x64 },
|
---|
136 | { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux },
|
---|
137 | { ovf::CIMOSType_CIMOS_LINUX, VBOXOSTYPE_Linux22 },
|
---|
138 | { ovf::CIMOSType_CIMOS_SunJavaDesktopSystem, VBOXOSTYPE_Linux },
|
---|
139 | { ovf::CIMOSType_CIMOS_TurboLinux, VBOXOSTYPE_Turbolinux },
|
---|
140 | { ovf::CIMOSType_CIMOS_TurboLinux_64, VBOXOSTYPE_Turbolinux_x64 },
|
---|
141 | { ovf::CIMOSType_CIMOS_Mandriva, VBOXOSTYPE_Mandriva },
|
---|
142 | { ovf::CIMOSType_CIMOS_Mandriva_64, VBOXOSTYPE_Mandriva_x64 },
|
---|
143 | { ovf::CIMOSType_CIMOS_Ubuntu, VBOXOSTYPE_Ubuntu },
|
---|
144 | { ovf::CIMOSType_CIMOS_Ubuntu_64, VBOXOSTYPE_Ubuntu_x64 },
|
---|
145 | { ovf::CIMOSType_CIMOS_Debian, VBOXOSTYPE_Debian },
|
---|
146 | { ovf::CIMOSType_CIMOS_Debian_64, VBOXOSTYPE_Debian_x64 },
|
---|
147 | { ovf::CIMOSType_CIMOS_Linux_2_4_x, VBOXOSTYPE_Linux24 },
|
---|
148 | { ovf::CIMOSType_CIMOS_Linux_2_4_x_64, VBOXOSTYPE_Linux24_x64 },
|
---|
149 | { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Linux26 },
|
---|
150 | { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Linux26_x64 },
|
---|
151 | { ovf::CIMOSType_CIMOS_Linux_64, VBOXOSTYPE_Linux26_x64 },
|
---|
152 |
|
---|
153 | // types that we have support for but CIM doesn't
|
---|
154 | { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_ArchLinux },
|
---|
155 | { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_ArchLinux_x64 },
|
---|
156 | { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_FedoraCore },
|
---|
157 | { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_FedoraCore_x64 },
|
---|
158 | { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Gentoo },
|
---|
159 | { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Gentoo_x64 },
|
---|
160 | { ovf::CIMOSType_CIMOS_Linux_2_6_x, VBOXOSTYPE_Xandros },
|
---|
161 | { ovf::CIMOSType_CIMOS_Linux_2_6_x_64, VBOXOSTYPE_Xandros_x64 },
|
---|
162 | { ovf::CIMOSType_CIMOS_Solaris, VBOXOSTYPE_OpenSolaris },
|
---|
163 | { ovf::CIMOSType_CIMOS_Solaris_64, VBOXOSTYPE_OpenSolaris_x64 },
|
---|
164 |
|
---|
165 | // types added with CIM 2.25.0 follow:
|
---|
166 | { ovf::CIMOSType_CIMOS_WindowsServer2008R2, VBOXOSTYPE_Win2k8 }, // duplicate, see above
|
---|
167 | // { ovf::CIMOSType_CIMOS_VMwareESXi = 104, // we can't run ESX in a VM
|
---|
168 | { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7 },
|
---|
169 | { ovf::CIMOSType_CIMOS_Windows7, VBOXOSTYPE_Win7_x64 }, // there is no
|
---|
170 | // CIM 64-bit type for this
|
---|
171 | { ovf::CIMOSType_CIMOS_CentOS, VBOXOSTYPE_RedHat },
|
---|
172 | { ovf::CIMOSType_CIMOS_CentOS_64, VBOXOSTYPE_RedHat_x64 },
|
---|
173 | { ovf::CIMOSType_CIMOS_OracleLinux, VBOXOSTYPE_Oracle },
|
---|
174 | { ovf::CIMOSType_CIMOS_OracleLinux_64, VBOXOSTYPE_Oracle_x64 },
|
---|
175 | { ovf::CIMOSType_CIMOS_eComStation, VBOXOSTYPE_ECS },
|
---|
176 |
|
---|
177 | { ovf::CIMOSType_CIMOS_WindowsServer2011, VBOXOSTYPE_Win2k8_x64 }, // no 1:1 match on the VBox side
|
---|
178 | { ovf::CIMOSType_CIMOS_WindowsServer2012, VBOXOSTYPE_Win2k12_x64 },
|
---|
179 | { ovf::CIMOSType_CIMOS_Windows8, VBOXOSTYPE_Win8 },
|
---|
180 | { ovf::CIMOSType_CIMOS_Windows8_64, VBOXOSTYPE_Win8_x64 },
|
---|
181 | { ovf::CIMOSType_CIMOS_WindowsServer2012R2, VBOXOSTYPE_Win2k12_x64 },
|
---|
182 | { ovf::CIMOSType_CIMOS_Windows8_1, VBOXOSTYPE_Win81 },
|
---|
183 | { ovf::CIMOSType_CIMOS_Windows8_1_64, VBOXOSTYPE_Win81_x64 },
|
---|
184 | { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k16_x64 },
|
---|
185 | { ovf::CIMOSType_CIMOS_Windows10, VBOXOSTYPE_Win10 },
|
---|
186 | { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
|
---|
187 | { ovf::CIMOSType_CIMOS_Windows10_64, VBOXOSTYPE_Win10_x64 },
|
---|
188 | { ovf::CIMOSType_CIMOS_WindowsServer2016, VBOXOSTYPE_Win2k19_x64 }, // no CIM type for this yet
|
---|
189 |
|
---|
190 | // there are no CIM types for these, so these turn to "other" on export:
|
---|
191 | // VBOXOSTYPE_OpenBSD
|
---|
192 | // VBOXOSTYPE_OpenBSD_x64
|
---|
193 | // VBOXOSTYPE_NetBSD
|
---|
194 | // VBOXOSTYPE_NetBSD_x64
|
---|
195 |
|
---|
196 | };
|
---|
197 |
|
---|
198 | /* Pattern structure for matching the OS type description field */
|
---|
199 | struct osTypePattern
|
---|
200 | {
|
---|
201 | const char *pcszPattern;
|
---|
202 | VBOXOSTYPE osType;
|
---|
203 | };
|
---|
204 |
|
---|
205 | /* These are the 32-Bit ones. They are sorted by priority. */
|
---|
206 | static const osTypePattern g_aOsTypesPattern[] =
|
---|
207 | {
|
---|
208 | {"Windows NT", VBOXOSTYPE_WinNT4},
|
---|
209 | {"Windows XP", VBOXOSTYPE_WinXP},
|
---|
210 | {"Windows 2000", VBOXOSTYPE_Win2k},
|
---|
211 | {"Windows 2003", VBOXOSTYPE_Win2k3},
|
---|
212 | {"Windows Vista", VBOXOSTYPE_WinVista},
|
---|
213 | {"Windows 2008", VBOXOSTYPE_Win2k8},
|
---|
214 | {"Windows 7", VBOXOSTYPE_Win7},
|
---|
215 | {"Windows 8.1", VBOXOSTYPE_Win81},
|
---|
216 | {"Windows 8", VBOXOSTYPE_Win8},
|
---|
217 | {"Windows 10", VBOXOSTYPE_Win10},
|
---|
218 | {"SUSE", VBOXOSTYPE_OpenSUSE},
|
---|
219 | {"Novell", VBOXOSTYPE_OpenSUSE},
|
---|
220 | {"Red Hat", VBOXOSTYPE_RedHat},
|
---|
221 | {"Mandriva", VBOXOSTYPE_Mandriva},
|
---|
222 | {"Ubuntu", VBOXOSTYPE_Ubuntu},
|
---|
223 | {"Debian", VBOXOSTYPE_Debian},
|
---|
224 | {"QNX", VBOXOSTYPE_QNX},
|
---|
225 | {"Linux 2.4", VBOXOSTYPE_Linux24},
|
---|
226 | {"Linux 2.6", VBOXOSTYPE_Linux26},
|
---|
227 | {"Linux", VBOXOSTYPE_Linux},
|
---|
228 | {"OpenSolaris", VBOXOSTYPE_OpenSolaris},
|
---|
229 | {"Solaris", VBOXOSTYPE_OpenSolaris},
|
---|
230 | {"FreeBSD", VBOXOSTYPE_FreeBSD},
|
---|
231 | {"NetBSD", VBOXOSTYPE_NetBSD},
|
---|
232 | {"Windows 95", VBOXOSTYPE_Win95},
|
---|
233 | {"Windows 98", VBOXOSTYPE_Win98},
|
---|
234 | {"Windows Me", VBOXOSTYPE_WinMe},
|
---|
235 | {"Windows 3.", VBOXOSTYPE_Win31},
|
---|
236 | {"DOS", VBOXOSTYPE_DOS},
|
---|
237 | {"OS2", VBOXOSTYPE_OS2}
|
---|
238 | };
|
---|
239 |
|
---|
240 | /* These are the 64-Bit ones. They are sorted by priority. */
|
---|
241 | static const osTypePattern g_aOsTypesPattern64[] =
|
---|
242 | {
|
---|
243 | {"Windows XP", VBOXOSTYPE_WinXP_x64},
|
---|
244 | {"Windows 2003", VBOXOSTYPE_Win2k3_x64},
|
---|
245 | {"Windows Vista", VBOXOSTYPE_WinVista_x64},
|
---|
246 | {"Windows 2008", VBOXOSTYPE_Win2k8_x64},
|
---|
247 | {"Windows 7", VBOXOSTYPE_Win7_x64},
|
---|
248 | {"Windows 8.1", VBOXOSTYPE_Win81_x64},
|
---|
249 | {"Windows 8", VBOXOSTYPE_Win8_x64},
|
---|
250 | {"Windows 2012", VBOXOSTYPE_Win2k12_x64},
|
---|
251 | {"Windows 10", VBOXOSTYPE_Win10_x64},
|
---|
252 | {"Windows 2016", VBOXOSTYPE_Win2k16_x64},
|
---|
253 | {"Windows 2019", VBOXOSTYPE_Win2k19_x64},
|
---|
254 | {"SUSE", VBOXOSTYPE_OpenSUSE_x64},
|
---|
255 | {"Novell", VBOXOSTYPE_OpenSUSE_x64},
|
---|
256 | {"Red Hat", VBOXOSTYPE_RedHat_x64},
|
---|
257 | {"Mandriva", VBOXOSTYPE_Mandriva_x64},
|
---|
258 | {"Ubuntu", VBOXOSTYPE_Ubuntu_x64},
|
---|
259 | {"Debian", VBOXOSTYPE_Debian_x64},
|
---|
260 | {"Linux 2.4", VBOXOSTYPE_Linux24_x64},
|
---|
261 | {"Linux 2.6", VBOXOSTYPE_Linux26_x64},
|
---|
262 | {"Linux", VBOXOSTYPE_Linux26_x64},
|
---|
263 | {"OpenSolaris", VBOXOSTYPE_OpenSolaris_x64},
|
---|
264 | {"Solaris", VBOXOSTYPE_OpenSolaris_x64},
|
---|
265 | {"FreeBSD", VBOXOSTYPE_FreeBSD_x64},
|
---|
266 | };
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Private helper func that suggests a VirtualBox guest OS type
|
---|
270 | * for the given OVF operating system type.
|
---|
271 | */
|
---|
272 | void convertCIMOSType2VBoxOSType(Utf8Str &strType, ovf::CIMOSType_T c, const Utf8Str &cStr)
|
---|
273 | {
|
---|
274 | /* First check if the type is other/other_64 */
|
---|
275 | if (c == ovf::CIMOSType_CIMOS_Other)
|
---|
276 | {
|
---|
277 | for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern); ++i)
|
---|
278 | if (cStr.contains(g_aOsTypesPattern[i].pcszPattern, Utf8Str::CaseInsensitive))
|
---|
279 | {
|
---|
280 | strType = Global::OSTypeId(g_aOsTypesPattern[i].osType);
|
---|
281 | return;
|
---|
282 | }
|
---|
283 | }
|
---|
284 | else if (c == ovf::CIMOSType_CIMOS_Other_64)
|
---|
285 | {
|
---|
286 | for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypesPattern64); ++i)
|
---|
287 | if (cStr.contains(g_aOsTypesPattern64[i].pcszPattern, Utf8Str::CaseInsensitive))
|
---|
288 | {
|
---|
289 | strType = Global::OSTypeId(g_aOsTypesPattern64[i].osType);
|
---|
290 | return;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
|
---|
295 | {
|
---|
296 | if (c == g_aOsTypes[i].cim)
|
---|
297 | {
|
---|
298 | strType = Global::OSTypeId(g_aOsTypes[i].osType);
|
---|
299 | return;
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | if (c == ovf::CIMOSType_CIMOS_Other_64)
|
---|
304 | strType = Global::OSTypeId(VBOXOSTYPE_Unknown_x64);
|
---|
305 | else
|
---|
306 | strType = Global::OSTypeId(VBOXOSTYPE_Unknown);
|
---|
307 | }
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Private helper func that suggests a VirtualBox guest OS type
|
---|
311 | * for the given OVF operating system type.
|
---|
312 | * @returns CIM OS type.
|
---|
313 | * @param pcszVBox Our guest OS type identifier string.
|
---|
314 | * @param fLongMode Whether long mode is enabled and a 64-bit CIM type is
|
---|
315 | * preferred even if the VBox guest type isn't 64-bit.
|
---|
316 | */
|
---|
317 | ovf::CIMOSType_T convertVBoxOSType2CIMOSType(const char *pcszVBox, BOOL fLongMode)
|
---|
318 | {
|
---|
319 | for (size_t i = 0; i < RT_ELEMENTS(g_aOsTypes); ++i)
|
---|
320 | {
|
---|
321 | if (!RTStrICmp(pcszVBox, Global::OSTypeId(g_aOsTypes[i].osType)))
|
---|
322 | {
|
---|
323 | if (fLongMode && !(g_aOsTypes[i].osType & VBOXOSTYPE_x64))
|
---|
324 | {
|
---|
325 | VBOXOSTYPE enmDesiredOsType = (VBOXOSTYPE)((int)g_aOsTypes[i].osType | (int)VBOXOSTYPE_x64);
|
---|
326 | for (size_t j = i+1; j < RT_ELEMENTS(g_aOsTypes); j++)
|
---|
327 | if (g_aOsTypes[j].osType == enmDesiredOsType)
|
---|
328 | return g_aOsTypes[j].cim;
|
---|
329 | if (i > 0)
|
---|
330 | {
|
---|
331 | for (size_t j = i-1; j > 0; j++)
|
---|
332 | if (g_aOsTypes[j].osType == enmDesiredOsType)
|
---|
333 | return g_aOsTypes[j].cim;
|
---|
334 | }
|
---|
335 | /* Not all OSes have 64-bit versions, so just return the 32-bit variant. */
|
---|
336 | }
|
---|
337 | return g_aOsTypes[i].cim;
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | return fLongMode ? ovf::CIMOSType_CIMOS_Other_64 : ovf::CIMOSType_CIMOS_Other;
|
---|
342 | }
|
---|
343 |
|
---|
344 | Utf8Str convertNetworkAttachmentTypeToString(NetworkAttachmentType_T type)
|
---|
345 | {
|
---|
346 | Utf8Str strType;
|
---|
347 | switch (type)
|
---|
348 | {
|
---|
349 | case NetworkAttachmentType_NAT: strType = "NAT"; break;
|
---|
350 | case NetworkAttachmentType_Bridged: strType = "Bridged"; break;
|
---|
351 | case NetworkAttachmentType_Internal: strType = "Internal"; break;
|
---|
352 | case NetworkAttachmentType_HostOnly: strType = "HostOnly"; break;
|
---|
353 | case NetworkAttachmentType_HostOnlyNetwork: strType = "HostOnlyNetwork"; break;
|
---|
354 | case NetworkAttachmentType_Generic: strType = "Generic"; break;
|
---|
355 | case NetworkAttachmentType_NATNetwork: strType = "NATNetwork"; break;
|
---|
356 | case NetworkAttachmentType_Null: strType = "Null"; break;
|
---|
357 | case NetworkAttachmentType_Cloud: strType = "Cloud"; break;
|
---|
358 | #ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
|
---|
359 | case NetworkAttachmentType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
|
---|
360 | #endif
|
---|
361 | }
|
---|
362 | return strType;
|
---|
363 | }
|
---|
364 |
|
---|
365 |
|
---|
366 | ////////////////////////////////////////////////////////////////////////////////
|
---|
367 | //
|
---|
368 | // Appliance constructor / destructor
|
---|
369 | //
|
---|
370 | // ////////////////////////////////////////////////////////////////////////////////
|
---|
371 |
|
---|
372 | DEFINE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
|
---|
373 |
|
---|
374 | HRESULT VirtualSystemDescription::FinalConstruct()
|
---|
375 | {
|
---|
376 | return BaseFinalConstruct();
|
---|
377 | }
|
---|
378 |
|
---|
379 | void VirtualSystemDescription::FinalRelease()
|
---|
380 | {
|
---|
381 | uninit();
|
---|
382 |
|
---|
383 | BaseFinalRelease();
|
---|
384 | }
|
---|
385 |
|
---|
386 | Appliance::Appliance()
|
---|
387 | : mVirtualBox(NULL)
|
---|
388 | {
|
---|
389 | }
|
---|
390 |
|
---|
391 | Appliance::~Appliance()
|
---|
392 | {
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | HRESULT Appliance::FinalConstruct()
|
---|
397 | {
|
---|
398 | return BaseFinalConstruct();
|
---|
399 | }
|
---|
400 |
|
---|
401 | void Appliance::FinalRelease()
|
---|
402 | {
|
---|
403 | uninit();
|
---|
404 |
|
---|
405 | BaseFinalRelease();
|
---|
406 | }
|
---|
407 |
|
---|
408 |
|
---|
409 | ////////////////////////////////////////////////////////////////////////////////
|
---|
410 | //
|
---|
411 | // Internal helpers
|
---|
412 | //
|
---|
413 | ////////////////////////////////////////////////////////////////////////////////
|
---|
414 |
|
---|
415 |
|
---|
416 | ////////////////////////////////////////////////////////////////////////////////
|
---|
417 | //
|
---|
418 | // IVirtualBox public methods
|
---|
419 | //
|
---|
420 | ////////////////////////////////////////////////////////////////////////////////
|
---|
421 |
|
---|
422 | // This code is here so we won't have to include the appliance headers in the
|
---|
423 | // IVirtualBox implementation.
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * Implementation for IVirtualBox::createAppliance.
|
---|
427 | *
|
---|
428 | * @param aAppliance IAppliance object created if S_OK is returned.
|
---|
429 | * @return S_OK or error.
|
---|
430 | */
|
---|
431 | HRESULT VirtualBox::createAppliance(ComPtr<IAppliance> &aAppliance)
|
---|
432 | {
|
---|
433 | ComObjPtr<Appliance> appliance;
|
---|
434 | HRESULT hrc = appliance.createObject();
|
---|
435 | if (SUCCEEDED(hrc))
|
---|
436 | {
|
---|
437 | hrc = appliance->init(this);
|
---|
438 | if (SUCCEEDED(hrc))
|
---|
439 | hrc = appliance.queryInterfaceTo(aAppliance.asOutParam());
|
---|
440 | }
|
---|
441 | return hrc;
|
---|
442 | }
|
---|
443 |
|
---|
444 | /**
|
---|
445 | * Appliance COM initializer.
|
---|
446 | * @param aVirtualBox The VirtualBox object.
|
---|
447 | */
|
---|
448 | HRESULT Appliance::init(VirtualBox *aVirtualBox)
|
---|
449 | {
|
---|
450 | HRESULT rc = S_OK;
|
---|
451 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
452 | AutoInitSpan autoInitSpan(this);
|
---|
453 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
454 |
|
---|
455 | /* Weak reference to a VirtualBox object */
|
---|
456 | unconst(mVirtualBox) = aVirtualBox;
|
---|
457 |
|
---|
458 | // initialize data
|
---|
459 | m = new Data;
|
---|
460 | m->m_pSecretKeyStore = new SecretKeyStore(false /* fRequireNonPageable*/);
|
---|
461 | AssertReturn(m->m_pSecretKeyStore, E_FAIL);
|
---|
462 |
|
---|
463 | rc = i_initBackendNames();
|
---|
464 |
|
---|
465 | /* Confirm a successful initialization */
|
---|
466 | autoInitSpan.setSucceeded();
|
---|
467 |
|
---|
468 | return rc;
|
---|
469 | }
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * Appliance COM uninitializer.
|
---|
473 | */
|
---|
474 | void Appliance::uninit()
|
---|
475 | {
|
---|
476 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
477 | AutoUninitSpan autoUninitSpan(this);
|
---|
478 | if (autoUninitSpan.uninitDone())
|
---|
479 | return;
|
---|
480 |
|
---|
481 | if (m->m_pSecretKeyStore)
|
---|
482 | delete m->m_pSecretKeyStore;
|
---|
483 |
|
---|
484 | delete m;
|
---|
485 | m = NULL;
|
---|
486 | }
|
---|
487 |
|
---|
488 | ////////////////////////////////////////////////////////////////////////////////
|
---|
489 | //
|
---|
490 | // IAppliance public methods
|
---|
491 | //
|
---|
492 | ////////////////////////////////////////////////////////////////////////////////
|
---|
493 |
|
---|
494 | /**
|
---|
495 | * Public method implementation.
|
---|
496 | */
|
---|
497 | HRESULT Appliance::getPath(com::Utf8Str &aPath)
|
---|
498 | {
|
---|
499 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
500 |
|
---|
501 | aPath = m->locInfo.strPath;
|
---|
502 |
|
---|
503 | return S_OK;
|
---|
504 | }
|
---|
505 |
|
---|
506 | /**
|
---|
507 | * Public method implementation.
|
---|
508 | */
|
---|
509 | HRESULT Appliance::getDisks(std::vector<com::Utf8Str> &aDisks)
|
---|
510 | {
|
---|
511 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
512 |
|
---|
513 | aDisks.resize(0);
|
---|
514 |
|
---|
515 | if (m->pReader) // OVFReader instantiated?
|
---|
516 | {
|
---|
517 | aDisks.resize(m->pReader->m_mapDisks.size());
|
---|
518 |
|
---|
519 | ovf::DiskImagesMap::const_iterator it;
|
---|
520 | size_t i = 0;
|
---|
521 | for (it = m->pReader->m_mapDisks.begin();
|
---|
522 | it != m->pReader->m_mapDisks.end();
|
---|
523 | ++it, ++i)
|
---|
524 | {
|
---|
525 | // create a string representing this disk
|
---|
526 | const ovf::DiskImage &d = it->second;
|
---|
527 | char *psz = NULL;
|
---|
528 | RTStrAPrintf(&psz,
|
---|
529 | "%s\t"
|
---|
530 | "%RI64\t"
|
---|
531 | "%RI64\t"
|
---|
532 | "%s\t"
|
---|
533 | "%s\t"
|
---|
534 | "%RI64\t"
|
---|
535 | "%RI64\t"
|
---|
536 | "%s",
|
---|
537 | d.strDiskId.c_str(),
|
---|
538 | d.iCapacity,
|
---|
539 | d.iPopulatedSize,
|
---|
540 | d.strFormat.c_str(),
|
---|
541 | d.strHref.c_str(),
|
---|
542 | d.iSize,
|
---|
543 | d.iChunkSize,
|
---|
544 | d.strCompression.c_str());
|
---|
545 | Utf8Str utf(psz);
|
---|
546 | aDisks[i] = utf;
|
---|
547 | RTStrFree(psz);
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | return S_OK;
|
---|
552 | }
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * Public method implementation.
|
---|
556 | */
|
---|
557 | HRESULT Appliance::getCertificate(ComPtr<ICertificate> &aCertificateInfo)
|
---|
558 | {
|
---|
559 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
560 |
|
---|
561 | /* Can be NULL at this point, queryInterfaceto handles that. */
|
---|
562 | m->ptrCertificateInfo.queryInterfaceTo(aCertificateInfo.asOutParam());
|
---|
563 | return S_OK;
|
---|
564 | }
|
---|
565 |
|
---|
566 | /**
|
---|
567 | * Public method implementation.
|
---|
568 | */
|
---|
569 | HRESULT Appliance::getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions)
|
---|
570 | {
|
---|
571 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
572 |
|
---|
573 | aVirtualSystemDescriptions.resize(m->virtualSystemDescriptions.size());
|
---|
574 | std::list< ComObjPtr<VirtualSystemDescription> > vsds(m->virtualSystemDescriptions);
|
---|
575 | size_t i = 0;
|
---|
576 | for (std::list< ComObjPtr<VirtualSystemDescription> >::iterator it = vsds.begin(); it != vsds.end(); ++it, ++i)
|
---|
577 | {
|
---|
578 | (*it).queryInterfaceTo(aVirtualSystemDescriptions[i].asOutParam());
|
---|
579 | }
|
---|
580 | return S_OK;
|
---|
581 | }
|
---|
582 |
|
---|
583 | /**
|
---|
584 | * Public method implementation.
|
---|
585 | */
|
---|
586 | HRESULT Appliance::getMachines(std::vector<com::Utf8Str> &aMachines)
|
---|
587 | {
|
---|
588 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
589 |
|
---|
590 | aMachines.resize(m->llGuidsMachinesCreated.size());
|
---|
591 | size_t i = 0;
|
---|
592 | for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin();
|
---|
593 | it != m->llGuidsMachinesCreated.end();
|
---|
594 | ++it, ++i)
|
---|
595 | {
|
---|
596 | const Guid &uuid = *it;
|
---|
597 | aMachines[i] = uuid.toUtf16();
|
---|
598 | }
|
---|
599 | return S_OK;
|
---|
600 | }
|
---|
601 |
|
---|
602 | HRESULT Appliance::createVFSExplorer(const com::Utf8Str &aURI, ComPtr<IVFSExplorer> &aExplorer)
|
---|
603 | {
|
---|
604 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
605 |
|
---|
606 | ComObjPtr<VFSExplorer> explorer;
|
---|
607 | HRESULT rc = S_OK;
|
---|
608 | try
|
---|
609 | {
|
---|
610 | Utf8Str uri(aURI);
|
---|
611 | /* Check which kind of export the user has requested */
|
---|
612 | LocationInfo li;
|
---|
613 | i_parseURI(aURI, li);
|
---|
614 | /* Create the explorer object */
|
---|
615 | explorer.createObject();
|
---|
616 | rc = explorer->init(li.storageType, li.strPath, li.strHostname, li.strUsername, li.strPassword, mVirtualBox);
|
---|
617 | }
|
---|
618 | catch (HRESULT aRC)
|
---|
619 | {
|
---|
620 | rc = aRC;
|
---|
621 | }
|
---|
622 |
|
---|
623 | if (SUCCEEDED(rc))
|
---|
624 | /* Return explorer to the caller */
|
---|
625 | explorer.queryInterfaceTo(aExplorer.asOutParam());
|
---|
626 |
|
---|
627 | return rc;
|
---|
628 | }
|
---|
629 |
|
---|
630 |
|
---|
631 | /**
|
---|
632 | * Public method implementation.
|
---|
633 | * Add the "aRequested" numbers of new empty objects of VSD into the list
|
---|
634 | * "virtualSystemDescriptions".
|
---|
635 | * The parameter "aCreated" keeps the actual number of the added objects.
|
---|
636 | * In case of exception all added objects are removed from the list.
|
---|
637 | */
|
---|
638 | HRESULT Appliance::createVirtualSystemDescriptions(ULONG aRequested, ULONG *aCreated)
|
---|
639 | {
|
---|
640 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
641 |
|
---|
642 | HRESULT rc = S_OK;
|
---|
643 | uint32_t lQuantity = aRequested;
|
---|
644 | uint32_t i=0;
|
---|
645 |
|
---|
646 | if (lQuantity < 1)
|
---|
647 | return setError(E_FAIL, tr("The number of VirtualSystemDescription objects must be at least 1 or more."));
|
---|
648 | try
|
---|
649 | {
|
---|
650 | for (; i<lQuantity; ++i)
|
---|
651 | {
|
---|
652 | ComObjPtr<VirtualSystemDescription> opVSD;
|
---|
653 | rc = opVSD.createObject();
|
---|
654 | if (SUCCEEDED(rc))
|
---|
655 | {
|
---|
656 | rc = opVSD->init();
|
---|
657 | if (SUCCEEDED(rc))
|
---|
658 | m->virtualSystemDescriptions.push_back(opVSD);
|
---|
659 | else
|
---|
660 | break;
|
---|
661 | }
|
---|
662 | else
|
---|
663 | break;
|
---|
664 | }
|
---|
665 |
|
---|
666 | if (i<lQuantity)
|
---|
667 | LogRel(("Number of created VirtualSystemDescription objects is less than requested"
|
---|
668 | "(Requested %d, Created %d)",lQuantity, i));
|
---|
669 |
|
---|
670 | *aCreated = i;
|
---|
671 | }
|
---|
672 | catch (HRESULT aRC)
|
---|
673 | {
|
---|
674 | for (; i>0; --i)
|
---|
675 | {
|
---|
676 | if (!m->virtualSystemDescriptions.empty())
|
---|
677 | m->virtualSystemDescriptions.pop_back();
|
---|
678 | else
|
---|
679 | break;
|
---|
680 | }
|
---|
681 | rc = aRC;
|
---|
682 | }
|
---|
683 |
|
---|
684 | return rc;
|
---|
685 | }
|
---|
686 |
|
---|
687 | /**
|
---|
688 | * Public method implementation.
|
---|
689 | */
|
---|
690 | HRESULT Appliance::getWarnings(std::vector<com::Utf8Str> &aWarnings)
|
---|
691 | {
|
---|
692 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
693 |
|
---|
694 | aWarnings.resize(m->llWarnings.size());
|
---|
695 |
|
---|
696 | list<Utf8Str>::const_iterator it;
|
---|
697 | size_t i = 0;
|
---|
698 | for (it = m->llWarnings.begin();
|
---|
699 | it != m->llWarnings.end();
|
---|
700 | ++it, ++i)
|
---|
701 | {
|
---|
702 | aWarnings[i] = *it;
|
---|
703 | }
|
---|
704 |
|
---|
705 | return S_OK;
|
---|
706 | }
|
---|
707 |
|
---|
708 | HRESULT Appliance::getPasswordIds(std::vector<com::Utf8Str> &aIdentifiers)
|
---|
709 | {
|
---|
710 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
711 |
|
---|
712 | aIdentifiers = m->m_vecPasswordIdentifiers;
|
---|
713 | return S_OK;
|
---|
714 | }
|
---|
715 |
|
---|
716 | HRESULT Appliance::getMediumIdsForPasswordId(const com::Utf8Str &aPasswordId, std::vector<com::Guid> &aIdentifiers)
|
---|
717 | {
|
---|
718 | HRESULT hrc = S_OK;
|
---|
719 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
720 |
|
---|
721 | std::map<com::Utf8Str, GUIDVEC>::const_iterator it = m->m_mapPwIdToMediumIds.find(aPasswordId);
|
---|
722 | if (it != m->m_mapPwIdToMediumIds.end())
|
---|
723 | aIdentifiers = it->second;
|
---|
724 | else
|
---|
725 | hrc = setError(E_FAIL, tr("The given password identifier is not associated with any medium"));
|
---|
726 |
|
---|
727 | return hrc;
|
---|
728 | }
|
---|
729 |
|
---|
730 | HRESULT Appliance::addPasswords(const std::vector<com::Utf8Str> &aIdentifiers,
|
---|
731 | const std::vector<com::Utf8Str> &aPasswords)
|
---|
732 | {
|
---|
733 | HRESULT hrc = S_OK;
|
---|
734 |
|
---|
735 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
736 |
|
---|
737 | /* Check that the IDs do not exist already before changing anything. */
|
---|
738 | for (unsigned i = 0; i < aIdentifiers.size(); i++)
|
---|
739 | {
|
---|
740 | SecretKey *pKey = NULL;
|
---|
741 | int rc = m->m_pSecretKeyStore->retainSecretKey(aIdentifiers[i], &pKey);
|
---|
742 | if (rc != VERR_NOT_FOUND)
|
---|
743 | {
|
---|
744 | AssertPtr(pKey);
|
---|
745 | if (pKey)
|
---|
746 | pKey->release();
|
---|
747 | return setError(VBOX_E_OBJECT_IN_USE, tr("A password with the given ID already exists"));
|
---|
748 | }
|
---|
749 | }
|
---|
750 |
|
---|
751 | for (unsigned i = 0; i < aIdentifiers.size() && SUCCEEDED(hrc); i++)
|
---|
752 | {
|
---|
753 | size_t cbKey = aPasswords[i].length() + 1; /* Include terminator */
|
---|
754 | const uint8_t *pbKey = (const uint8_t *)aPasswords[i].c_str();
|
---|
755 |
|
---|
756 | int rc = m->m_pSecretKeyStore->addSecretKey(aIdentifiers[i], pbKey, cbKey);
|
---|
757 | if (RT_SUCCESS(rc))
|
---|
758 | m->m_cPwProvided++;
|
---|
759 | else if (rc == VERR_NO_MEMORY)
|
---|
760 | hrc = setError(E_OUTOFMEMORY, tr("Failed to allocate enough secure memory for the key"));
|
---|
761 | else
|
---|
762 | hrc = setError(E_FAIL, tr("Unknown error happened while adding a password (%Rrc)"), rc);
|
---|
763 | }
|
---|
764 |
|
---|
765 | return hrc;
|
---|
766 | }
|
---|
767 |
|
---|
768 | ////////////////////////////////////////////////////////////////////////////////
|
---|
769 | //
|
---|
770 | // Appliance private methods
|
---|
771 | //
|
---|
772 | ////////////////////////////////////////////////////////////////////////////////
|
---|
773 |
|
---|
774 | HRESULT Appliance::i_initBackendNames()
|
---|
775 | {
|
---|
776 | HRESULT hrc = S_OK;
|
---|
777 | if (!g_fInitializedBackendNames)
|
---|
778 | {
|
---|
779 | /*
|
---|
780 | * Use the system properties to translate file extensions into
|
---|
781 | * storage backend names.
|
---|
782 | */
|
---|
783 | static struct
|
---|
784 | {
|
---|
785 | const char *pszExt; /**< extension */
|
---|
786 | char *pszBackendName;
|
---|
787 | size_t cbBackendName;
|
---|
788 | } const s_aFormats[] =
|
---|
789 | {
|
---|
790 | { "iso", g_szIsoBackend, sizeof(g_szIsoBackend) },
|
---|
791 | { "vmdk", g_szVmdkBackend, sizeof(g_szVmdkBackend) },
|
---|
792 | { "vhd", g_szVhdBackend, sizeof(g_szVhdBackend) },
|
---|
793 | };
|
---|
794 | SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
|
---|
795 | for (unsigned i = 0; i < RT_ELEMENTS(s_aFormats); i++)
|
---|
796 | {
|
---|
797 | ComObjPtr<MediumFormat> trgFormat = pSysProps->i_mediumFormatFromExtension(s_aFormats[i].pszExt);
|
---|
798 | if (trgFormat.isNotNull())
|
---|
799 | {
|
---|
800 | const char *pszName = trgFormat->i_getName().c_str();
|
---|
801 | int vrc = RTStrCopy(s_aFormats[i].pszBackendName, s_aFormats[i].cbBackendName, pszName);
|
---|
802 | AssertRCStmt(vrc, hrc = setError(E_FAIL, "Unexpected storage backend name copy error %Rrc for %s.", vrc, pszName));
|
---|
803 | }
|
---|
804 | else
|
---|
805 | hrc = setError(E_FAIL, tr("Can't find appropriate medium format for ISO type of a virtual disk."));
|
---|
806 | }
|
---|
807 |
|
---|
808 | if (SUCCEEDED(hrc))
|
---|
809 | g_fInitializedBackendNames = true;
|
---|
810 | }
|
---|
811 |
|
---|
812 | return hrc;
|
---|
813 | }
|
---|
814 |
|
---|
815 | Utf8Str Appliance::i_typeOfVirtualDiskFormatFromURI(Utf8Str uri) const
|
---|
816 | {
|
---|
817 | Assert(g_fInitializedBackendNames);
|
---|
818 |
|
---|
819 | unsigned i = RT_ELEMENTS(g_aUriToBackend);
|
---|
820 | while (i-- > 0)
|
---|
821 | if (RTStrICmp(g_aUriToBackend[i].pszUri, uri.c_str()) == 0)
|
---|
822 | return Utf8Str(g_aUriToBackend[i].pszBackend);
|
---|
823 | return Utf8Str();
|
---|
824 | }
|
---|
825 |
|
---|
826 | #if 0 /* unused */
|
---|
827 | std::set<Utf8Str> Appliance::i_URIFromTypeOfVirtualDiskFormat(Utf8Str type)
|
---|
828 | {
|
---|
829 | Assert(g_fInitializedBackendNames);
|
---|
830 |
|
---|
831 | std::set<Utf8Str> UriSet;
|
---|
832 | unsigned i = RT_ELEMENTS(g_aUriToBackend);
|
---|
833 | while (i-- > 0)
|
---|
834 | if (RTStrICmp(g_aUriToBackend[i].pszBackend, type.c_str()) == 0)
|
---|
835 | UriSet.insert(g_aUriToBackend[i].pszUri);
|
---|
836 | return UriSet;
|
---|
837 | }
|
---|
838 | #endif
|
---|
839 |
|
---|
840 | /**
|
---|
841 | * Returns a medium format object corresponding to the given
|
---|
842 | * disk image or null if no such format.
|
---|
843 | *
|
---|
844 | * @param di Disk Image
|
---|
845 | * @param mf Medium Format
|
---|
846 | *
|
---|
847 | * @return ComObjPtr<MediumFormat>
|
---|
848 | */
|
---|
849 | HRESULT Appliance::i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf)
|
---|
850 | {
|
---|
851 | HRESULT rc = S_OK;
|
---|
852 |
|
---|
853 | /* Get the system properties. */
|
---|
854 | SystemProperties *pSysProps = mVirtualBox->i_getSystemProperties();
|
---|
855 |
|
---|
856 | /* We need a proper source format description */
|
---|
857 | /* Which format to use? */
|
---|
858 | Utf8Str strSrcFormat = i_typeOfVirtualDiskFormatFromURI(di.strFormat);
|
---|
859 |
|
---|
860 | /*
|
---|
861 | * fallback, if we can't determine virtual disk format using URI from the attribute ovf:format
|
---|
862 | * in the corresponding section <Disk> in the OVF file.
|
---|
863 | */
|
---|
864 | if (strSrcFormat.isEmpty())
|
---|
865 | {
|
---|
866 | strSrcFormat = di.strHref;
|
---|
867 |
|
---|
868 | /* check either file gzipped or not
|
---|
869 | * if "yes" then remove last extension,
|
---|
870 | * i.e. "image.vmdk.gz"->"image.vmdk"
|
---|
871 | */
|
---|
872 | if (di.strCompression == "gzip")
|
---|
873 | {
|
---|
874 | if (RTPathHasSuffix(strSrcFormat.c_str()))
|
---|
875 | {
|
---|
876 | strSrcFormat.stripSuffix();
|
---|
877 | }
|
---|
878 | else
|
---|
879 | {
|
---|
880 | mf.setNull();
|
---|
881 | rc = setError(E_FAIL,
|
---|
882 | tr("Internal inconsistency looking up medium format for the disk image '%s'"),
|
---|
883 | di.strHref.c_str());
|
---|
884 | return rc;
|
---|
885 | }
|
---|
886 | }
|
---|
887 | /* Figure out from extension which format the image of disk has. */
|
---|
888 | if (RTPathHasSuffix(strSrcFormat.c_str()))
|
---|
889 | {
|
---|
890 | const char *pszExt = RTPathSuffix(strSrcFormat.c_str());
|
---|
891 | if (pszExt)
|
---|
892 | pszExt++;
|
---|
893 | mf = pSysProps->i_mediumFormatFromExtension(pszExt);
|
---|
894 | }
|
---|
895 | else
|
---|
896 | mf.setNull();
|
---|
897 | }
|
---|
898 | else
|
---|
899 | mf = pSysProps->i_mediumFormat(strSrcFormat);
|
---|
900 |
|
---|
901 | if (mf.isNull())
|
---|
902 | rc = setError(E_FAIL, tr("Internal inconsistency looking up medium format for the disk image '%s'"),
|
---|
903 | di.strHref.c_str());
|
---|
904 |
|
---|
905 | return rc;
|
---|
906 | }
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Setup automatic I/O stream digest calculation, adding it to hOurManifest.
|
---|
910 | *
|
---|
911 | * @returns Passthru I/O stream, of @a hVfsIos if no digest calc needed.
|
---|
912 | * @param hVfsIos The stream to wrap. Always consumed.
|
---|
913 | * @param pszManifestEntry The manifest entry.
|
---|
914 | * @param fRead Set if read stream, clear if write.
|
---|
915 | * @throws Nothing.
|
---|
916 | */
|
---|
917 | RTVFSIOSTREAM Appliance::i_manifestSetupDigestCalculationForGivenIoStream(RTVFSIOSTREAM hVfsIos, const char *pszManifestEntry,
|
---|
918 | bool fRead /*= true */)
|
---|
919 | {
|
---|
920 | int vrc;
|
---|
921 | Assert(!RTManifestPtIosIsInstanceOf(hVfsIos));
|
---|
922 |
|
---|
923 | if (m->fDigestTypes == 0)
|
---|
924 | return hVfsIos;
|
---|
925 |
|
---|
926 | /* Create the manifest if necessary. */
|
---|
927 | if (m->hOurManifest == NIL_RTMANIFEST)
|
---|
928 | {
|
---|
929 | vrc = RTManifestCreate(0 /*fFlags*/, &m->hOurManifest);
|
---|
930 | AssertRCReturnStmt(vrc, RTVfsIoStrmRelease(hVfsIos), NIL_RTVFSIOSTREAM);
|
---|
931 | }
|
---|
932 |
|
---|
933 | /* Setup the stream. */
|
---|
934 | RTVFSIOSTREAM hVfsIosPt;
|
---|
935 | vrc = RTManifestEntryAddPassthruIoStream(m->hOurManifest, hVfsIos, pszManifestEntry, m->fDigestTypes, fRead, &hVfsIosPt);
|
---|
936 |
|
---|
937 | RTVfsIoStrmRelease(hVfsIos); /* always consumed! */
|
---|
938 | if (RT_SUCCESS(vrc))
|
---|
939 | return hVfsIosPt;
|
---|
940 |
|
---|
941 | setErrorVrc(vrc, "RTManifestEntryAddPassthruIoStream failed with rc=%Rrc", vrc);
|
---|
942 | return NIL_RTVFSIOSTREAM;
|
---|
943 | }
|
---|
944 |
|
---|
945 | /**
|
---|
946 | * Returns true if the appliance is in "idle" state. This should always be the
|
---|
947 | * case unless an import or export is currently in progress. Similar to machine
|
---|
948 | * states, this permits the Appliance implementation code to let go of the
|
---|
949 | * Appliance object lock while a time-consuming disk conversion is in progress
|
---|
950 | * without exposing the appliance to conflicting calls.
|
---|
951 | *
|
---|
952 | * This sets an error on "this" (the appliance) and returns false if the appliance
|
---|
953 | * is busy. The caller should then return E_ACCESSDENIED.
|
---|
954 | *
|
---|
955 | * Must be called from under the object lock!
|
---|
956 | */
|
---|
957 | bool Appliance::i_isApplianceIdle()
|
---|
958 | {
|
---|
959 | if (m->state == ApplianceImporting)
|
---|
960 | setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy importing files"));
|
---|
961 | else if (m->state == ApplianceExporting)
|
---|
962 | setError(VBOX_E_INVALID_OBJECT_STATE, tr("The appliance is busy exporting files"));
|
---|
963 | else
|
---|
964 | return true;
|
---|
965 |
|
---|
966 | return false;
|
---|
967 | }
|
---|
968 |
|
---|
969 | HRESULT Appliance::i_searchUniqueVMName(Utf8Str &aName) const
|
---|
970 | {
|
---|
971 | ComPtr<IMachine> ptrMachine;
|
---|
972 | char *tmpName = RTStrDup(aName.c_str());
|
---|
973 | int i = 1;
|
---|
974 | while (mVirtualBox->FindMachine(Bstr(tmpName).raw(), ptrMachine.asOutParam()) != VBOX_E_OBJECT_NOT_FOUND)
|
---|
975 | {
|
---|
976 | RTStrFree(tmpName);
|
---|
977 | RTStrAPrintf(&tmpName, "%s %d", aName.c_str(), i);
|
---|
978 | ++i;
|
---|
979 | }
|
---|
980 | aName = tmpName;
|
---|
981 | RTStrFree(tmpName);
|
---|
982 |
|
---|
983 | return S_OK;
|
---|
984 | }
|
---|
985 |
|
---|
986 | HRESULT Appliance::i_ensureUniqueImageFilePath(const Utf8Str &aMachineFolder, DeviceType_T aDeviceType, Utf8Str &aName) const
|
---|
987 | {
|
---|
988 | /*
|
---|
989 | * Check if the file exists or if a medium with this path is registered already
|
---|
990 | */
|
---|
991 | Utf8Str strAbsName;
|
---|
992 | size_t offDashNum = ~(size_t)0;
|
---|
993 | size_t cchDashNum = 0;
|
---|
994 | for (unsigned i = 1;; i++)
|
---|
995 | {
|
---|
996 | /* Complete the path (could be relative to machine folder). */
|
---|
997 | int rc = RTPathAbsExCxx(strAbsName, aMachineFolder, aName);
|
---|
998 | AssertRCReturn(rc, Global::vboxStatusCodeToCOM(rc)); /** @todo stupid caller ignores this */
|
---|
999 |
|
---|
1000 | /* Check that the file does not exist and that there is no media somehow matching the name. */
|
---|
1001 | if (!RTPathExists(strAbsName.c_str()))
|
---|
1002 | {
|
---|
1003 | ComPtr<IMedium> ptrMedium;
|
---|
1004 | HRESULT hrc = mVirtualBox->OpenMedium(Bstr(strAbsName).raw(), aDeviceType, AccessMode_ReadWrite,
|
---|
1005 | FALSE /* fForceNewUuid */, ptrMedium.asOutParam());
|
---|
1006 | if (hrc == VBOX_E_OBJECT_NOT_FOUND)
|
---|
1007 | return S_OK;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /* Insert '_%i' before the suffix and try again. */
|
---|
1011 | if (offDashNum == ~(size_t)0)
|
---|
1012 | {
|
---|
1013 | const char *pszSuffix = RTPathSuffix(aName.c_str());
|
---|
1014 | offDashNum = pszSuffix ? (size_t)(pszSuffix - aName.c_str()) : aName.length();
|
---|
1015 | }
|
---|
1016 | char szTmp[32];
|
---|
1017 | size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "_%u", i);
|
---|
1018 | aName.replace(offDashNum, cchDashNum, szTmp, cchTmp);
|
---|
1019 | cchDashNum = cchTmp;
|
---|
1020 | }
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | /**
|
---|
1024 | * Called from Appliance::importImpl() and Appliance::writeImpl() to set up a
|
---|
1025 | * progress object with the proper weights and maximum progress values.
|
---|
1026 | */
|
---|
1027 | HRESULT Appliance::i_setUpProgress(ComObjPtr<Progress> &pProgress,
|
---|
1028 | const Utf8Str &strDescription,
|
---|
1029 | SetUpProgressMode mode)
|
---|
1030 | {
|
---|
1031 | HRESULT rc;
|
---|
1032 |
|
---|
1033 | /* Create the progress object */
|
---|
1034 | try
|
---|
1035 | {
|
---|
1036 | rc = pProgress.createObject();
|
---|
1037 | if (FAILED(rc))
|
---|
1038 | return rc;
|
---|
1039 | }
|
---|
1040 | catch (std::bad_alloc &)
|
---|
1041 | {
|
---|
1042 | return E_OUTOFMEMORY;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | // compute the disks weight (this sets ulTotalDisksMB and cDisks in the instance data)
|
---|
1046 | i_disksWeight();
|
---|
1047 |
|
---|
1048 | m->ulWeightForManifestOperation = 0;
|
---|
1049 |
|
---|
1050 | ULONG cOperations = 1 // one for XML setup
|
---|
1051 | + m->cDisks; // plus one per disk
|
---|
1052 | ULONG ulTotalOperationsWeight;
|
---|
1053 | if (m->ulTotalDisksMB)
|
---|
1054 | {
|
---|
1055 | m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress for the XML
|
---|
1056 | ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
|
---|
1057 | }
|
---|
1058 | else
|
---|
1059 | {
|
---|
1060 | // no disks to export:
|
---|
1061 | m->ulWeightForXmlOperation = 1;
|
---|
1062 | ulTotalOperationsWeight = 1;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | switch (mode)
|
---|
1066 | {
|
---|
1067 | case ImportFile:
|
---|
1068 | {
|
---|
1069 | break;
|
---|
1070 | }
|
---|
1071 | case WriteFile:
|
---|
1072 | {
|
---|
1073 | // assume that creating the manifest will take .1% of the time it takes to export the disks
|
---|
1074 | if (m->fManifest)
|
---|
1075 | {
|
---|
1076 | ++cOperations; // another one for creating the manifest
|
---|
1077 |
|
---|
1078 | m->ulWeightForManifestOperation = (ULONG)((double)m->ulTotalDisksMB * .1 / 100); // use .5% of the
|
---|
1079 | // progress for the manifest
|
---|
1080 | ulTotalOperationsWeight += m->ulWeightForManifestOperation;
|
---|
1081 | }
|
---|
1082 | break;
|
---|
1083 | }
|
---|
1084 | case ImportS3:
|
---|
1085 | {
|
---|
1086 | cOperations += 1 + 1; // another one for the manifest file & another one for the import
|
---|
1087 | ulTotalOperationsWeight = m->ulTotalDisksMB;
|
---|
1088 | if (!m->ulTotalDisksMB)
|
---|
1089 | // no disks to export:
|
---|
1090 | ulTotalOperationsWeight = 1;
|
---|
1091 |
|
---|
1092 | ULONG ulImportWeight = (ULONG)((double)ulTotalOperationsWeight * 50 / 100); // use 50% for import
|
---|
1093 | ulTotalOperationsWeight += ulImportWeight;
|
---|
1094 |
|
---|
1095 | m->ulWeightForXmlOperation = ulImportWeight; /* save for using later */
|
---|
1096 |
|
---|
1097 | ULONG ulInitWeight = (ULONG)((double)ulTotalOperationsWeight * 0.1 / 100); // use 0.1% for init
|
---|
1098 | ulTotalOperationsWeight += ulInitWeight;
|
---|
1099 | break;
|
---|
1100 | }
|
---|
1101 | case WriteS3:
|
---|
1102 | {
|
---|
1103 | cOperations += 1 + 1; // another one for the mf & another one for temporary creation
|
---|
1104 |
|
---|
1105 | if (m->ulTotalDisksMB)
|
---|
1106 | {
|
---|
1107 | m->ulWeightForXmlOperation = (ULONG)((double)m->ulTotalDisksMB * 1 / 100); // use 1% of the progress
|
---|
1108 | // for OVF file upload
|
---|
1109 | // (we didn't know the
|
---|
1110 | // size at this point)
|
---|
1111 | ulTotalOperationsWeight = m->ulTotalDisksMB + m->ulWeightForXmlOperation;
|
---|
1112 | }
|
---|
1113 | else
|
---|
1114 | {
|
---|
1115 | // no disks to export:
|
---|
1116 | ulTotalOperationsWeight = 1;
|
---|
1117 | m->ulWeightForXmlOperation = 1;
|
---|
1118 | }
|
---|
1119 | ULONG ulOVFCreationWeight = (ULONG)((double)ulTotalOperationsWeight * 50.0 / 100.0); /* Use 50% for the
|
---|
1120 | creation of the OVF
|
---|
1121 | & the disks */
|
---|
1122 | ulTotalOperationsWeight += ulOVFCreationWeight;
|
---|
1123 | break;
|
---|
1124 | }
|
---|
1125 | case ExportCloud:
|
---|
1126 | case ImportCloud:
|
---|
1127 | break;
|
---|
1128 | }
|
---|
1129 | Log(("Setting up progress object: ulTotalMB = %d, cDisks = %d, => cOperations = %d, ulTotalOperationsWeight = %d, m->ulWeightForXmlOperation = %d\n",
|
---|
1130 | m->ulTotalDisksMB, m->cDisks, cOperations, ulTotalOperationsWeight, m->ulWeightForXmlOperation));
|
---|
1131 |
|
---|
1132 | return pProgress->init(mVirtualBox, static_cast<IAppliance*>(this),
|
---|
1133 | strDescription,
|
---|
1134 | TRUE /* aCancelable */,
|
---|
1135 | cOperations, // ULONG cOperations,
|
---|
1136 | ulTotalOperationsWeight, // ULONG ulTotalOperationsWeight,
|
---|
1137 | strDescription, // CBSTR bstrFirstOperationDescription,
|
---|
1138 | m->ulWeightForXmlOperation); // ULONG ulFirstOperationWeight,
|
---|
1139 | }
|
---|
1140 |
|
---|
1141 | void Appliance::i_addWarning(const char* aWarning, ...)
|
---|
1142 | {
|
---|
1143 | try
|
---|
1144 | {
|
---|
1145 | va_list args;
|
---|
1146 | va_start(args, aWarning);
|
---|
1147 | Utf8Str str(aWarning, args);
|
---|
1148 | va_end(args);
|
---|
1149 | m->llWarnings.push_back(str);
|
---|
1150 | }
|
---|
1151 | catch (...)
|
---|
1152 | {
|
---|
1153 | AssertFailed();
|
---|
1154 | }
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | /**
|
---|
1158 | * Refreshes the cDisks and ulTotalDisksMB members in the instance data.
|
---|
1159 | * Requires that virtual system descriptions are present.
|
---|
1160 | */
|
---|
1161 | void Appliance::i_disksWeight()
|
---|
1162 | {
|
---|
1163 | m->ulTotalDisksMB = 0;
|
---|
1164 | m->cDisks = 0;
|
---|
1165 | // weigh the disk images according to their sizes
|
---|
1166 | list< ComObjPtr<VirtualSystemDescription> >::const_iterator it;
|
---|
1167 | for (it = m->virtualSystemDescriptions.begin();
|
---|
1168 | it != m->virtualSystemDescriptions.end();
|
---|
1169 | ++it)
|
---|
1170 | {
|
---|
1171 | ComObjPtr<VirtualSystemDescription> vsdescThis = (*it);
|
---|
1172 | /* One for every medium of the Virtual System */
|
---|
1173 | std::list<VirtualSystemDescriptionEntry*> avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
|
---|
1174 | std::list<VirtualSystemDescriptionEntry*>::const_iterator itH;
|
---|
1175 | for (itH = avsdeHDs.begin();
|
---|
1176 | itH != avsdeHDs.end();
|
---|
1177 | ++itH)
|
---|
1178 | {
|
---|
1179 | const VirtualSystemDescriptionEntry *pHD = *itH;
|
---|
1180 | m->ulTotalDisksMB += pHD->ulSizeMB;
|
---|
1181 | ++m->cDisks;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | avsdeHDs = vsdescThis->i_findByType(VirtualSystemDescriptionType_CDROM);
|
---|
1185 | for (itH = avsdeHDs.begin();
|
---|
1186 | itH != avsdeHDs.end();
|
---|
1187 | ++itH)
|
---|
1188 | {
|
---|
1189 | const VirtualSystemDescriptionEntry *pHD = *itH;
|
---|
1190 | m->ulTotalDisksMB += pHD->ulSizeMB;
|
---|
1191 | ++m->cDisks;
|
---|
1192 | }
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | void Appliance::i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket)
|
---|
1198 | {
|
---|
1199 | /* Buckets are S3 specific. So parse the bucket out of the file path */
|
---|
1200 | if (!aPath.startsWith("/"))
|
---|
1201 | throw setError(E_INVALIDARG,
|
---|
1202 | tr("The path '%s' must start with /"), aPath.c_str());
|
---|
1203 | size_t bpos = aPath.find("/", 1);
|
---|
1204 | if (bpos != Utf8Str::npos)
|
---|
1205 | {
|
---|
1206 | aBucket = aPath.substr(1, bpos - 1); /* The bucket without any slashes */
|
---|
1207 | aPath = aPath.substr(bpos); /* The rest of the file path */
|
---|
1208 | }
|
---|
1209 | /* If there is no bucket name provided reject it */
|
---|
1210 | if (aBucket.isEmpty())
|
---|
1211 | throw setError(E_INVALIDARG,
|
---|
1212 | tr("You doesn't provide a bucket name in the URI '%s'"), aPath.c_str());
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | /**
|
---|
1216 | * Worker for TaskOVF::handler.
|
---|
1217 | *
|
---|
1218 | * The TaskOVF is started in Appliance::readImpl() and Appliance::importImpl()
|
---|
1219 | * and Appliance::writeImpl().
|
---|
1220 | *
|
---|
1221 | * This will in turn call Appliance::readFS() or Appliance::importFS() or
|
---|
1222 | * Appliance::writeFS().
|
---|
1223 | *
|
---|
1224 | * @thread pTask The task.
|
---|
1225 | */
|
---|
1226 | /* static */ void Appliance::i_importOrExportThreadTask(TaskOVF *pTask)
|
---|
1227 | {
|
---|
1228 | LogFlowFuncEnter();
|
---|
1229 | AssertReturnVoid(pTask);
|
---|
1230 |
|
---|
1231 | Appliance *pAppliance = pTask->pAppliance;
|
---|
1232 | LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
|
---|
1233 |
|
---|
1234 | switch (pTask->taskType)
|
---|
1235 | {
|
---|
1236 | case TaskOVF::Read:
|
---|
1237 | pAppliance->m->resetReadData();
|
---|
1238 | if (pTask->locInfo.storageType == VFSType_File)
|
---|
1239 | pTask->rc = pAppliance->i_readFS(pTask);
|
---|
1240 | else
|
---|
1241 | pTask->rc = E_NOTIMPL;
|
---|
1242 | break;
|
---|
1243 |
|
---|
1244 | case TaskOVF::Import:
|
---|
1245 | /** @todo allow overriding these? */
|
---|
1246 | if (!pAppliance->m->fSignatureValid && pAppliance->m->pbSignedDigest)
|
---|
1247 | pTask->rc = pAppliance->setError(E_FAIL, tr("The manifest signature for '%s' is not valid"),
|
---|
1248 | pTask->locInfo.strPath.c_str());
|
---|
1249 | else if (!pAppliance->m->fCertificateValid && pAppliance->m->pbSignedDigest)
|
---|
1250 | {
|
---|
1251 | if (pAppliance->m->strCertError.isNotEmpty())
|
---|
1252 | pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid: %s"),
|
---|
1253 | pTask->locInfo.strPath.c_str(), pAppliance->m->strCertError.c_str());
|
---|
1254 | else
|
---|
1255 | pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is not valid"),
|
---|
1256 | pTask->locInfo.strPath.c_str());
|
---|
1257 | }
|
---|
1258 | // fusion does not consider this a show stopper (we've filed a warning during read).
|
---|
1259 | //else if (pAppliance->m->fCertificateMissingPath && pAppliance->m->pbSignedDigest)
|
---|
1260 | // pTask->rc = pAppliance->setError(E_FAIL, tr("The certificate used to signed '%s' is does not have a valid CA path"),
|
---|
1261 | // pTask->locInfo.strPath.c_str());
|
---|
1262 | else
|
---|
1263 | {
|
---|
1264 | if (pTask->locInfo.storageType == VFSType_File)
|
---|
1265 | pTask->rc = pAppliance->i_importFS(pTask);
|
---|
1266 | else
|
---|
1267 | pTask->rc = E_NOTIMPL;
|
---|
1268 | }
|
---|
1269 | break;
|
---|
1270 |
|
---|
1271 | case TaskOVF::Write:
|
---|
1272 | if (pTask->locInfo.storageType == VFSType_File)
|
---|
1273 | pTask->rc = pAppliance->i_writeFS(pTask);
|
---|
1274 | else
|
---|
1275 | pTask->rc = E_NOTIMPL;
|
---|
1276 | break;
|
---|
1277 |
|
---|
1278 | default:
|
---|
1279 | AssertFailed();
|
---|
1280 | pTask->rc = E_FAIL;
|
---|
1281 | break;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | if (!pTask->pProgress.isNull())
|
---|
1285 | pTask->pProgress->i_notifyComplete(pTask->rc);
|
---|
1286 |
|
---|
1287 | LogFlowFuncLeave();
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | /* static */ DECLCALLBACK(int) Appliance::TaskOVF::updateProgress(unsigned uPercent, void *pvUser)
|
---|
1291 | {
|
---|
1292 | Appliance::TaskOVF* pTask = *(Appliance::TaskOVF**)pvUser;
|
---|
1293 |
|
---|
1294 | if ( pTask
|
---|
1295 | && !pTask->pProgress.isNull())
|
---|
1296 | {
|
---|
1297 | BOOL fCanceled;
|
---|
1298 | pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
|
---|
1299 | if (fCanceled)
|
---|
1300 | return -1;
|
---|
1301 | pTask->pProgress->SetCurrentOperationProgress(uPercent);
|
---|
1302 | }
|
---|
1303 | return VINF_SUCCESS;
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | /**
|
---|
1307 | * Worker for TaskOPC::handler.
|
---|
1308 | * @thread pTask The task.
|
---|
1309 | */
|
---|
1310 | /* static */
|
---|
1311 | void Appliance::i_exportOPCThreadTask(TaskOPC *pTask)
|
---|
1312 | {
|
---|
1313 | LogFlowFuncEnter();
|
---|
1314 | AssertReturnVoid(pTask);
|
---|
1315 |
|
---|
1316 | Appliance *pAppliance = pTask->pAppliance;
|
---|
1317 | LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
|
---|
1318 |
|
---|
1319 | switch (pTask->taskType)
|
---|
1320 | {
|
---|
1321 | case TaskOPC::Export:
|
---|
1322 | pTask->rc = pAppliance->i_writeFSOPC(pTask);
|
---|
1323 | break;
|
---|
1324 |
|
---|
1325 | default:
|
---|
1326 | AssertFailed();
|
---|
1327 | pTask->rc = E_FAIL;
|
---|
1328 | break;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | if (!pTask->pProgress.isNull())
|
---|
1332 | pTask->pProgress->i_notifyComplete(pTask->rc);
|
---|
1333 |
|
---|
1334 | LogFlowFuncLeave();
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /* static */
|
---|
1338 | DECLCALLBACK(int) Appliance::TaskOPC::updateProgress(unsigned uPercent, void *pvUser)
|
---|
1339 | {
|
---|
1340 | Appliance::TaskOPC* pTask = *(Appliance::TaskOPC**)pvUser;
|
---|
1341 |
|
---|
1342 | if ( pTask
|
---|
1343 | && !pTask->pProgress.isNull())
|
---|
1344 | {
|
---|
1345 | BOOL fCanceled;
|
---|
1346 | pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
|
---|
1347 | if (fCanceled)
|
---|
1348 | return -1;
|
---|
1349 | pTask->pProgress->SetCurrentOperationProgress(uPercent);
|
---|
1350 | }
|
---|
1351 | return VINF_SUCCESS;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | /**
|
---|
1355 | * Worker for TaskCloud::handler.
|
---|
1356 | * @thread pTask The task.
|
---|
1357 | */
|
---|
1358 | /* static */
|
---|
1359 | void Appliance::i_importOrExportCloudThreadTask(TaskCloud *pTask)
|
---|
1360 | {
|
---|
1361 | LogFlowFuncEnter();
|
---|
1362 | AssertReturnVoid(pTask);
|
---|
1363 |
|
---|
1364 | Appliance *pAppliance = pTask->pAppliance;
|
---|
1365 | LogFlowFunc(("Appliance %p taskType=%d\n", pAppliance, pTask->taskType));
|
---|
1366 |
|
---|
1367 | switch (pTask->taskType)
|
---|
1368 | {
|
---|
1369 | case TaskCloud::Export:
|
---|
1370 | pAppliance->i_setApplianceState(ApplianceExporting);
|
---|
1371 | pTask->rc = pAppliance->i_exportCloudImpl(pTask);
|
---|
1372 | break;
|
---|
1373 | case TaskCloud::Import:
|
---|
1374 | pAppliance->i_setApplianceState(ApplianceImporting);
|
---|
1375 | pTask->rc = pAppliance->i_importCloudImpl(pTask);
|
---|
1376 | break;
|
---|
1377 | case TaskCloud::ReadData:
|
---|
1378 | pAppliance->i_setApplianceState(ApplianceImporting);
|
---|
1379 | pTask->rc = pAppliance->i_gettingCloudData(pTask);
|
---|
1380 | break;
|
---|
1381 | default:
|
---|
1382 | AssertFailed();
|
---|
1383 | pTask->rc = E_FAIL;
|
---|
1384 | break;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | pAppliance->i_setApplianceState(ApplianceIdle);
|
---|
1388 |
|
---|
1389 | if (!pTask->pProgress.isNull())
|
---|
1390 | pTask->pProgress->i_notifyComplete(pTask->rc);
|
---|
1391 |
|
---|
1392 | LogFlowFuncLeave();
|
---|
1393 | }
|
---|
1394 |
|
---|
1395 | /* static */
|
---|
1396 | DECLCALLBACK(int) Appliance::TaskCloud::updateProgress(unsigned uPercent, void *pvUser)
|
---|
1397 | {
|
---|
1398 | Appliance::TaskCloud* pTask = *(Appliance::TaskCloud**)pvUser;
|
---|
1399 |
|
---|
1400 | if ( pTask
|
---|
1401 | && !pTask->pProgress.isNull())
|
---|
1402 | {
|
---|
1403 | BOOL fCanceled;
|
---|
1404 | pTask->pProgress->COMGETTER(Canceled)(&fCanceled);
|
---|
1405 | if (fCanceled)
|
---|
1406 | return -1;
|
---|
1407 | pTask->pProgress->SetCurrentOperationProgress(uPercent);
|
---|
1408 | }
|
---|
1409 | return VINF_SUCCESS;
|
---|
1410 | }
|
---|
1411 |
|
---|
1412 | void i_parseURI(Utf8Str strUri, LocationInfo &locInfo)
|
---|
1413 | {
|
---|
1414 | /* Check the URI for the protocol */
|
---|
1415 | if (strUri.startsWith("file://", Utf8Str::CaseInsensitive)) /* File based */
|
---|
1416 | {
|
---|
1417 | locInfo.storageType = VFSType_File;
|
---|
1418 | strUri = strUri.substr(sizeof("file://") - 1);
|
---|
1419 | }
|
---|
1420 | else if (strUri.startsWith("SunCloud://", Utf8Str::CaseInsensitive)) /* Sun Cloud service */
|
---|
1421 | {
|
---|
1422 | locInfo.storageType = VFSType_S3;
|
---|
1423 | strUri = strUri.substr(sizeof("SunCloud://") - 1);
|
---|
1424 | }
|
---|
1425 | else if (strUri.startsWith("S3://", Utf8Str::CaseInsensitive)) /* S3 service */
|
---|
1426 | {
|
---|
1427 | locInfo.storageType = VFSType_S3;
|
---|
1428 | strUri = strUri.substr(sizeof("S3://") - 1);
|
---|
1429 | }
|
---|
1430 | else if (strUri.startsWith("OCI://", Utf8Str::CaseInsensitive)) /* OCI service (storage or compute) */
|
---|
1431 | {
|
---|
1432 | locInfo.storageType = VFSType_Cloud;
|
---|
1433 | locInfo.strProvider = "OCI";
|
---|
1434 | strUri = strUri.substr(sizeof("OCI://") - 1);
|
---|
1435 | }
|
---|
1436 | else if (strUri.startsWith("webdav://", Utf8Str::CaseInsensitive)) /* webdav service */
|
---|
1437 | throw E_NOTIMPL;
|
---|
1438 |
|
---|
1439 | /* Not necessary on a file based URI */
|
---|
1440 | // if (locInfo.storageType != VFSType_File)
|
---|
1441 | // {
|
---|
1442 | // size_t uppos = strUri.find("@"); /* username:password combo */
|
---|
1443 | // if (uppos != Utf8Str::npos)
|
---|
1444 | // {
|
---|
1445 | // locInfo.strUsername = strUri.substr(0, uppos);
|
---|
1446 | // strUri = strUri.substr(uppos + 1);
|
---|
1447 | // size_t upos = locInfo.strUsername.find(":");
|
---|
1448 | // if (upos != Utf8Str::npos)
|
---|
1449 | // {
|
---|
1450 | // locInfo.strPassword = locInfo.strUsername.substr(upos + 1);
|
---|
1451 | // locInfo.strUsername = locInfo.strUsername.substr(0, upos);
|
---|
1452 | // }
|
---|
1453 | // }
|
---|
1454 | // size_t hpos = strUri.find("/"); /* hostname part */
|
---|
1455 | // if (hpos != Utf8Str::npos)
|
---|
1456 | // {
|
---|
1457 | // locInfo.strHostname = strUri.substr(0, hpos);
|
---|
1458 | // strUri = strUri.substr(hpos);
|
---|
1459 | // }
|
---|
1460 | // }
|
---|
1461 |
|
---|
1462 | locInfo.strPath = strUri;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 |
|
---|
1466 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1467 | //
|
---|
1468 | // IVirtualSystemDescription constructor / destructor
|
---|
1469 | //
|
---|
1470 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1471 |
|
---|
1472 | /**
|
---|
1473 | * COM initializer.
|
---|
1474 | * @return
|
---|
1475 | */
|
---|
1476 | HRESULT VirtualSystemDescription::init()
|
---|
1477 | {
|
---|
1478 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
1479 | AutoInitSpan autoInitSpan(this);
|
---|
1480 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
1481 |
|
---|
1482 | /* Initialize data */
|
---|
1483 | m = new Data();
|
---|
1484 | m->pConfig = NULL;
|
---|
1485 |
|
---|
1486 | /* Confirm a successful initialization */
|
---|
1487 | autoInitSpan.setSucceeded();
|
---|
1488 | return S_OK;
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | /**
|
---|
1492 | * COM uninitializer.
|
---|
1493 | */
|
---|
1494 |
|
---|
1495 | void VirtualSystemDescription::uninit()
|
---|
1496 | {
|
---|
1497 | if (m->pConfig)
|
---|
1498 | delete m->pConfig;
|
---|
1499 | delete m;
|
---|
1500 | m = NULL;
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 |
|
---|
1504 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1505 | //
|
---|
1506 | // IVirtualSystemDescription public methods
|
---|
1507 | //
|
---|
1508 | ////////////////////////////////////////////////////////////////////////////////
|
---|
1509 |
|
---|
1510 | /**
|
---|
1511 | * Public method implementation.
|
---|
1512 | */
|
---|
1513 | HRESULT VirtualSystemDescription::getCount(ULONG *aCount)
|
---|
1514 | {
|
---|
1515 | if (!aCount)
|
---|
1516 | return E_POINTER;
|
---|
1517 |
|
---|
1518 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1519 |
|
---|
1520 | *aCount = (ULONG)m->maDescriptions.size();
|
---|
1521 | return S_OK;
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | /**
|
---|
1525 | * Public method implementation.
|
---|
1526 | */
|
---|
1527 | HRESULT VirtualSystemDescription::getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
1528 | std::vector<com::Utf8Str> &aRefs,
|
---|
1529 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
1530 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
1531 | std::vector<com::Utf8Str> &aExtraConfigValues)
|
---|
1532 |
|
---|
1533 | {
|
---|
1534 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1535 | size_t c = m->maDescriptions.size();
|
---|
1536 | aTypes.resize(c);
|
---|
1537 | aRefs.resize(c);
|
---|
1538 | aOVFValues.resize(c);
|
---|
1539 | aVBoxValues.resize(c);
|
---|
1540 | aExtraConfigValues.resize(c);
|
---|
1541 |
|
---|
1542 | for (size_t i = 0; i < c; i++)
|
---|
1543 | {
|
---|
1544 | const VirtualSystemDescriptionEntry &vsde = m->maDescriptions[i];
|
---|
1545 | aTypes[i] = vsde.type;
|
---|
1546 | aRefs[i] = vsde.strRef;
|
---|
1547 | aOVFValues[i] = vsde.strOvf;
|
---|
1548 | aVBoxValues[i] = vsde.strVBoxCurrent;
|
---|
1549 | aExtraConfigValues[i] = vsde.strExtraConfigCurrent;
|
---|
1550 | }
|
---|
1551 | return S_OK;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | /**
|
---|
1555 | * Public method implementation.
|
---|
1556 | */
|
---|
1557 | HRESULT VirtualSystemDescription::getDescriptionByType(VirtualSystemDescriptionType_T aType,
|
---|
1558 | std::vector<VirtualSystemDescriptionType_T> &aTypes,
|
---|
1559 | std::vector<com::Utf8Str> &aRefs,
|
---|
1560 | std::vector<com::Utf8Str> &aOVFValues,
|
---|
1561 | std::vector<com::Utf8Str> &aVBoxValues,
|
---|
1562 | std::vector<com::Utf8Str> &aExtraConfigValues)
|
---|
1563 | {
|
---|
1564 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1565 | std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType(aType);
|
---|
1566 |
|
---|
1567 | size_t c = vsd.size();
|
---|
1568 | aTypes.resize(c);
|
---|
1569 | aRefs.resize(c);
|
---|
1570 | aOVFValues.resize(c);
|
---|
1571 | aVBoxValues.resize(c);
|
---|
1572 | aExtraConfigValues.resize(c);
|
---|
1573 |
|
---|
1574 | size_t i = 0;
|
---|
1575 | for (list<VirtualSystemDescriptionEntry*>::const_iterator it = vsd.begin(); it != vsd.end(); ++it, ++i)
|
---|
1576 | {
|
---|
1577 | const VirtualSystemDescriptionEntry *vsde = (*it);
|
---|
1578 | aTypes[i] = vsde->type;
|
---|
1579 | aRefs[i] = vsde->strRef;
|
---|
1580 | aOVFValues[i] = vsde->strOvf;
|
---|
1581 | aVBoxValues[i] = vsde->strVBoxCurrent;
|
---|
1582 | aExtraConfigValues[i] = vsde->strExtraConfigCurrent;
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | return S_OK;
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | /**
|
---|
1589 | * Public method implementation.
|
---|
1590 | */
|
---|
1591 | HRESULT VirtualSystemDescription::getValuesByType(VirtualSystemDescriptionType_T aType,
|
---|
1592 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
1593 | std::vector<com::Utf8Str> &aValues)
|
---|
1594 | {
|
---|
1595 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1596 |
|
---|
1597 | std::list<VirtualSystemDescriptionEntry*> vsd = i_findByType (aType);
|
---|
1598 | aValues.resize((ULONG)vsd.size());
|
---|
1599 |
|
---|
1600 | list<VirtualSystemDescriptionEntry*>::const_iterator it;
|
---|
1601 | size_t i = 0;
|
---|
1602 | for (it = vsd.begin();
|
---|
1603 | it != vsd.end();
|
---|
1604 | ++it, ++i)
|
---|
1605 | {
|
---|
1606 | const VirtualSystemDescriptionEntry *vsde = (*it);
|
---|
1607 |
|
---|
1608 | Bstr bstr;
|
---|
1609 | switch (aWhich)
|
---|
1610 | {
|
---|
1611 | case VirtualSystemDescriptionValueType_Reference: aValues[i] = vsde->strRef; break;
|
---|
1612 | case VirtualSystemDescriptionValueType_Original: aValues[i] = vsde->strOvf; break;
|
---|
1613 | case VirtualSystemDescriptionValueType_Auto: aValues[i] = vsde->strVBoxCurrent; break;
|
---|
1614 | case VirtualSystemDescriptionValueType_ExtraConfig: aValues[i] = vsde->strExtraConfigCurrent; break;
|
---|
1615 | #ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
|
---|
1616 | case VirtualSystemDescriptionValueType_32BitHack: AssertFailedBreak(); /* (compiler warnings) */
|
---|
1617 | #endif
|
---|
1618 | }
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | return S_OK;
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 | /**
|
---|
1625 | * Public method implementation.
|
---|
1626 | */
|
---|
1627 | HRESULT VirtualSystemDescription::setFinalValues(const std::vector<BOOL> &aEnabled,
|
---|
1628 | const std::vector<com::Utf8Str> &aVBoxValues,
|
---|
1629 | const std::vector<com::Utf8Str> &aExtraConfigValues)
|
---|
1630 | {
|
---|
1631 | #ifndef RT_OS_WINDOWS
|
---|
1632 | // NOREF(aEnabledSize);
|
---|
1633 | #endif /* RT_OS_WINDOWS */
|
---|
1634 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1635 |
|
---|
1636 | if ( (aEnabled.size() != m->maDescriptions.size())
|
---|
1637 | || (aVBoxValues.size() != m->maDescriptions.size())
|
---|
1638 | || (aExtraConfigValues.size() != m->maDescriptions.size())
|
---|
1639 | )
|
---|
1640 | return E_INVALIDARG;
|
---|
1641 |
|
---|
1642 | size_t i = 0;
|
---|
1643 | for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
|
---|
1644 | it != m->maDescriptions.end();
|
---|
1645 | ++it, ++i)
|
---|
1646 | {
|
---|
1647 | VirtualSystemDescriptionEntry& vsde = *it;
|
---|
1648 |
|
---|
1649 | if (aEnabled[i])
|
---|
1650 | {
|
---|
1651 | vsde.strVBoxCurrent = aVBoxValues[i];
|
---|
1652 | vsde.strExtraConfigCurrent = aExtraConfigValues[i];
|
---|
1653 | }
|
---|
1654 | else
|
---|
1655 | vsde.type = VirtualSystemDescriptionType_Ignore;
|
---|
1656 | }
|
---|
1657 |
|
---|
1658 | return S_OK;
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | /**
|
---|
1662 | * Public method implementation.
|
---|
1663 | */
|
---|
1664 | HRESULT VirtualSystemDescription::addDescription(VirtualSystemDescriptionType_T aType,
|
---|
1665 | const com::Utf8Str &aVBoxValue,
|
---|
1666 | const com::Utf8Str &aExtraConfigValue)
|
---|
1667 |
|
---|
1668 | {
|
---|
1669 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
1670 | i_addEntry(aType, "", aVBoxValue, aVBoxValue, 0, aExtraConfigValue);
|
---|
1671 | return S_OK;
|
---|
1672 | }
|
---|
1673 |
|
---|
1674 | /**
|
---|
1675 | * Internal method; adds a new description item to the member list.
|
---|
1676 | * @param aType Type of description for the new item.
|
---|
1677 | * @param strRef Reference item; only used with storage controllers.
|
---|
1678 | * @param aOvfValue Corresponding original value from OVF.
|
---|
1679 | * @param aVBoxValue Initial configuration value (can be overridden by caller with setFinalValues).
|
---|
1680 | * @param ulSizeMB Weight for IProgress
|
---|
1681 | * @param strExtraConfig Extra configuration; meaning dependent on type.
|
---|
1682 | */
|
---|
1683 | void VirtualSystemDescription::i_addEntry(VirtualSystemDescriptionType_T aType,
|
---|
1684 | const Utf8Str &strRef,
|
---|
1685 | const Utf8Str &aOvfValue,
|
---|
1686 | const Utf8Str &aVBoxValue,
|
---|
1687 | uint32_t ulSizeMB,
|
---|
1688 | const Utf8Str &strExtraConfig /*= ""*/)
|
---|
1689 | {
|
---|
1690 | VirtualSystemDescriptionEntry vsde;
|
---|
1691 | vsde.ulIndex = (uint32_t)m->maDescriptions.size(); // each entry gets an index so the client side can reference them
|
---|
1692 | vsde.type = aType;
|
---|
1693 | vsde.strRef = strRef;
|
---|
1694 | vsde.strOvf = aOvfValue;
|
---|
1695 | vsde.strVBoxSuggested /* remember original value */
|
---|
1696 | = vsde.strVBoxCurrent /* and set current value which can be overridden by setFinalValues() */
|
---|
1697 | = aVBoxValue;
|
---|
1698 | vsde.strExtraConfigSuggested
|
---|
1699 | = vsde.strExtraConfigCurrent
|
---|
1700 | = strExtraConfig;
|
---|
1701 | vsde.ulSizeMB = ulSizeMB;
|
---|
1702 |
|
---|
1703 | vsde.skipIt = false;
|
---|
1704 |
|
---|
1705 | m->maDescriptions.push_back(vsde);
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | /**
|
---|
1709 | * Private method; returns a list of description items containing all the items from the member
|
---|
1710 | * description items of this virtual system that match the given type.
|
---|
1711 | */
|
---|
1712 | std::list<VirtualSystemDescriptionEntry*> VirtualSystemDescription::i_findByType(VirtualSystemDescriptionType_T aType)
|
---|
1713 | {
|
---|
1714 | std::list<VirtualSystemDescriptionEntry*> vsd;
|
---|
1715 | for (vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
|
---|
1716 | it != m->maDescriptions.end();
|
---|
1717 | ++it)
|
---|
1718 | {
|
---|
1719 | if (it->type == aType)
|
---|
1720 | vsd.push_back(&(*it));
|
---|
1721 | }
|
---|
1722 |
|
---|
1723 | return vsd;
|
---|
1724 | }
|
---|
1725 |
|
---|
1726 | HRESULT VirtualSystemDescription::removeDescriptionByType(VirtualSystemDescriptionType_T aType)
|
---|
1727 | {
|
---|
1728 | std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
|
---|
1729 | while (it != m->maDescriptions.end())
|
---|
1730 | {
|
---|
1731 | if (it->type == aType)
|
---|
1732 | it = m->maDescriptions.erase(it);
|
---|
1733 | else
|
---|
1734 | ++it;
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 | return S_OK;
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | /* Private method; delete all records from the list
|
---|
1741 | * m->llDescriptions that match the given type.
|
---|
1742 | */
|
---|
1743 | void VirtualSystemDescription::i_removeByType(VirtualSystemDescriptionType_T aType)
|
---|
1744 | {
|
---|
1745 | std::vector<VirtualSystemDescriptionEntry>::iterator it = m->maDescriptions.begin();
|
---|
1746 | while (it != m->maDescriptions.end())
|
---|
1747 | {
|
---|
1748 | if (it->type == aType)
|
---|
1749 | it = m->maDescriptions.erase(it);
|
---|
1750 | else
|
---|
1751 | ++it;
|
---|
1752 | }
|
---|
1753 | }
|
---|
1754 |
|
---|
1755 | /**
|
---|
1756 | * Private method; looks thru the member hardware items for the IDE, SATA, or SCSI controller with
|
---|
1757 | * the given reference ID. Useful when needing the controller for a particular
|
---|
1758 | * virtual disk.
|
---|
1759 | */
|
---|
1760 | const VirtualSystemDescriptionEntry* VirtualSystemDescription::i_findControllerFromID(const Utf8Str &id)
|
---|
1761 | {
|
---|
1762 | vector<VirtualSystemDescriptionEntry>::const_iterator it;
|
---|
1763 | for (it = m->maDescriptions.begin();
|
---|
1764 | it != m->maDescriptions.end();
|
---|
1765 | ++it)
|
---|
1766 | {
|
---|
1767 | const VirtualSystemDescriptionEntry &d = *it;
|
---|
1768 | switch (d.type)
|
---|
1769 | {
|
---|
1770 | case VirtualSystemDescriptionType_HardDiskControllerIDE:
|
---|
1771 | case VirtualSystemDescriptionType_HardDiskControllerSATA:
|
---|
1772 | case VirtualSystemDescriptionType_HardDiskControllerSCSI:
|
---|
1773 | case VirtualSystemDescriptionType_HardDiskControllerVirtioSCSI:
|
---|
1774 | case VirtualSystemDescriptionType_HardDiskControllerSAS:
|
---|
1775 | if (d.strRef == id)
|
---|
1776 | return &d;
|
---|
1777 | break;
|
---|
1778 | default: break; /* Shut up MSC. */
|
---|
1779 | }
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | return NULL;
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | /**
|
---|
1786 | * Method called from Appliance::Interpret() if the source OVF for a virtual system
|
---|
1787 | * contains a <vbox:Machine> element. This method then attempts to parse that and
|
---|
1788 | * create a MachineConfigFile instance from it which is stored in this instance data
|
---|
1789 | * and can then be used to create a machine.
|
---|
1790 | *
|
---|
1791 | * This must only be called once per instance.
|
---|
1792 | *
|
---|
1793 | * This rethrows all XML and logic errors from MachineConfigFile.
|
---|
1794 | *
|
---|
1795 | * @param elmMachine <vbox:Machine> element with attributes and subelements from some
|
---|
1796 | * DOM tree.
|
---|
1797 | */
|
---|
1798 | void VirtualSystemDescription::i_importVBoxMachineXML(const xml::ElementNode &elmMachine)
|
---|
1799 | {
|
---|
1800 | settings::MachineConfigFile *pConfig = NULL;
|
---|
1801 |
|
---|
1802 | Assert(m->pConfig == NULL);
|
---|
1803 |
|
---|
1804 | try
|
---|
1805 | {
|
---|
1806 | pConfig = new settings::MachineConfigFile(NULL);
|
---|
1807 | pConfig->importMachineXML(elmMachine);
|
---|
1808 |
|
---|
1809 | m->pConfig = pConfig;
|
---|
1810 | }
|
---|
1811 | catch (...)
|
---|
1812 | {
|
---|
1813 | if (pConfig)
|
---|
1814 | delete pConfig;
|
---|
1815 | throw;
|
---|
1816 | }
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 | /**
|
---|
1820 | * Returns the machine config created by importVBoxMachineXML() or NULL if there's none.
|
---|
1821 | */
|
---|
1822 | const settings::MachineConfigFile* VirtualSystemDescription::i_getMachineConfig() const
|
---|
1823 | {
|
---|
1824 | return m->pConfig;
|
---|
1825 | }
|
---|
1826 |
|
---|