1 | /* $Id: VBoxManageAppliance.cpp 72823 2018-07-03 14:31:50Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - The appliance-related commands.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-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 VBOX_ONLY_DOCS
|
---|
19 |
|
---|
20 |
|
---|
21 | /*********************************************************************************************************************************
|
---|
22 | * Header Files *
|
---|
23 | *********************************************************************************************************************************/
|
---|
24 | #ifndef VBOX_ONLY_DOCS
|
---|
25 | #include <VBox/com/com.h>
|
---|
26 | #include <VBox/com/string.h>
|
---|
27 | #include <VBox/com/Guid.h>
|
---|
28 | #include <VBox/com/array.h>
|
---|
29 | #include <VBox/com/ErrorInfo.h>
|
---|
30 | #include <VBox/com/errorprint.h>
|
---|
31 | #include <VBox/com/VirtualBox.h>
|
---|
32 |
|
---|
33 | #include <list>
|
---|
34 | #include <map>
|
---|
35 | #endif /* !VBOX_ONLY_DOCS */
|
---|
36 |
|
---|
37 | #include <iprt/stream.h>
|
---|
38 | #include <iprt/getopt.h>
|
---|
39 | #include <iprt/ctype.h>
|
---|
40 | #include <iprt/path.h>
|
---|
41 | #include <iprt/file.h>
|
---|
42 |
|
---|
43 | #include <VBox/log.h>
|
---|
44 | #include <VBox/param.h>
|
---|
45 |
|
---|
46 | #include "VBoxManage.h"
|
---|
47 | using namespace com;
|
---|
48 |
|
---|
49 |
|
---|
50 | // funcs
|
---|
51 | ///////////////////////////////////////////////////////////////////////////////
|
---|
52 |
|
---|
53 | typedef std::map<Utf8Str, Utf8Str> ArgsMap; // pairs of strings like "vmname" => "newvmname"
|
---|
54 | typedef std::map<uint32_t, ArgsMap> ArgsMapsMap; // map of maps, one for each virtual system, sorted by index
|
---|
55 |
|
---|
56 | typedef std::map<uint32_t, bool> IgnoresMap; // pairs of numeric description entry indices
|
---|
57 | typedef std::map<uint32_t, IgnoresMap> IgnoresMapsMap; // map of maps, one for each virtual system, sorted by index
|
---|
58 |
|
---|
59 | static bool findArgValue(Utf8Str &strOut,
|
---|
60 | ArgsMap *pmapArgs,
|
---|
61 | const Utf8Str &strKey)
|
---|
62 | {
|
---|
63 | if (pmapArgs)
|
---|
64 | {
|
---|
65 | ArgsMap::iterator it;
|
---|
66 | it = pmapArgs->find(strKey);
|
---|
67 | if (it != pmapArgs->end())
|
---|
68 | {
|
---|
69 | strOut = it->second;
|
---|
70 | pmapArgs->erase(it);
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 |
|
---|
78 | static int parseImportOptions(const char *psz, com::SafeArray<ImportOptions_T> *options)
|
---|
79 | {
|
---|
80 | int rc = VINF_SUCCESS;
|
---|
81 | while (psz && *psz && RT_SUCCESS(rc))
|
---|
82 | {
|
---|
83 | size_t len;
|
---|
84 | const char *pszComma = strchr(psz, ',');
|
---|
85 | if (pszComma)
|
---|
86 | len = pszComma - psz;
|
---|
87 | else
|
---|
88 | len = strlen(psz);
|
---|
89 | if (len > 0)
|
---|
90 | {
|
---|
91 | if (!RTStrNICmp(psz, "KeepAllMACs", len))
|
---|
92 | options->push_back(ImportOptions_KeepAllMACs);
|
---|
93 | else if (!RTStrNICmp(psz, "KeepNATMACs", len))
|
---|
94 | options->push_back(ImportOptions_KeepNATMACs);
|
---|
95 | else if (!RTStrNICmp(psz, "ImportToVDI", len))
|
---|
96 | options->push_back(ImportOptions_ImportToVDI);
|
---|
97 | else
|
---|
98 | rc = VERR_PARSE_ERROR;
|
---|
99 | }
|
---|
100 | if (pszComma)
|
---|
101 | psz += len + 1;
|
---|
102 | else
|
---|
103 | psz += len;
|
---|
104 | }
|
---|
105 |
|
---|
106 | return rc;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static const RTGETOPTDEF g_aImportApplianceOptions[] =
|
---|
110 | {
|
---|
111 | { "--dry-run", 'n', RTGETOPT_REQ_NOTHING },
|
---|
112 | { "-dry-run", 'n', RTGETOPT_REQ_NOTHING }, // deprecated
|
---|
113 | { "--dryrun", 'n', RTGETOPT_REQ_NOTHING },
|
---|
114 | { "-dryrun", 'n', RTGETOPT_REQ_NOTHING }, // deprecated
|
---|
115 | { "--detailed-progress", 'P', RTGETOPT_REQ_NOTHING },
|
---|
116 | { "-detailed-progress", 'P', RTGETOPT_REQ_NOTHING }, // deprecated
|
---|
117 | { "--vsys", 's', RTGETOPT_REQ_UINT32 },
|
---|
118 | { "-vsys", 's', RTGETOPT_REQ_UINT32 }, // deprecated
|
---|
119 | { "--ostype", 'o', RTGETOPT_REQ_STRING },
|
---|
120 | { "-ostype", 'o', RTGETOPT_REQ_STRING }, // deprecated
|
---|
121 | { "--vmname", 'V', RTGETOPT_REQ_STRING },
|
---|
122 | { "-vmname", 'V', RTGETOPT_REQ_STRING }, // deprecated
|
---|
123 | { "--settingsfile", 'S', RTGETOPT_REQ_STRING },
|
---|
124 | { "--basefolder", 'p', RTGETOPT_REQ_STRING },
|
---|
125 | { "--group", 'g', RTGETOPT_REQ_STRING },
|
---|
126 | { "--memory", 'm', RTGETOPT_REQ_STRING },
|
---|
127 | { "-memory", 'm', RTGETOPT_REQ_STRING }, // deprecated
|
---|
128 | { "--cpus", 'c', RTGETOPT_REQ_STRING },
|
---|
129 | { "--description", 'd', RTGETOPT_REQ_STRING },
|
---|
130 | { "--eula", 'L', RTGETOPT_REQ_STRING },
|
---|
131 | { "-eula", 'L', RTGETOPT_REQ_STRING }, // deprecated
|
---|
132 | { "--unit", 'u', RTGETOPT_REQ_UINT32 },
|
---|
133 | { "-unit", 'u', RTGETOPT_REQ_UINT32 }, // deprecated
|
---|
134 | { "--ignore", 'x', RTGETOPT_REQ_NOTHING },
|
---|
135 | { "-ignore", 'x', RTGETOPT_REQ_NOTHING }, // deprecated
|
---|
136 | { "--scsitype", 'T', RTGETOPT_REQ_UINT32 },
|
---|
137 | { "-scsitype", 'T', RTGETOPT_REQ_UINT32 }, // deprecated
|
---|
138 | { "--type", 'T', RTGETOPT_REQ_UINT32 }, // deprecated
|
---|
139 | { "-type", 'T', RTGETOPT_REQ_UINT32 }, // deprecated
|
---|
140 | #if 0 /* Changing the controller is fully valid, but the current design on how
|
---|
141 | the params are evaluated here doesn't allow two parameter for one
|
---|
142 | unit. The target disk path is more important. I leave it for future
|
---|
143 | improvments. */
|
---|
144 | { "--controller", 'C', RTGETOPT_REQ_STRING },
|
---|
145 | #endif
|
---|
146 | { "--disk", 'D', RTGETOPT_REQ_STRING },
|
---|
147 | { "--options", 'O', RTGETOPT_REQ_STRING },
|
---|
148 | };
|
---|
149 |
|
---|
150 | RTEXITCODE handleImportAppliance(HandlerArg *arg)
|
---|
151 | {
|
---|
152 | HRESULT rc = S_OK;
|
---|
153 |
|
---|
154 | Utf8Str strOvfFilename;
|
---|
155 | bool fExecute = true; // if true, then we actually do the import
|
---|
156 | com::SafeArray<ImportOptions_T> options;
|
---|
157 | uint32_t ulCurVsys = (uint32_t)-1;
|
---|
158 | uint32_t ulCurUnit = (uint32_t)-1;
|
---|
159 | // for each --vsys X command, maintain a map of command line items
|
---|
160 | // (we'll parse them later after interpreting the OVF, when we can
|
---|
161 | // actually check whether they make sense semantically)
|
---|
162 | ArgsMapsMap mapArgsMapsPerVsys;
|
---|
163 | IgnoresMapsMap mapIgnoresMapsPerVsys;
|
---|
164 |
|
---|
165 | int c;
|
---|
166 | RTGETOPTUNION ValueUnion;
|
---|
167 | RTGETOPTSTATE GetState;
|
---|
168 | // start at 0 because main() has hacked both the argc and argv given to us
|
---|
169 | RTGetOptInit(&GetState, arg->argc, arg->argv, g_aImportApplianceOptions, RT_ELEMENTS(g_aImportApplianceOptions),
|
---|
170 | 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
|
---|
171 | while ((c = RTGetOpt(&GetState, &ValueUnion)))
|
---|
172 | {
|
---|
173 | switch (c)
|
---|
174 | {
|
---|
175 | case 'n': // --dry-run
|
---|
176 | fExecute = false;
|
---|
177 | break;
|
---|
178 |
|
---|
179 | case 'P': // --detailed-progress
|
---|
180 | g_fDetailedProgress = true;
|
---|
181 | break;
|
---|
182 |
|
---|
183 | case 's': // --vsys
|
---|
184 | ulCurVsys = ValueUnion.u32;
|
---|
185 | ulCurUnit = (uint32_t)-1;
|
---|
186 | break;
|
---|
187 |
|
---|
188 | case 'o': // --ostype
|
---|
189 | if (ulCurVsys == (uint32_t)-1)
|
---|
190 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
191 | mapArgsMapsPerVsys[ulCurVsys]["ostype"] = ValueUnion.psz;
|
---|
192 | break;
|
---|
193 |
|
---|
194 | case 'V': // --vmname
|
---|
195 | if (ulCurVsys == (uint32_t)-1)
|
---|
196 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
197 | mapArgsMapsPerVsys[ulCurVsys]["vmname"] = ValueUnion.psz;
|
---|
198 | break;
|
---|
199 |
|
---|
200 | case 'S': // --settingsfile
|
---|
201 | if (ulCurVsys == (uint32_t)-1)
|
---|
202 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
203 | mapArgsMapsPerVsys[ulCurVsys]["settingsfile"] = ValueUnion.psz;
|
---|
204 | break;
|
---|
205 |
|
---|
206 | case 'p': // --basefolder
|
---|
207 | if (ulCurVsys == (uint32_t)-1)
|
---|
208 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
209 | mapArgsMapsPerVsys[ulCurVsys]["basefolder"] = ValueUnion.psz;
|
---|
210 | break;
|
---|
211 |
|
---|
212 | case 'g': // --group
|
---|
213 | if (ulCurVsys == (uint32_t)-1)
|
---|
214 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
215 | mapArgsMapsPerVsys[ulCurVsys]["group"] = ValueUnion.psz;
|
---|
216 | break;
|
---|
217 |
|
---|
218 | case 'd': // --description
|
---|
219 | if (ulCurVsys == (uint32_t)-1)
|
---|
220 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
221 | mapArgsMapsPerVsys[ulCurVsys]["description"] = ValueUnion.psz;
|
---|
222 | break;
|
---|
223 |
|
---|
224 | case 'L': // --eula
|
---|
225 | if (ulCurVsys == (uint32_t)-1)
|
---|
226 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
227 | mapArgsMapsPerVsys[ulCurVsys]["eula"] = ValueUnion.psz;
|
---|
228 | break;
|
---|
229 |
|
---|
230 | case 'm': // --memory
|
---|
231 | if (ulCurVsys == (uint32_t)-1)
|
---|
232 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
233 | mapArgsMapsPerVsys[ulCurVsys]["memory"] = ValueUnion.psz;
|
---|
234 | break;
|
---|
235 |
|
---|
236 | case 'c': // --cpus
|
---|
237 | if (ulCurVsys == (uint32_t)-1)
|
---|
238 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
239 | mapArgsMapsPerVsys[ulCurVsys]["cpus"] = ValueUnion.psz;
|
---|
240 | break;
|
---|
241 |
|
---|
242 | case 'u': // --unit
|
---|
243 | ulCurUnit = ValueUnion.u32;
|
---|
244 | break;
|
---|
245 |
|
---|
246 | case 'x': // --ignore
|
---|
247 | if (ulCurVsys == (uint32_t)-1)
|
---|
248 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
249 | if (ulCurUnit == (uint32_t)-1)
|
---|
250 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong);
|
---|
251 | mapIgnoresMapsPerVsys[ulCurVsys][ulCurUnit] = true;
|
---|
252 | break;
|
---|
253 |
|
---|
254 | case 'T': // --scsitype
|
---|
255 | if (ulCurVsys == (uint32_t)-1)
|
---|
256 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
257 | if (ulCurUnit == (uint32_t)-1)
|
---|
258 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong);
|
---|
259 | mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("scsitype%u", ulCurUnit)] = ValueUnion.psz;
|
---|
260 | break;
|
---|
261 |
|
---|
262 | case 'C': // --controller
|
---|
263 | if (ulCurVsys == (uint32_t)-1)
|
---|
264 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
265 | if (ulCurUnit == (uint32_t)-1)
|
---|
266 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong);
|
---|
267 | mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("controller%u", ulCurUnit)] = ValueUnion.psz;
|
---|
268 | break;
|
---|
269 |
|
---|
270 | case 'D': // --disk
|
---|
271 | if (ulCurVsys == (uint32_t)-1)
|
---|
272 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
273 | if (ulCurUnit == (uint32_t)-1)
|
---|
274 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong);
|
---|
275 | mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("disk%u", ulCurUnit)] = ValueUnion.psz;
|
---|
276 | break;
|
---|
277 |
|
---|
278 | case 'O': // --options
|
---|
279 | if (RT_FAILURE(parseImportOptions(ValueUnion.psz, &options)))
|
---|
280 | return errorArgument("Invalid import options '%s'\n", ValueUnion.psz);
|
---|
281 | break;
|
---|
282 |
|
---|
283 | case VINF_GETOPT_NOT_OPTION:
|
---|
284 | if (strOvfFilename.isEmpty())
|
---|
285 | strOvfFilename = ValueUnion.psz;
|
---|
286 | else
|
---|
287 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid parameter '%s'", ValueUnion.psz);
|
---|
288 | break;
|
---|
289 |
|
---|
290 | default:
|
---|
291 | if (c > 0)
|
---|
292 | {
|
---|
293 | if (RT_C_IS_PRINT(c))
|
---|
294 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid option -%c", c);
|
---|
295 | else
|
---|
296 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid option case %i", c);
|
---|
297 | }
|
---|
298 | else if (c == VERR_GETOPT_UNKNOWN_OPTION)
|
---|
299 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "unknown option: %s\n", ValueUnion.psz);
|
---|
300 | else if (ValueUnion.pDef)
|
---|
301 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
|
---|
302 | else
|
---|
303 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "error: %Rrs", c);
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | if (strOvfFilename.isEmpty())
|
---|
308 | return errorSyntax(USAGE_IMPORTAPPLIANCE, "Not enough arguments for \"import\" command.");
|
---|
309 |
|
---|
310 | do
|
---|
311 | {
|
---|
312 | ComPtr<IAppliance> pAppliance;
|
---|
313 | CHECK_ERROR_BREAK(arg->virtualBox, CreateAppliance(pAppliance.asOutParam()));
|
---|
314 |
|
---|
315 | char *pszAbsFilePath;
|
---|
316 | if (strOvfFilename.startsWith("S3://", RTCString::CaseInsensitive) ||
|
---|
317 | strOvfFilename.startsWith("SunCloud://", RTCString::CaseInsensitive) ||
|
---|
318 | strOvfFilename.startsWith("webdav://", RTCString::CaseInsensitive))
|
---|
319 | pszAbsFilePath = RTStrDup(strOvfFilename.c_str());
|
---|
320 | else
|
---|
321 | pszAbsFilePath = RTPathAbsDup(strOvfFilename.c_str());
|
---|
322 | ComPtr<IProgress> progressRead;
|
---|
323 | CHECK_ERROR_BREAK(pAppliance, Read(Bstr(pszAbsFilePath).raw(),
|
---|
324 | progressRead.asOutParam()));
|
---|
325 | RTStrFree(pszAbsFilePath);
|
---|
326 |
|
---|
327 | rc = showProgress(progressRead);
|
---|
328 | CHECK_PROGRESS_ERROR_RET(progressRead, ("Appliance read failed"), RTEXITCODE_FAILURE);
|
---|
329 |
|
---|
330 | Bstr path; /* fetch the path, there is stuff like username/password removed if any */
|
---|
331 | CHECK_ERROR_BREAK(pAppliance, COMGETTER(Path)(path.asOutParam()));
|
---|
332 | // call interpret(); this can yield both warnings and errors, so we need
|
---|
333 | // to tinker with the error info a bit
|
---|
334 | RTStrmPrintf(g_pStdErr, "Interpreting %ls...\n", path.raw());
|
---|
335 | rc = pAppliance->Interpret();
|
---|
336 | com::ErrorInfo info0(pAppliance, COM_IIDOF(IAppliance));
|
---|
337 |
|
---|
338 | com::SafeArray<BSTR> aWarnings;
|
---|
339 | if (SUCCEEDED(pAppliance->GetWarnings(ComSafeArrayAsOutParam(aWarnings))))
|
---|
340 | {
|
---|
341 | size_t cWarnings = aWarnings.size();
|
---|
342 | for (unsigned i = 0; i < cWarnings; ++i)
|
---|
343 | {
|
---|
344 | Bstr bstrWarning(aWarnings[i]);
|
---|
345 | RTMsgWarning("%ls.", bstrWarning.raw());
|
---|
346 | }
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (FAILED(rc)) // during interpret, after printing warnings
|
---|
350 | {
|
---|
351 | com::GluePrintErrorInfo(info0);
|
---|
352 | com::GluePrintErrorContext("Interpret", __FILE__, __LINE__);
|
---|
353 | break;
|
---|
354 | }
|
---|
355 |
|
---|
356 | RTStrmPrintf(g_pStdErr, "OK.\n");
|
---|
357 |
|
---|
358 | // fetch all disks
|
---|
359 | com::SafeArray<BSTR> retDisks;
|
---|
360 | CHECK_ERROR_BREAK(pAppliance,
|
---|
361 | COMGETTER(Disks)(ComSafeArrayAsOutParam(retDisks)));
|
---|
362 | if (retDisks.size() > 0)
|
---|
363 | {
|
---|
364 | RTPrintf("Disks:\n");
|
---|
365 | for (unsigned i = 0; i < retDisks.size(); i++)
|
---|
366 | RTPrintf(" %ls\n", retDisks[i]);
|
---|
367 | RTPrintf("\n");
|
---|
368 | }
|
---|
369 |
|
---|
370 | // fetch virtual system descriptions
|
---|
371 | com::SafeIfaceArray<IVirtualSystemDescription> aVirtualSystemDescriptions;
|
---|
372 | CHECK_ERROR_BREAK(pAppliance,
|
---|
373 | COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(aVirtualSystemDescriptions)));
|
---|
374 |
|
---|
375 | size_t cVirtualSystemDescriptions = aVirtualSystemDescriptions.size();
|
---|
376 |
|
---|
377 | // match command line arguments with virtual system descriptions;
|
---|
378 | // this is only to sort out invalid indices at this time
|
---|
379 | ArgsMapsMap::const_iterator it;
|
---|
380 | for (it = mapArgsMapsPerVsys.begin();
|
---|
381 | it != mapArgsMapsPerVsys.end();
|
---|
382 | ++it)
|
---|
383 | {
|
---|
384 | uint32_t ulVsys = it->first;
|
---|
385 | if (ulVsys >= cVirtualSystemDescriptions)
|
---|
386 | return errorSyntax(USAGE_IMPORTAPPLIANCE,
|
---|
387 | "Invalid index %RI32 with -vsys option; the OVF contains only %zu virtual system(s).",
|
---|
388 | ulVsys, cVirtualSystemDescriptions);
|
---|
389 | }
|
---|
390 |
|
---|
391 | uint32_t cLicensesInTheWay = 0;
|
---|
392 |
|
---|
393 | // dump virtual system descriptions and match command-line arguments
|
---|
394 | if (cVirtualSystemDescriptions > 0)
|
---|
395 | {
|
---|
396 | for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i)
|
---|
397 | {
|
---|
398 | com::SafeArray<VirtualSystemDescriptionType_T> retTypes;
|
---|
399 | com::SafeArray<BSTR> aRefs;
|
---|
400 | com::SafeArray<BSTR> aOvfValues;
|
---|
401 | com::SafeArray<BSTR> aVBoxValues;
|
---|
402 | com::SafeArray<BSTR> aExtraConfigValues;
|
---|
403 | CHECK_ERROR_BREAK(aVirtualSystemDescriptions[i],
|
---|
404 | GetDescription(ComSafeArrayAsOutParam(retTypes),
|
---|
405 | ComSafeArrayAsOutParam(aRefs),
|
---|
406 | ComSafeArrayAsOutParam(aOvfValues),
|
---|
407 | ComSafeArrayAsOutParam(aVBoxValues),
|
---|
408 | ComSafeArrayAsOutParam(aExtraConfigValues)));
|
---|
409 |
|
---|
410 | RTPrintf("Virtual system %u:\n", i);
|
---|
411 |
|
---|
412 | // look up the corresponding command line options, if any
|
---|
413 | ArgsMap *pmapArgs = NULL;
|
---|
414 | ArgsMapsMap::iterator itm = mapArgsMapsPerVsys.find(i);
|
---|
415 | if (itm != mapArgsMapsPerVsys.end())
|
---|
416 | pmapArgs = &itm->second;
|
---|
417 |
|
---|
418 | // this collects the final values for setFinalValues()
|
---|
419 | com::SafeArray<BOOL> aEnabled(retTypes.size());
|
---|
420 | com::SafeArray<BSTR> aFinalValues(retTypes.size());
|
---|
421 |
|
---|
422 | for (unsigned a = 0; a < retTypes.size(); ++a)
|
---|
423 | {
|
---|
424 | VirtualSystemDescriptionType_T t = retTypes[a];
|
---|
425 |
|
---|
426 | Utf8Str strOverride;
|
---|
427 |
|
---|
428 | Bstr bstrFinalValue = aVBoxValues[a];
|
---|
429 |
|
---|
430 | bool fIgnoreThis = mapIgnoresMapsPerVsys[i][a];
|
---|
431 |
|
---|
432 | aEnabled[a] = true;
|
---|
433 |
|
---|
434 | switch (t)
|
---|
435 | {
|
---|
436 | case VirtualSystemDescriptionType_OS:
|
---|
437 | if (findArgValue(strOverride, pmapArgs, "ostype"))
|
---|
438 | {
|
---|
439 | bstrFinalValue = strOverride;
|
---|
440 | RTPrintf("%2u: OS type specified with --ostype: \"%ls\"\n",
|
---|
441 | a, bstrFinalValue.raw());
|
---|
442 | }
|
---|
443 | else
|
---|
444 | RTPrintf("%2u: Suggested OS type: \"%ls\""
|
---|
445 | "\n (change with \"--vsys %u --ostype <type>\"; use \"list ostypes\" to list all possible values)\n",
|
---|
446 | a, bstrFinalValue.raw(), i);
|
---|
447 | break;
|
---|
448 |
|
---|
449 | case VirtualSystemDescriptionType_Name:
|
---|
450 | if (findArgValue(strOverride, pmapArgs, "vmname"))
|
---|
451 | {
|
---|
452 | bstrFinalValue = strOverride;
|
---|
453 | RTPrintf("%2u: VM name specified with --vmname: \"%ls\"\n",
|
---|
454 | a, bstrFinalValue.raw());
|
---|
455 | }
|
---|
456 | else
|
---|
457 | RTPrintf("%2u: Suggested VM name \"%ls\""
|
---|
458 | "\n (change with \"--vsys %u --vmname <name>\")\n",
|
---|
459 | a, bstrFinalValue.raw(), i);
|
---|
460 | break;
|
---|
461 |
|
---|
462 | case VirtualSystemDescriptionType_Product:
|
---|
463 | RTPrintf("%2u: Product (ignored): %ls\n",
|
---|
464 | a, aVBoxValues[a]);
|
---|
465 | break;
|
---|
466 |
|
---|
467 | case VirtualSystemDescriptionType_ProductUrl:
|
---|
468 | RTPrintf("%2u: ProductUrl (ignored): %ls\n",
|
---|
469 | a, aVBoxValues[a]);
|
---|
470 | break;
|
---|
471 |
|
---|
472 | case VirtualSystemDescriptionType_Vendor:
|
---|
473 | RTPrintf("%2u: Vendor (ignored): %ls\n",
|
---|
474 | a, aVBoxValues[a]);
|
---|
475 | break;
|
---|
476 |
|
---|
477 | case VirtualSystemDescriptionType_VendorUrl:
|
---|
478 | RTPrintf("%2u: VendorUrl (ignored): %ls\n",
|
---|
479 | a, aVBoxValues[a]);
|
---|
480 | break;
|
---|
481 |
|
---|
482 | case VirtualSystemDescriptionType_Version:
|
---|
483 | RTPrintf("%2u: Version (ignored): %ls\n",
|
---|
484 | a, aVBoxValues[a]);
|
---|
485 | break;
|
---|
486 |
|
---|
487 | case VirtualSystemDescriptionType_Description:
|
---|
488 | if (findArgValue(strOverride, pmapArgs, "description"))
|
---|
489 | {
|
---|
490 | bstrFinalValue = strOverride;
|
---|
491 | RTPrintf("%2u: Description specified with --description: \"%ls\"\n",
|
---|
492 | a, bstrFinalValue.raw());
|
---|
493 | }
|
---|
494 | else
|
---|
495 | RTPrintf("%2u: Description \"%ls\""
|
---|
496 | "\n (change with \"--vsys %u --description <desc>\")\n",
|
---|
497 | a, bstrFinalValue.raw(), i);
|
---|
498 | break;
|
---|
499 |
|
---|
500 | case VirtualSystemDescriptionType_License:
|
---|
501 | ++cLicensesInTheWay;
|
---|
502 | if (findArgValue(strOverride, pmapArgs, "eula"))
|
---|
503 | {
|
---|
504 | if (strOverride == "show")
|
---|
505 | {
|
---|
506 | RTPrintf("%2u: End-user license agreement"
|
---|
507 | "\n (accept with \"--vsys %u --eula accept\"):"
|
---|
508 | "\n\n%ls\n\n",
|
---|
509 | a, i, bstrFinalValue.raw());
|
---|
510 | }
|
---|
511 | else if (strOverride == "accept")
|
---|
512 | {
|
---|
513 | RTPrintf("%2u: End-user license agreement (accepted)\n",
|
---|
514 | a);
|
---|
515 | --cLicensesInTheWay;
|
---|
516 | }
|
---|
517 | else
|
---|
518 | return errorSyntax(USAGE_IMPORTAPPLIANCE,
|
---|
519 | "Argument to --eula must be either \"show\" or \"accept\".");
|
---|
520 | }
|
---|
521 | else
|
---|
522 | RTPrintf("%2u: End-user license agreement"
|
---|
523 | "\n (display with \"--vsys %u --eula show\";"
|
---|
524 | "\n accept with \"--vsys %u --eula accept\")\n",
|
---|
525 | a, i, i);
|
---|
526 | break;
|
---|
527 |
|
---|
528 | case VirtualSystemDescriptionType_CPU:
|
---|
529 | if (findArgValue(strOverride, pmapArgs, "cpus"))
|
---|
530 | {
|
---|
531 | uint32_t cCPUs;
|
---|
532 | if ( strOverride.toInt(cCPUs) == VINF_SUCCESS
|
---|
533 | && cCPUs >= VMM_MIN_CPU_COUNT
|
---|
534 | && cCPUs <= VMM_MAX_CPU_COUNT
|
---|
535 | )
|
---|
536 | {
|
---|
537 | bstrFinalValue = strOverride;
|
---|
538 | RTPrintf("%2u: No. of CPUs specified with --cpus: %ls\n",
|
---|
539 | a, bstrFinalValue.raw());
|
---|
540 | }
|
---|
541 | else
|
---|
542 | return errorSyntax(USAGE_IMPORTAPPLIANCE,
|
---|
543 | "Argument to --cpus option must be a number greater than %d and less than %d.",
|
---|
544 | VMM_MIN_CPU_COUNT - 1, VMM_MAX_CPU_COUNT + 1);
|
---|
545 | }
|
---|
546 | else
|
---|
547 | RTPrintf("%2u: Number of CPUs: %ls\n (change with \"--vsys %u --cpus <n>\")\n",
|
---|
548 | a, bstrFinalValue.raw(), i);
|
---|
549 | break;
|
---|
550 |
|
---|
551 | case VirtualSystemDescriptionType_Memory:
|
---|
552 | {
|
---|
553 | if (findArgValue(strOverride, pmapArgs, "memory"))
|
---|
554 | {
|
---|
555 | uint32_t ulMemMB;
|
---|
556 | if (VINF_SUCCESS == strOverride.toInt(ulMemMB))
|
---|
557 | {
|
---|
558 | bstrFinalValue = strOverride;
|
---|
559 | RTPrintf("%2u: Guest memory specified with --memory: %ls MB\n",
|
---|
560 | a, bstrFinalValue.raw());
|
---|
561 | }
|
---|
562 | else
|
---|
563 | return errorSyntax(USAGE_IMPORTAPPLIANCE,
|
---|
564 | "Argument to --memory option must be a non-negative number.");
|
---|
565 | }
|
---|
566 | else
|
---|
567 | RTPrintf("%2u: Guest memory: %ls MB\n (change with \"--vsys %u --memory <MB>\")\n",
|
---|
568 | a, bstrFinalValue.raw(), i);
|
---|
569 | break;
|
---|
570 | }
|
---|
571 |
|
---|
572 | case VirtualSystemDescriptionType_HardDiskControllerIDE:
|
---|
573 | if (fIgnoreThis)
|
---|
574 | {
|
---|
575 | RTPrintf("%2u: IDE controller, type %ls -- disabled\n",
|
---|
576 | a,
|
---|
577 | aVBoxValues[a]);
|
---|
578 | aEnabled[a] = false;
|
---|
579 | }
|
---|
580 | else
|
---|
581 | RTPrintf("%2u: IDE controller, type %ls"
|
---|
582 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
583 | a,
|
---|
584 | aVBoxValues[a],
|
---|
585 | i, a);
|
---|
586 | break;
|
---|
587 |
|
---|
588 | case VirtualSystemDescriptionType_HardDiskControllerSATA:
|
---|
589 | if (fIgnoreThis)
|
---|
590 | {
|
---|
591 | RTPrintf("%2u: SATA controller, type %ls -- disabled\n",
|
---|
592 | a,
|
---|
593 | aVBoxValues[a]);
|
---|
594 | aEnabled[a] = false;
|
---|
595 | }
|
---|
596 | else
|
---|
597 | RTPrintf("%2u: SATA controller, type %ls"
|
---|
598 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
599 | a,
|
---|
600 | aVBoxValues[a],
|
---|
601 | i, a);
|
---|
602 | break;
|
---|
603 |
|
---|
604 | case VirtualSystemDescriptionType_HardDiskControllerSAS:
|
---|
605 | if (fIgnoreThis)
|
---|
606 | {
|
---|
607 | RTPrintf("%2u: SAS controller, type %ls -- disabled\n",
|
---|
608 | a,
|
---|
609 | aVBoxValues[a]);
|
---|
610 | aEnabled[a] = false;
|
---|
611 | }
|
---|
612 | else
|
---|
613 | RTPrintf("%2u: SAS controller, type %ls"
|
---|
614 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
615 | a,
|
---|
616 | aVBoxValues[a],
|
---|
617 | i, a);
|
---|
618 | break;
|
---|
619 |
|
---|
620 | case VirtualSystemDescriptionType_HardDiskControllerSCSI:
|
---|
621 | if (fIgnoreThis)
|
---|
622 | {
|
---|
623 | RTPrintf("%2u: SCSI controller, type %ls -- disabled\n",
|
---|
624 | a,
|
---|
625 | aVBoxValues[a]);
|
---|
626 | aEnabled[a] = false;
|
---|
627 | }
|
---|
628 | else
|
---|
629 | {
|
---|
630 | Utf8StrFmt strTypeArg("scsitype%u", a);
|
---|
631 | if (findArgValue(strOverride, pmapArgs, strTypeArg))
|
---|
632 | {
|
---|
633 | bstrFinalValue = strOverride;
|
---|
634 | RTPrintf("%2u: SCSI controller, type set with --unit %u --scsitype: \"%ls\"\n",
|
---|
635 | a,
|
---|
636 | a,
|
---|
637 | bstrFinalValue.raw());
|
---|
638 | }
|
---|
639 | else
|
---|
640 | RTPrintf("%2u: SCSI controller, type %ls"
|
---|
641 | "\n (change with \"--vsys %u --unit %u --scsitype {BusLogic|LsiLogic}\";"
|
---|
642 | "\n disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
643 | a,
|
---|
644 | aVBoxValues[a],
|
---|
645 | i, a, i, a);
|
---|
646 | }
|
---|
647 | break;
|
---|
648 |
|
---|
649 | case VirtualSystemDescriptionType_HardDiskImage:
|
---|
650 | if (fIgnoreThis)
|
---|
651 | {
|
---|
652 | RTPrintf("%2u: Hard disk image: source image=%ls -- disabled\n",
|
---|
653 | a,
|
---|
654 | aOvfValues[a]);
|
---|
655 | aEnabled[a] = false;
|
---|
656 | }
|
---|
657 | else
|
---|
658 | {
|
---|
659 | Utf8StrFmt strTypeArg("disk%u", a);
|
---|
660 | RTCList<ImportOptions_T> optionsList = options.toList();
|
---|
661 |
|
---|
662 | bstrFinalValue = aVBoxValues[a];
|
---|
663 |
|
---|
664 | if (findArgValue(strOverride, pmapArgs, strTypeArg))
|
---|
665 | {
|
---|
666 | if (!optionsList.contains(ImportOptions_ImportToVDI))
|
---|
667 | {
|
---|
668 | RTUUID uuid;
|
---|
669 | /* Check if this is a uuid. If so, don't touch. */
|
---|
670 | int vrc = RTUuidFromStr(&uuid, strOverride.c_str());
|
---|
671 | if (vrc != VINF_SUCCESS)
|
---|
672 | {
|
---|
673 | /* Make the path absolute. */
|
---|
674 | if (!RTPathStartsWithRoot(strOverride.c_str()))
|
---|
675 | {
|
---|
676 | char pszPwd[RTPATH_MAX];
|
---|
677 | vrc = RTPathGetCurrent(pszPwd, RTPATH_MAX);
|
---|
678 | if (RT_SUCCESS(vrc))
|
---|
679 | strOverride = Utf8Str(pszPwd).append(RTPATH_SLASH).append(strOverride);
|
---|
680 | }
|
---|
681 | }
|
---|
682 | bstrFinalValue = strOverride;
|
---|
683 | }
|
---|
684 | else
|
---|
685 | {
|
---|
686 | //print some error about incompatible command-line arguments
|
---|
687 | return errorSyntax(USAGE_IMPORTAPPLIANCE,
|
---|
688 | "Option --ImportToVDI shall not be used together with "
|
---|
689 | "manually set target path.");
|
---|
690 |
|
---|
691 | }
|
---|
692 |
|
---|
693 | RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls\n",
|
---|
694 | a,
|
---|
695 | aOvfValues[a],
|
---|
696 | bstrFinalValue.raw(),
|
---|
697 | aExtraConfigValues[a]);
|
---|
698 | }
|
---|
699 | #if 0 /* Changing the controller is fully valid, but the current design on how
|
---|
700 | the params are evaluated here doesn't allow two parameter for one
|
---|
701 | unit. The target disk path is more important I leave it for future
|
---|
702 | improvments. */
|
---|
703 | Utf8StrFmt strTypeArg("controller%u", a);
|
---|
704 | if (findArgValue(strOverride, pmapArgs, strTypeArg))
|
---|
705 | {
|
---|
706 | // strOverride now has the controller index as a number, but we
|
---|
707 | // need a "controller=X" format string
|
---|
708 | strOverride = Utf8StrFmt("controller=%s", strOverride.c_str());
|
---|
709 | Bstr bstrExtraConfigValue = strOverride;
|
---|
710 | bstrExtraConfigValue.detachTo(&aExtraConfigValues[a]);
|
---|
711 | RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls\n",
|
---|
712 | a,
|
---|
713 | aOvfValues[a],
|
---|
714 | aVBoxValues[a],
|
---|
715 | aExtraConfigValues[a]);
|
---|
716 | }
|
---|
717 | #endif
|
---|
718 | else
|
---|
719 | {
|
---|
720 | strOverride = aVBoxValues[a];
|
---|
721 |
|
---|
722 | /*
|
---|
723 | * Current solution isn't optimal.
|
---|
724 | * Better way is to provide API call for function
|
---|
725 | * Appliance::i_findMediumFormatFromDiskImage()
|
---|
726 | * and creating one new function which returns
|
---|
727 | * struct ovf::DiskImage for currently processed disk.
|
---|
728 | */
|
---|
729 |
|
---|
730 | /*
|
---|
731 | * if user wants to convert all imported disks to VDI format
|
---|
732 | * we need to replace files extensions to "vdi"
|
---|
733 | * except CD/DVD disks
|
---|
734 | */
|
---|
735 | if (optionsList.contains(ImportOptions_ImportToVDI))
|
---|
736 | {
|
---|
737 | ComPtr<IVirtualBox> pVirtualBox = arg->virtualBox;
|
---|
738 | ComPtr<ISystemProperties> systemProperties;
|
---|
739 | com::SafeIfaceArray<IMediumFormat> mediumFormats;
|
---|
740 | Bstr bstrFormatName;
|
---|
741 |
|
---|
742 | CHECK_ERROR(pVirtualBox,
|
---|
743 | COMGETTER(SystemProperties)(systemProperties.asOutParam()));
|
---|
744 |
|
---|
745 | CHECK_ERROR(systemProperties,
|
---|
746 | COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
|
---|
747 |
|
---|
748 | /* go through all supported media formats and store files extensions only for RAW */
|
---|
749 | com::SafeArray<BSTR> extensions;
|
---|
750 |
|
---|
751 | for (unsigned j = 0; j < mediumFormats.size(); ++j)
|
---|
752 | {
|
---|
753 | com::SafeArray<DeviceType_T> deviceType;
|
---|
754 | ComPtr<IMediumFormat> mediumFormat = mediumFormats[j];
|
---|
755 | CHECK_ERROR(mediumFormat, COMGETTER(Name)(bstrFormatName.asOutParam()));
|
---|
756 | Utf8Str strFormatName = Utf8Str(bstrFormatName);
|
---|
757 |
|
---|
758 | if (strFormatName.compare("RAW", Utf8Str::CaseInsensitive) == 0)
|
---|
759 | {
|
---|
760 | /* getting files extensions for "RAW" format */
|
---|
761 | CHECK_ERROR(mediumFormat,
|
---|
762 | DescribeFileExtensions(ComSafeArrayAsOutParam(extensions),
|
---|
763 | ComSafeArrayAsOutParam(deviceType)));
|
---|
764 | break;
|
---|
765 | }
|
---|
766 | }
|
---|
767 |
|
---|
768 | /* go through files extensions for RAW format and compare them with
|
---|
769 | * extension of current file
|
---|
770 | */
|
---|
771 | bool fReplace = true;
|
---|
772 |
|
---|
773 | const char *pszExtension = RTPathSuffix(strOverride.c_str());
|
---|
774 | if (pszExtension)
|
---|
775 | pszExtension++;
|
---|
776 |
|
---|
777 | for (unsigned j = 0; j < extensions.size(); ++j)
|
---|
778 | {
|
---|
779 | Bstr bstrExt(extensions[j]);
|
---|
780 | Utf8Str strExtension(bstrExt);
|
---|
781 | if(strExtension.compare(pszExtension, Utf8Str::CaseInsensitive) == 0)
|
---|
782 | {
|
---|
783 | fReplace = false;
|
---|
784 | break;
|
---|
785 | }
|
---|
786 | }
|
---|
787 |
|
---|
788 | if (fReplace)
|
---|
789 | {
|
---|
790 | strOverride = strOverride.stripSuffix();
|
---|
791 | strOverride = strOverride.append(".").append("vdi");
|
---|
792 | }
|
---|
793 | }
|
---|
794 |
|
---|
795 | bstrFinalValue = strOverride;
|
---|
796 |
|
---|
797 | RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls"
|
---|
798 | "\n (change target path with \"--vsys %u --unit %u --disk path\";"
|
---|
799 | "\n disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
800 | a,
|
---|
801 | aOvfValues[a],
|
---|
802 | bstrFinalValue.raw(),
|
---|
803 | aExtraConfigValues[a],
|
---|
804 | i, a, i, a);
|
---|
805 | }
|
---|
806 | }
|
---|
807 | break;
|
---|
808 |
|
---|
809 | case VirtualSystemDescriptionType_CDROM:
|
---|
810 | if (fIgnoreThis)
|
---|
811 | {
|
---|
812 | RTPrintf("%2u: CD-ROM -- disabled\n",
|
---|
813 | a);
|
---|
814 | aEnabled[a] = false;
|
---|
815 | }
|
---|
816 | else
|
---|
817 | RTPrintf("%2u: CD-ROM"
|
---|
818 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
819 | a, i, a);
|
---|
820 | break;
|
---|
821 |
|
---|
822 | case VirtualSystemDescriptionType_Floppy:
|
---|
823 | if (fIgnoreThis)
|
---|
824 | {
|
---|
825 | RTPrintf("%2u: Floppy -- disabled\n",
|
---|
826 | a);
|
---|
827 | aEnabled[a] = false;
|
---|
828 | }
|
---|
829 | else
|
---|
830 | RTPrintf("%2u: Floppy"
|
---|
831 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
832 | a, i, a);
|
---|
833 | break;
|
---|
834 |
|
---|
835 | case VirtualSystemDescriptionType_NetworkAdapter:
|
---|
836 | RTPrintf("%2u: Network adapter: orig %ls, config %ls, extra %ls\n", /// @todo implement once we have a plan for the back-end
|
---|
837 | a,
|
---|
838 | aOvfValues[a],
|
---|
839 | aVBoxValues[a],
|
---|
840 | aExtraConfigValues[a]);
|
---|
841 | break;
|
---|
842 |
|
---|
843 | case VirtualSystemDescriptionType_USBController:
|
---|
844 | if (fIgnoreThis)
|
---|
845 | {
|
---|
846 | RTPrintf("%2u: USB controller -- disabled\n",
|
---|
847 | a);
|
---|
848 | aEnabled[a] = false;
|
---|
849 | }
|
---|
850 | else
|
---|
851 | RTPrintf("%2u: USB controller"
|
---|
852 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
853 | a, i, a);
|
---|
854 | break;
|
---|
855 |
|
---|
856 | case VirtualSystemDescriptionType_SoundCard:
|
---|
857 | if (fIgnoreThis)
|
---|
858 | {
|
---|
859 | RTPrintf("%2u: Sound card \"%ls\" -- disabled\n",
|
---|
860 | a,
|
---|
861 | aOvfValues[a]);
|
---|
862 | aEnabled[a] = false;
|
---|
863 | }
|
---|
864 | else
|
---|
865 | RTPrintf("%2u: Sound card (appliance expects \"%ls\", can change on import)"
|
---|
866 | "\n (disable with \"--vsys %u --unit %u --ignore\")\n",
|
---|
867 | a,
|
---|
868 | aOvfValues[a],
|
---|
869 | i,
|
---|
870 | a);
|
---|
871 | break;
|
---|
872 |
|
---|
873 | case VirtualSystemDescriptionType_SettingsFile:
|
---|
874 | if (findArgValue(strOverride, pmapArgs, "settingsfile"))
|
---|
875 | {
|
---|
876 | bstrFinalValue = strOverride;
|
---|
877 | RTPrintf("%2u: VM settings file name specified with --settingsfile: \"%ls\"\n",
|
---|
878 | a, bstrFinalValue.raw());
|
---|
879 | }
|
---|
880 | else
|
---|
881 | RTPrintf("%2u: Suggested VM settings file name \"%ls\""
|
---|
882 | "\n (change with \"--vsys %u --settingsfile <filename>\")\n",
|
---|
883 | a, bstrFinalValue.raw(), i);
|
---|
884 | break;
|
---|
885 |
|
---|
886 | case VirtualSystemDescriptionType_BaseFolder:
|
---|
887 | if (findArgValue(strOverride, pmapArgs, "basefolder"))
|
---|
888 | {
|
---|
889 | bstrFinalValue = strOverride;
|
---|
890 | RTPrintf("%2u: VM base folder specified with --basefolder: \"%ls\"\n",
|
---|
891 | a, bstrFinalValue.raw());
|
---|
892 | }
|
---|
893 | else
|
---|
894 | RTPrintf("%2u: Suggested VM base folder \"%ls\""
|
---|
895 | "\n (change with \"--vsys %u --basefolder <path>\")\n",
|
---|
896 | a, bstrFinalValue.raw(), i);
|
---|
897 | break;
|
---|
898 |
|
---|
899 | case VirtualSystemDescriptionType_PrimaryGroup:
|
---|
900 | if (findArgValue(strOverride, pmapArgs, "group"))
|
---|
901 | {
|
---|
902 | bstrFinalValue = strOverride;
|
---|
903 | RTPrintf("%2u: VM group specified with --group: \"%ls\"\n",
|
---|
904 | a, bstrFinalValue.raw());
|
---|
905 | }
|
---|
906 | else
|
---|
907 | RTPrintf("%2u: Suggested VM group \"%ls\""
|
---|
908 | "\n (change with \"--vsys %u --group <group>\")\n",
|
---|
909 | a, bstrFinalValue.raw(), i);
|
---|
910 | break;
|
---|
911 |
|
---|
912 | case VirtualSystemDescriptionType_Miscellaneous:
|
---|
913 | /** @todo VirtualSystemDescriptionType_Miscellaneous? */
|
---|
914 | break;
|
---|
915 | case VirtualSystemDescriptionType_Ignore:
|
---|
916 | break;
|
---|
917 | }
|
---|
918 |
|
---|
919 | bstrFinalValue.detachTo(&aFinalValues[a]);
|
---|
920 | }
|
---|
921 |
|
---|
922 | if (fExecute)
|
---|
923 | CHECK_ERROR_BREAK(aVirtualSystemDescriptions[i],
|
---|
924 | SetFinalValues(ComSafeArrayAsInParam(aEnabled),
|
---|
925 | ComSafeArrayAsInParam(aFinalValues),
|
---|
926 | ComSafeArrayAsInParam(aExtraConfigValues)));
|
---|
927 |
|
---|
928 | } // for (unsigned i = 0; i < cVirtualSystemDescriptions; ++i)
|
---|
929 |
|
---|
930 | if (cLicensesInTheWay == 1)
|
---|
931 | RTMsgError("Cannot import until the license agreement listed above is accepted.");
|
---|
932 | else if (cLicensesInTheWay > 1)
|
---|
933 | RTMsgError("Cannot import until the %c license agreements listed above are accepted.", cLicensesInTheWay);
|
---|
934 |
|
---|
935 | if (!cLicensesInTheWay && fExecute)
|
---|
936 | {
|
---|
937 | // go!
|
---|
938 | ComPtr<IProgress> progress;
|
---|
939 | CHECK_ERROR_BREAK(pAppliance,
|
---|
940 | ImportMachines(ComSafeArrayAsInParam(options), progress.asOutParam()));
|
---|
941 |
|
---|
942 | rc = showProgress(progress);
|
---|
943 | CHECK_PROGRESS_ERROR_RET(progress, ("Appliance import failed"), RTEXITCODE_FAILURE);
|
---|
944 |
|
---|
945 | if (SUCCEEDED(rc))
|
---|
946 | RTPrintf("Successfully imported the appliance.\n");
|
---|
947 | }
|
---|
948 | } // end if (aVirtualSystemDescriptions.size() > 0)
|
---|
949 | } while (0);
|
---|
950 |
|
---|
951 | return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
952 | }
|
---|
953 |
|
---|
954 | static int parseExportOptions(const char *psz, com::SafeArray<ExportOptions_T> *options)
|
---|
955 | {
|
---|
956 | int rc = VINF_SUCCESS;
|
---|
957 | while (psz && *psz && RT_SUCCESS(rc))
|
---|
958 | {
|
---|
959 | size_t len;
|
---|
960 | const char *pszComma = strchr(psz, ',');
|
---|
961 | if (pszComma)
|
---|
962 | len = pszComma - psz;
|
---|
963 | else
|
---|
964 | len = strlen(psz);
|
---|
965 | if (len > 0)
|
---|
966 | {
|
---|
967 | if (!RTStrNICmp(psz, "CreateManifest", len))
|
---|
968 | options->push_back(ExportOptions_CreateManifest);
|
---|
969 | else if (!RTStrNICmp(psz, "manifest", len))
|
---|
970 | options->push_back(ExportOptions_CreateManifest);
|
---|
971 | else if (!RTStrNICmp(psz, "ExportDVDImages", len))
|
---|
972 | options->push_back(ExportOptions_ExportDVDImages);
|
---|
973 | else if (!RTStrNICmp(psz, "iso", len))
|
---|
974 | options->push_back(ExportOptions_ExportDVDImages);
|
---|
975 | else if (!RTStrNICmp(psz, "StripAllMACs", len))
|
---|
976 | options->push_back(ExportOptions_StripAllMACs);
|
---|
977 | else if (!RTStrNICmp(psz, "nomacs", len))
|
---|
978 | options->push_back(ExportOptions_StripAllMACs);
|
---|
979 | else if (!RTStrNICmp(psz, "StripAllNonNATMACs", len))
|
---|
980 | options->push_back(ExportOptions_StripAllNonNATMACs);
|
---|
981 | else if (!RTStrNICmp(psz, "nomacsbutnat", len))
|
---|
982 | options->push_back(ExportOptions_StripAllNonNATMACs);
|
---|
983 | else
|
---|
984 | rc = VERR_PARSE_ERROR;
|
---|
985 | }
|
---|
986 | if (pszComma)
|
---|
987 | psz += len + 1;
|
---|
988 | else
|
---|
989 | psz += len;
|
---|
990 | }
|
---|
991 |
|
---|
992 | return rc;
|
---|
993 | }
|
---|
994 |
|
---|
995 | static const RTGETOPTDEF g_aExportOptions[] =
|
---|
996 | {
|
---|
997 | { "--output", 'o', RTGETOPT_REQ_STRING },
|
---|
998 | { "--legacy09", 'l', RTGETOPT_REQ_NOTHING },
|
---|
999 | { "--ovf09", 'l', RTGETOPT_REQ_NOTHING },
|
---|
1000 | { "--ovf10", '1', RTGETOPT_REQ_NOTHING },
|
---|
1001 | { "--ovf20", '2', RTGETOPT_REQ_NOTHING },
|
---|
1002 | { "--opc10", 'c', RTGETOPT_REQ_NOTHING },
|
---|
1003 | { "--manifest", 'm', RTGETOPT_REQ_NOTHING }, // obsoleted by --options
|
---|
1004 | { "--iso", 'I', RTGETOPT_REQ_NOTHING }, // obsoleted by --options
|
---|
1005 | { "--vsys", 's', RTGETOPT_REQ_UINT32 },
|
---|
1006 | { "--vmname", 'V', RTGETOPT_REQ_STRING },
|
---|
1007 | { "--product", 'p', RTGETOPT_REQ_STRING },
|
---|
1008 | { "--producturl", 'P', RTGETOPT_REQ_STRING },
|
---|
1009 | { "--vendor", 'n', RTGETOPT_REQ_STRING },
|
---|
1010 | { "--vendorurl", 'N', RTGETOPT_REQ_STRING },
|
---|
1011 | { "--version", 'v', RTGETOPT_REQ_STRING },
|
---|
1012 | { "--description", 'd', RTGETOPT_REQ_STRING },
|
---|
1013 | { "--eula", 'e', RTGETOPT_REQ_STRING },
|
---|
1014 | { "--eulafile", 'E', RTGETOPT_REQ_STRING },
|
---|
1015 | { "--options", 'O', RTGETOPT_REQ_STRING },
|
---|
1016 | };
|
---|
1017 |
|
---|
1018 | RTEXITCODE handleExportAppliance(HandlerArg *a)
|
---|
1019 | {
|
---|
1020 | HRESULT rc = S_OK;
|
---|
1021 |
|
---|
1022 | Utf8Str strOutputFile;
|
---|
1023 | Utf8Str strOvfFormat("ovf-1.0"); // the default export version
|
---|
1024 | bool fManifest = false; // the default
|
---|
1025 | bool fExportISOImages = false; // the default
|
---|
1026 | com::SafeArray<ExportOptions_T> options;
|
---|
1027 | std::list< ComPtr<IMachine> > llMachines;
|
---|
1028 |
|
---|
1029 | uint32_t ulCurVsys = (uint32_t)-1;
|
---|
1030 | // for each --vsys X command, maintain a map of command line items
|
---|
1031 | ArgsMapsMap mapArgsMapsPerVsys;
|
---|
1032 | do
|
---|
1033 | {
|
---|
1034 | int c;
|
---|
1035 |
|
---|
1036 | RTGETOPTUNION ValueUnion;
|
---|
1037 | RTGETOPTSTATE GetState;
|
---|
1038 | // start at 0 because main() has hacked both the argc and argv given to us
|
---|
1039 | RTGetOptInit(&GetState, a->argc, a->argv, g_aExportOptions,
|
---|
1040 | RT_ELEMENTS(g_aExportOptions), 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
|
---|
1041 |
|
---|
1042 | Utf8Str strProductUrl;
|
---|
1043 | while ((c = RTGetOpt(&GetState, &ValueUnion)))
|
---|
1044 | {
|
---|
1045 | switch (c)
|
---|
1046 | {
|
---|
1047 | case 'o': // --output
|
---|
1048 | if (strOutputFile.length())
|
---|
1049 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "You can only specify --output once.");
|
---|
1050 | else
|
---|
1051 | strOutputFile = ValueUnion.psz;
|
---|
1052 | break;
|
---|
1053 |
|
---|
1054 | case 'l': // --legacy09/--ovf09
|
---|
1055 | strOvfFormat = "ovf-0.9";
|
---|
1056 | break;
|
---|
1057 |
|
---|
1058 | case '1': // --ovf10
|
---|
1059 | strOvfFormat = "ovf-1.0";
|
---|
1060 | break;
|
---|
1061 |
|
---|
1062 | case '2': // --ovf20
|
---|
1063 | strOvfFormat = "ovf-2.0";
|
---|
1064 | break;
|
---|
1065 |
|
---|
1066 | case 'c': // --opc
|
---|
1067 | strOvfFormat = "opc-1.0";
|
---|
1068 | break;
|
---|
1069 |
|
---|
1070 | case 'I': // --iso
|
---|
1071 | fExportISOImages = true;
|
---|
1072 | break;
|
---|
1073 |
|
---|
1074 | case 'm': // --manifest
|
---|
1075 | fManifest = true;
|
---|
1076 | break;
|
---|
1077 |
|
---|
1078 | case 's': // --vsys
|
---|
1079 | ulCurVsys = ValueUnion.u32;
|
---|
1080 | break;
|
---|
1081 |
|
---|
1082 | case 'V': // --vmname
|
---|
1083 | if (ulCurVsys == (uint32_t)-1)
|
---|
1084 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1085 | mapArgsMapsPerVsys[ulCurVsys]["vmname"] = ValueUnion.psz;
|
---|
1086 | break;
|
---|
1087 |
|
---|
1088 | case 'p': // --product
|
---|
1089 | if (ulCurVsys == (uint32_t)-1)
|
---|
1090 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1091 | mapArgsMapsPerVsys[ulCurVsys]["product"] = ValueUnion.psz;
|
---|
1092 | break;
|
---|
1093 |
|
---|
1094 | case 'P': // --producturl
|
---|
1095 | if (ulCurVsys == (uint32_t)-1)
|
---|
1096 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1097 | mapArgsMapsPerVsys[ulCurVsys]["producturl"] = ValueUnion.psz;
|
---|
1098 | break;
|
---|
1099 |
|
---|
1100 | case 'n': // --vendor
|
---|
1101 | if (ulCurVsys == (uint32_t)-1)
|
---|
1102 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1103 | mapArgsMapsPerVsys[ulCurVsys]["vendor"] = ValueUnion.psz;
|
---|
1104 | break;
|
---|
1105 |
|
---|
1106 | case 'N': // --vendorurl
|
---|
1107 | if (ulCurVsys == (uint32_t)-1)
|
---|
1108 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1109 | mapArgsMapsPerVsys[ulCurVsys]["vendorurl"] = ValueUnion.psz;
|
---|
1110 | break;
|
---|
1111 |
|
---|
1112 | case 'v': // --version
|
---|
1113 | if (ulCurVsys == (uint32_t)-1)
|
---|
1114 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1115 | mapArgsMapsPerVsys[ulCurVsys]["version"] = ValueUnion.psz;
|
---|
1116 | break;
|
---|
1117 |
|
---|
1118 | case 'd': // --description
|
---|
1119 | if (ulCurVsys == (uint32_t)-1)
|
---|
1120 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1121 | mapArgsMapsPerVsys[ulCurVsys]["description"] = ValueUnion.psz;
|
---|
1122 | break;
|
---|
1123 |
|
---|
1124 | case 'e': // --eula
|
---|
1125 | if (ulCurVsys == (uint32_t)-1)
|
---|
1126 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1127 | mapArgsMapsPerVsys[ulCurVsys]["eula"] = ValueUnion.psz;
|
---|
1128 | break;
|
---|
1129 |
|
---|
1130 | case 'E': // --eulafile
|
---|
1131 | if (ulCurVsys == (uint32_t)-1)
|
---|
1132 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong);
|
---|
1133 | mapArgsMapsPerVsys[ulCurVsys]["eulafile"] = ValueUnion.psz;
|
---|
1134 | break;
|
---|
1135 |
|
---|
1136 | case 'O': // --options
|
---|
1137 | if (RT_FAILURE(parseExportOptions(ValueUnion.psz, &options)))
|
---|
1138 | return errorArgument("Invalid export options '%s'\n", ValueUnion.psz);
|
---|
1139 | break;
|
---|
1140 |
|
---|
1141 | case VINF_GETOPT_NOT_OPTION:
|
---|
1142 | {
|
---|
1143 | Utf8Str strMachine(ValueUnion.psz);
|
---|
1144 | // must be machine: try UUID or name
|
---|
1145 | ComPtr<IMachine> machine;
|
---|
1146 | CHECK_ERROR_BREAK(a->virtualBox, FindMachine(Bstr(strMachine).raw(),
|
---|
1147 | machine.asOutParam()));
|
---|
1148 | if (machine)
|
---|
1149 | llMachines.push_back(machine);
|
---|
1150 | break;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | default:
|
---|
1154 | if (c > 0)
|
---|
1155 | {
|
---|
1156 | if (RT_C_IS_GRAPH(c))
|
---|
1157 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "unhandled option: -%c", c);
|
---|
1158 | else
|
---|
1159 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "unhandled option: %i", c);
|
---|
1160 | }
|
---|
1161 | else if (c == VERR_GETOPT_UNKNOWN_OPTION)
|
---|
1162 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "unknown option: %s", ValueUnion.psz);
|
---|
1163 | else if (ValueUnion.pDef)
|
---|
1164 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
|
---|
1165 | else
|
---|
1166 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "%Rrs", c);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | if (FAILED(rc))
|
---|
1170 | break;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | if (FAILED(rc))
|
---|
1174 | break;
|
---|
1175 |
|
---|
1176 | if (llMachines.empty())
|
---|
1177 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "At least one machine must be specified with the export command.");
|
---|
1178 | if (!strOutputFile.length())
|
---|
1179 | return errorSyntax(USAGE_EXPORTAPPLIANCE, "Missing --output argument with export command.");
|
---|
1180 |
|
---|
1181 | // match command line arguments with the machines count
|
---|
1182 | // this is only to sort out invalid indices at this time
|
---|
1183 | ArgsMapsMap::const_iterator it;
|
---|
1184 | for (it = mapArgsMapsPerVsys.begin();
|
---|
1185 | it != mapArgsMapsPerVsys.end();
|
---|
1186 | ++it)
|
---|
1187 | {
|
---|
1188 | uint32_t ulVsys = it->first;
|
---|
1189 | if (ulVsys >= llMachines.size())
|
---|
1190 | return errorSyntax(USAGE_EXPORTAPPLIANCE,
|
---|
1191 | "Invalid index %RI32 with -vsys option; you specified only %zu virtual system(s).",
|
---|
1192 | ulVsys, llMachines.size());
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | ComPtr<IAppliance> pAppliance;
|
---|
1196 | CHECK_ERROR_BREAK(a->virtualBox, CreateAppliance(pAppliance.asOutParam()));
|
---|
1197 |
|
---|
1198 | char *pszAbsFilePath = 0;
|
---|
1199 | if (strOutputFile.startsWith("S3://", RTCString::CaseInsensitive) ||
|
---|
1200 | strOutputFile.startsWith("SunCloud://", RTCString::CaseInsensitive) ||
|
---|
1201 | strOutputFile.startsWith("webdav://", RTCString::CaseInsensitive))
|
---|
1202 | pszAbsFilePath = RTStrDup(strOutputFile.c_str());
|
---|
1203 | else
|
---|
1204 | pszAbsFilePath = RTPathAbsDup(strOutputFile.c_str());
|
---|
1205 |
|
---|
1206 | std::list< ComPtr<IMachine> >::iterator itM;
|
---|
1207 | uint32_t i=0;
|
---|
1208 | for (itM = llMachines.begin();
|
---|
1209 | itM != llMachines.end();
|
---|
1210 | ++itM, ++i)
|
---|
1211 | {
|
---|
1212 | ComPtr<IMachine> pMachine = *itM;
|
---|
1213 | ComPtr<IVirtualSystemDescription> pVSD;
|
---|
1214 | CHECK_ERROR_BREAK(pMachine, ExportTo(pAppliance, Bstr(pszAbsFilePath).raw(), pVSD.asOutParam()));
|
---|
1215 | // Add additional info to the virtual system description if the user wants so
|
---|
1216 | ArgsMap *pmapArgs = NULL;
|
---|
1217 | ArgsMapsMap::iterator itm = mapArgsMapsPerVsys.find(i);
|
---|
1218 | if (itm != mapArgsMapsPerVsys.end())
|
---|
1219 | pmapArgs = &itm->second;
|
---|
1220 | if (pmapArgs)
|
---|
1221 | {
|
---|
1222 | ArgsMap::iterator itD;
|
---|
1223 | for (itD = pmapArgs->begin();
|
---|
1224 | itD != pmapArgs->end();
|
---|
1225 | ++itD)
|
---|
1226 | {
|
---|
1227 | if (itD->first == "vmname")
|
---|
1228 | pVSD->AddDescription(VirtualSystemDescriptionType_Name,
|
---|
1229 | Bstr(itD->second).raw(),
|
---|
1230 | Bstr(itD->second).raw());
|
---|
1231 | else if (itD->first == "product")
|
---|
1232 | pVSD->AddDescription(VirtualSystemDescriptionType_Product,
|
---|
1233 | Bstr(itD->second).raw(),
|
---|
1234 | Bstr(itD->second).raw());
|
---|
1235 | else if (itD->first == "producturl")
|
---|
1236 | pVSD->AddDescription(VirtualSystemDescriptionType_ProductUrl,
|
---|
1237 | Bstr(itD->second).raw(),
|
---|
1238 | Bstr(itD->second).raw());
|
---|
1239 | else if (itD->first == "vendor")
|
---|
1240 | pVSD->AddDescription(VirtualSystemDescriptionType_Vendor,
|
---|
1241 | Bstr(itD->second).raw(),
|
---|
1242 | Bstr(itD->second).raw());
|
---|
1243 | else if (itD->first == "vendorurl")
|
---|
1244 | pVSD->AddDescription(VirtualSystemDescriptionType_VendorUrl,
|
---|
1245 | Bstr(itD->second).raw(),
|
---|
1246 | Bstr(itD->second).raw());
|
---|
1247 | else if (itD->first == "version")
|
---|
1248 | pVSD->AddDescription(VirtualSystemDescriptionType_Version,
|
---|
1249 | Bstr(itD->second).raw(),
|
---|
1250 | Bstr(itD->second).raw());
|
---|
1251 | else if (itD->first == "description")
|
---|
1252 | pVSD->AddDescription(VirtualSystemDescriptionType_Description,
|
---|
1253 | Bstr(itD->second).raw(),
|
---|
1254 | Bstr(itD->second).raw());
|
---|
1255 | else if (itD->first == "eula")
|
---|
1256 | pVSD->AddDescription(VirtualSystemDescriptionType_License,
|
---|
1257 | Bstr(itD->second).raw(),
|
---|
1258 | Bstr(itD->second).raw());
|
---|
1259 | else if (itD->first == "eulafile")
|
---|
1260 | {
|
---|
1261 | Utf8Str strContent;
|
---|
1262 | void *pvFile;
|
---|
1263 | size_t cbFile;
|
---|
1264 | int irc = RTFileReadAll(itD->second.c_str(), &pvFile, &cbFile);
|
---|
1265 | if (RT_SUCCESS(irc))
|
---|
1266 | {
|
---|
1267 | Bstr bstrContent((char*)pvFile, cbFile);
|
---|
1268 | pVSD->AddDescription(VirtualSystemDescriptionType_License,
|
---|
1269 | bstrContent.raw(),
|
---|
1270 | bstrContent.raw());
|
---|
1271 | RTFileReadAllFree(pvFile, cbFile);
|
---|
1272 | }
|
---|
1273 | else
|
---|
1274 | {
|
---|
1275 | RTMsgError("Cannot read license file \"%s\" which should be included in the virtual system %u.",
|
---|
1276 | itD->second.c_str(), i);
|
---|
1277 | return RTEXITCODE_FAILURE;
|
---|
1278 | }
|
---|
1279 | }
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | if (FAILED(rc))
|
---|
1285 | break;
|
---|
1286 |
|
---|
1287 | /* Query required passwords and supply them to the appliance. */
|
---|
1288 | com::SafeArray<BSTR> aIdentifiers;
|
---|
1289 |
|
---|
1290 | CHECK_ERROR_BREAK(pAppliance, GetPasswordIds(ComSafeArrayAsOutParam(aIdentifiers)));
|
---|
1291 |
|
---|
1292 | if (aIdentifiers.size() > 0)
|
---|
1293 | {
|
---|
1294 | com::SafeArray<BSTR> aPasswords(aIdentifiers.size());
|
---|
1295 | RTPrintf("Enter the passwords for the following identifiers to export the apppliance:\n");
|
---|
1296 | for (unsigned idxId = 0; idxId < aIdentifiers.size(); idxId++)
|
---|
1297 | {
|
---|
1298 | com::Utf8Str strPassword;
|
---|
1299 | Bstr bstrPassword;
|
---|
1300 | Bstr bstrId = aIdentifiers[idxId];
|
---|
1301 |
|
---|
1302 | RTEXITCODE rcExit = readPasswordFromConsole(&strPassword, "Password ID %s:", Utf8Str(bstrId).c_str());
|
---|
1303 | if (rcExit == RTEXITCODE_FAILURE)
|
---|
1304 | {
|
---|
1305 | RTStrFree(pszAbsFilePath);
|
---|
1306 | return rcExit;
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | bstrPassword = strPassword;
|
---|
1310 | bstrPassword.detachTo(&aPasswords[idxId]);
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | CHECK_ERROR_BREAK(pAppliance, AddPasswords(ComSafeArrayAsInParam(aIdentifiers),
|
---|
1314 | ComSafeArrayAsInParam(aPasswords)));
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | if (fManifest)
|
---|
1318 | options.push_back(ExportOptions_CreateManifest);
|
---|
1319 |
|
---|
1320 | if (fExportISOImages)
|
---|
1321 | options.push_back(ExportOptions_ExportDVDImages);
|
---|
1322 |
|
---|
1323 | ComPtr<IProgress> progress;
|
---|
1324 | CHECK_ERROR_BREAK(pAppliance, Write(Bstr(strOvfFormat).raw(),
|
---|
1325 | ComSafeArrayAsInParam(options),
|
---|
1326 | Bstr(pszAbsFilePath).raw(),
|
---|
1327 | progress.asOutParam()));
|
---|
1328 | RTStrFree(pszAbsFilePath);
|
---|
1329 |
|
---|
1330 | rc = showProgress(progress);
|
---|
1331 | CHECK_PROGRESS_ERROR_RET(progress, ("Appliance write failed"), RTEXITCODE_FAILURE);
|
---|
1332 |
|
---|
1333 | if (SUCCEEDED(rc))
|
---|
1334 | RTPrintf("Successfully exported %d machine(s).\n", llMachines.size());
|
---|
1335 |
|
---|
1336 | } while (0);
|
---|
1337 |
|
---|
1338 | return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | #endif /* !VBOX_ONLY_DOCS */
|
---|