VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageImport.cpp@ 16581

Last change on this file since 16581 was 16581, checked in by vboxsync, 16 years ago

VBoxManage: fix import error handling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
1/* $Id: VBoxManageImport.cpp 16581 2009-02-09 12:08:17Z vboxsync $ */
2/** @file
3 * VBoxManage - The appliance-related commands.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#ifndef VBOX_ONLY_DOCS
28#include <VBox/com/com.h>
29#include <VBox/com/string.h>
30#include <VBox/com/Guid.h>
31#include <VBox/com/array.h>
32#include <VBox/com/ErrorInfo.h>
33#include <VBox/com/errorprint2.h>
34#include <VBox/com/EventQueue.h>
35
36#include <VBox/com/VirtualBox.h>
37
38#include <list>
39#endif /* !VBOX_ONLY_DOCS */
40
41#include <iprt/stream.h>
42
43#include <VBox/log.h>
44
45#include "VBoxManage.h"
46using namespace com;
47
48
49// funcs
50///////////////////////////////////////////////////////////////////////////////
51
52int handleImportAppliance(HandlerArg *a)
53{
54 HRESULT rc = S_OK;
55
56 Utf8Str strOvfFilename;
57 bool fExecute = false; // if true, then we actually do the import (-exec argument)
58
59 for (int i = 0; i < a->argc; i++)
60 {
61 if (!strcmp(a->argv[i], "-exec"))
62 fExecute = true;
63 else if (!strOvfFilename)
64 strOvfFilename = a->argv[i];
65 else
66 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Too many arguments for \"import\" command.");
67 }
68
69 if (!strOvfFilename)
70 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Not enough arguments for \"import\" command.");
71
72 do
73 {
74 Bstr bstrOvfFilename(strOvfFilename);
75 ComPtr<IAppliance> appliance;
76 CHECK_ERROR_BREAK(a->virtualBox, OpenAppliance(bstrOvfFilename, appliance.asOutParam()));
77
78 RTPrintf("Interpreting...\n");
79 CHECK_ERROR_BREAK(appliance, Interpret());
80 RTPrintf("OK.\n");
81
82 // fetch all disks
83 com::SafeArray<BSTR> retDisks;
84 CHECK_ERROR_BREAK(appliance,
85 COMGETTER(Disks)(ComSafeArrayAsOutParam(retDisks)));
86 if (retDisks.size() > 0)
87 {
88 RTPrintf("Disks:");
89 for (unsigned i = 0; i < retDisks.size(); i++)
90 RTPrintf(" %ls", retDisks[i]);
91 RTPrintf("\n");
92 }
93
94 // fetch virtual system descriptions
95 com::SafeIfaceArray<IVirtualSystemDescription> aVirtualSystemDescriptions;
96 CHECK_ERROR_BREAK(appliance,
97 COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(aVirtualSystemDescriptions)));
98 if (aVirtualSystemDescriptions.size() > 0)
99 {
100 for (unsigned i = 0; i < aVirtualSystemDescriptions.size(); ++i)
101 {
102 com::SafeArray<VirtualSystemDescriptionType_T> retTypes;
103 com::SafeArray<BSTR> aRefs;
104 com::SafeArray<BSTR> aOrigValues;
105 com::SafeArray<BSTR> aConfigValues;
106 com::SafeArray<BSTR> aExtraConfigValues;
107 CHECK_ERROR_BREAK(aVirtualSystemDescriptions[i],
108 GetDescription(ComSafeArrayAsOutParam(retTypes),
109 ComSafeArrayAsOutParam(aRefs),
110 ComSafeArrayAsOutParam(aOrigValues),
111 ComSafeArrayAsOutParam(aConfigValues),
112 ComSafeArrayAsOutParam(aExtraConfigValues)));
113
114 RTPrintf("Virtual system %i:\n", i);
115 for (unsigned a = 0; a < retTypes.size(); ++a)
116 {
117 VirtualSystemDescriptionType_T t = retTypes[a];
118
119 Bstr bstrVMname;
120 Bstr bstrOstype;
121 uint32_t ulMemMB;
122 bool fUSB = false;
123
124 switch (t)
125 {
126 case VirtualSystemDescriptionType_Name:
127 bstrVMname = aConfigValues[a];
128 RTPrintf("%2d: Suggested VM name \"%ls\""
129 "\n (change with \"-vsys %d -vmname <name>\")\n",
130 a, bstrVMname.raw(), i);
131 break;
132
133 case VirtualSystemDescriptionType_OS:
134 bstrOstype = aConfigValues[a];
135 RTPrintf("%2d: Suggested OS type: \"%ls\""
136 "\n (change with \"-vsys %d -ostype <type>\"; use \"list ostypes\" to list all)\n",
137 a, bstrOstype.raw(), i);
138 break;
139
140 case VirtualSystemDescriptionType_CPU:
141 RTPrintf("%2d: Number of CPUs (ignored): %ls\n",
142 a, aConfigValues[a]);
143 break;
144
145 case VirtualSystemDescriptionType_Memory:
146 Utf8Str(Bstr(aConfigValues[a])).toInt(ulMemMB);
147 RTPrintf("%2d: Guest memory: %u MB\n (change with \"-vsys %d -memory <MB>\")\n",
148 a, ulMemMB, i);
149 break;
150
151 case VirtualSystemDescriptionType_HardDiskControllerIDE:
152 RTPrintf("%2d: IDE controller, type %ls"
153 "\n (disable with \"-vsys %d -ignore %d\")\n",
154 a,
155 aConfigValues[a],
156 i, a);
157 break;
158
159 case VirtualSystemDescriptionType_HardDiskControllerSATA:
160 RTPrintf("%2d: SATA controller, type %ls"
161 "\n (disable with \"-vsys %d -ignore %d\")\n",
162 a,
163 aConfigValues[a],
164 i, a);
165 break;
166
167 case VirtualSystemDescriptionType_HardDiskControllerSCSI:
168 RTPrintf("%2d: SCSI controller, type %ls"
169 "\n (change with \"-vsys %d -type%d={BusLogic|LsiLogic}\";"
170 "\n disable with \"-vsys %d -ignore %d\")\n",
171 a,
172 aConfigValues[a],
173 i, a, i, a);
174 break;
175
176 case VirtualSystemDescriptionType_HardDiskImage:
177 RTPrintf("%2d: Hard disk image: source image=%ls, target path=%ls, %ls"
178 "\n (change controller with \"-vsys %d -controller%d=<id>\";"
179 "\n disable with \"-vsys %d -ignore %d\")\n",
180 a,
181 aOrigValues[a],
182 aConfigValues[a],
183 aExtraConfigValues[a],
184 i, a, i, a);
185 break;
186
187 case VirtualSystemDescriptionType_CDROM:
188 RTPrintf("%2d: CD-ROM"
189 "\n (disable with \"-vsys %d -ignore %d\")\n",
190 a, i, a);
191 break;
192
193 case VirtualSystemDescriptionType_Floppy:
194 RTPrintf("%2d: Floppy"
195 "\n (disable with \"-vsys %d -ignore %d\")\n",
196 a, i, a);
197 break;
198
199 case VirtualSystemDescriptionType_NetworkAdapter:
200 RTPrintf("%2d: Network adapter: orig %ls, config %ls, extra %ls\n",
201 a,
202 aOrigValues[a],
203 aConfigValues[a],
204 aExtraConfigValues[a]);
205 break;
206
207 case VirtualSystemDescriptionType_USBController:
208 RTPrintf("%2d: USB controller"
209 "\n (disable with \"-vsys %d -ignore %d\")\n",
210 a, i, a);
211 break;
212
213 case VirtualSystemDescriptionType_SoundCard:
214 RTPrintf("%2d: Sound card (appliance expects \"%ls\", can change on import)"
215 "\n (disable with \"-vsys %d -ignore %d\")\n",
216 a,
217 aOrigValues[a],
218 i,
219 a);
220 break;
221 }
222 }
223 }
224
225 if (fExecute)
226 {
227 ComPtr<IProgress> progress;
228 CHECK_ERROR_BREAK(appliance,
229 ImportAppliance(progress.asOutParam()));
230
231 showProgress(progress);
232
233 if (SUCCEEDED(rc))
234 progress->COMGETTER(ResultCode)(&rc);
235
236 if (FAILED(rc))
237 {
238 com::ProgressErrorInfo info(progress);
239 com::GluePrintErrorInfo(info);
240 com::GluePrintErrorContext("ImportAppliance", __FILE__, __LINE__);
241 }
242 else
243 RTPrintf("Successfully imported the appliance.\n");
244 }
245 } // end if (aVirtualSystemDescriptions.size() > 0)
246 } while (0);
247
248 return SUCCEEDED(rc) ? 0 : 1;
249}
250
251#endif /* !VBOX_ONLY_DOCS */
Note: See TracBrowser for help on using the repository browser.

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