1 | /* $Id: VBoxManageImport.cpp 16530 2009-02-05 16:08:49Z 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.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 | * 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"
|
---|
46 | using namespace com;
|
---|
47 |
|
---|
48 |
|
---|
49 | // funcs
|
---|
50 | ///////////////////////////////////////////////////////////////////////////////
|
---|
51 |
|
---|
52 | int 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 | ulMemMB /= 1024 * 1024;
|
---|
148 | RTPrintf("%2d: Guest memory: %u MB\n (change with \"-vsys %d -memory <MB>\")\n",
|
---|
149 | a, ulMemMB, i);
|
---|
150 | break;
|
---|
151 |
|
---|
152 | case VirtualSystemDescriptionType_HardDiskControllerIDE:
|
---|
153 | RTPrintf("%2d: IDE controller, type %ls"
|
---|
154 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
155 | a,
|
---|
156 | aConfigValues[a],
|
---|
157 | i, a);
|
---|
158 | break;
|
---|
159 |
|
---|
160 | case VirtualSystemDescriptionType_HardDiskControllerSATA:
|
---|
161 | RTPrintf("%2d: SATA controller, type %ls"
|
---|
162 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
163 | a,
|
---|
164 | aConfigValues[a],
|
---|
165 | i, a);
|
---|
166 | break;
|
---|
167 |
|
---|
168 | case VirtualSystemDescriptionType_HardDiskControllerSCSI:
|
---|
169 | RTPrintf("%2d: SCSI controller, type %ls"
|
---|
170 | "\n (change with \"-vsys %d -type%d={BusLogic|LsiLogic}\";"
|
---|
171 | "\n disable with \"-vsys %d -ignore %d\")\n",
|
---|
172 | a,
|
---|
173 | aConfigValues[a],
|
---|
174 | i, a, i, a);
|
---|
175 | break;
|
---|
176 |
|
---|
177 | case VirtualSystemDescriptionType_HardDiskImage:
|
---|
178 | RTPrintf("%2d: Hard disk image: source image=%ls, target path=%ls, %ls"
|
---|
179 | "\n (change controller with \"-vsys %d -controller%d=<id>\";"
|
---|
180 | "\n disable with \"-vsys %d -ignore %d\")\n",
|
---|
181 | a,
|
---|
182 | aOrigValues[a],
|
---|
183 | aConfigValues[a],
|
---|
184 | aExtraConfigValues[a],
|
---|
185 | i, a, i, a);
|
---|
186 | break;
|
---|
187 |
|
---|
188 | case VirtualSystemDescriptionType_CDROM:
|
---|
189 | RTPrintf("%2d: CD-ROM"
|
---|
190 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
191 | a, i, a);
|
---|
192 | break;
|
---|
193 |
|
---|
194 | case VirtualSystemDescriptionType_Floppy:
|
---|
195 | RTPrintf("%2d: Floppy"
|
---|
196 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
197 | a, i, a);
|
---|
198 | break;
|
---|
199 |
|
---|
200 | case VirtualSystemDescriptionType_NetworkAdapter:
|
---|
201 | RTPrintf("%2d: Network adapter: orig %ls, config %ls, extra %ls\n",
|
---|
202 | a,
|
---|
203 | aOrigValues[a],
|
---|
204 | aConfigValues[a],
|
---|
205 | aExtraConfigValues[a]);
|
---|
206 | break;
|
---|
207 |
|
---|
208 | case VirtualSystemDescriptionType_USBController:
|
---|
209 | RTPrintf("%2d: USB controller"
|
---|
210 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
211 | a, i, a);
|
---|
212 | break;
|
---|
213 |
|
---|
214 | case VirtualSystemDescriptionType_SoundCard:
|
---|
215 | RTPrintf("%2d: Sound card (appliance expects \"%ls\", can change on import)"
|
---|
216 | "\n (disable with \"-vsys %d -ignore %d\")\n",
|
---|
217 | a,
|
---|
218 | aOrigValues[a],
|
---|
219 | i,
|
---|
220 | a);
|
---|
221 | break;
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | if (fExecute)
|
---|
227 | {
|
---|
228 | ComPtr<IProgress> progress;
|
---|
229 | CHECK_ERROR_BREAK(appliance,
|
---|
230 | ImportAppliance(progress.asOutParam()));
|
---|
231 |
|
---|
232 | showProgress(progress);
|
---|
233 |
|
---|
234 | if (SUCCEEDED(rc))
|
---|
235 | {
|
---|
236 | progress->COMGETTER(ResultCode)(&rc);
|
---|
237 | if (FAILED (rc))
|
---|
238 | {
|
---|
239 | com::ProgressErrorInfo info(progress);
|
---|
240 | if (info.isBasicAvailable())
|
---|
241 | RTPrintf("Error: failed to import appliance. Error message: %lS\n", info.getText().raw());
|
---|
242 | else
|
---|
243 | RTPrintf("Error: failed to import appliance. No error message available!\n");
|
---|
244 | }
|
---|
245 | else
|
---|
246 | RTPrintf("Successfully imported the appliance.\n");
|
---|
247 | }
|
---|
248 | }
|
---|
249 | } // end if (aVirtualSystemDescriptions.size() > 0)
|
---|
250 | } while (0);
|
---|
251 |
|
---|
252 | return SUCCEEDED(rc) ? 0 : 1;
|
---|
253 | }
|
---|
254 |
|
---|
255 | #endif /* !VBOX_ONLY_DOCS */
|
---|