VirtualBox

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

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

OVF: add IVirtualSystemDescription::disableItem(), fix disk import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/* $Id: VBoxManageImport.cpp 16517 2009-02-04 16:25:29Z 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/EventQueue.h>
34
35#include <VBox/com/VirtualBox.h>
36
37#include <list>
38#endif /* !VBOX_ONLY_DOCS */
39
40#include <iprt/stream.h>
41
42#include <VBox/log.h>
43
44#include "VBoxManage.h"
45using namespace com;
46
47
48// funcs
49///////////////////////////////////////////////////////////////////////////////
50
51int handleImportAppliance(HandlerArg *a)
52{
53 HRESULT rc = S_OK;
54
55 Utf8Str strOvfFilename;
56 bool fExecute = false; // if true, then we actually do the import (-exec argument)
57
58 for (int i = 0; i < a->argc; i++)
59 {
60 if (!strcmp(a->argv[i], "-exec"))
61 fExecute = true;
62 else if (!strOvfFilename)
63 strOvfFilename = a->argv[i];
64 else
65 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Too many arguments for \"import\" command.");
66 }
67
68 if (!strOvfFilename)
69 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Not enough arguments for \"import\" command.");
70
71 do
72 {
73 Bstr bstrOvfFilename(strOvfFilename);
74 ComPtr<IAppliance> appliance;
75 CHECK_ERROR_BREAK(a->virtualBox, OpenAppliance(bstrOvfFilename, appliance.asOutParam()));
76
77 RTPrintf("Interpreting...\n");
78 CHECK_ERROR_BREAK(appliance, Interpret());
79 RTPrintf("OK.\n");
80
81 // fetch all disks
82 com::SafeArray<BSTR> retDisks;
83 CHECK_ERROR_BREAK(appliance,
84 COMGETTER(Disks)(ComSafeArrayAsOutParam(retDisks)));
85 if (retDisks.size() > 0)
86 {
87 RTPrintf("Disks:");
88 for (unsigned i = 0; i < retDisks.size(); i++)
89 RTPrintf(" %ls", retDisks[i]);
90 RTPrintf("\n");
91 }
92
93 // fetch virtual system descriptions
94 com::SafeIfaceArray<IVirtualSystemDescription> aVirtualSystemDescriptions;
95 CHECK_ERROR_BREAK(appliance,
96 COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(aVirtualSystemDescriptions)));
97 if (aVirtualSystemDescriptions.size() > 0)
98 {
99 for (unsigned i = 0; i < aVirtualSystemDescriptions.size(); ++i)
100 {
101 com::SafeArray<VirtualSystemDescriptionType_T> retTypes;
102 com::SafeArray<BSTR> aRefs;
103 com::SafeArray<BSTR> aOrigValues;
104 com::SafeArray<BSTR> aConfigValues;
105 com::SafeArray<BSTR> aExtraConfigValues;
106 CHECK_ERROR_BREAK(aVirtualSystemDescriptions[i],
107 GetDescription(ComSafeArrayAsOutParam(retTypes),
108 ComSafeArrayAsOutParam(aRefs),
109 ComSafeArrayAsOutParam(aOrigValues),
110 ComSafeArrayAsOutParam(aConfigValues),
111 ComSafeArrayAsOutParam(aExtraConfigValues)));
112
113 RTPrintf("Virtual system %i:\n", i);
114 for (unsigned a = 0; a < retTypes.size(); ++a)
115 {
116 VirtualSystemDescriptionType_T t = retTypes[a];
117
118 Bstr bstrVMname;
119 Bstr bstrOstype;
120 uint32_t ulMemMB;
121 bool fUSB = false;
122
123 switch (t)
124 {
125 case VirtualSystemDescriptionType_Name:
126 bstrVMname = aConfigValues[a];
127 RTPrintf("%2d: Suggested VM name \"%ls\""
128 "\n (change with \"-vsys %d -vmname <name>\")\n",
129 a, bstrVMname.raw(), i);
130 break;
131
132 case VirtualSystemDescriptionType_OS:
133 bstrOstype = aConfigValues[a];
134 RTPrintf("%2d: Suggested OS type: \"%ls\""
135 "\n (change with \"-vsys %d -ostype <type>\"; use \"list ostypes\" to list all)\n",
136 a, bstrOstype.raw(), i);
137 break;
138
139 case VirtualSystemDescriptionType_CPU:
140 RTPrintf("%2d: Number of CPUs (ignored): %ls\n",
141 a, aConfigValues[a]);
142 break;
143
144 case VirtualSystemDescriptionType_Memory:
145 Utf8Str(Bstr(aConfigValues[a])).toInt(ulMemMB);
146 ulMemMB /= 1024 * 1024;
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 {
235 progress->COMGETTER(ResultCode)(&rc);
236 if (FAILED (rc))
237 {
238 com::ProgressErrorInfo info(progress);
239 if (info.isBasicAvailable())
240 RTPrintf("Error: failed to import appliance. Error message: %lS\n", info.getText().raw());
241 else
242 RTPrintf("Error: failed to import appliance. No error message available!\n");
243 }
244 else
245 RTPrintf("Successfully imported the appliance.\n");
246 }
247 }
248 } // end if (aVirtualSystemDescriptions.size() > 0)
249 } while (0);
250
251 return SUCCEEDED(rc) ? 0 : 1;
252}
253
254#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