VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageAppliance.cpp@ 59642

Last change on this file since 59642 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette