1 | /* $Id: VBoxManageList.cpp 42748 2012-08-10 09:33:34Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - The 'list' command.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 | #include <VBox/com/com.h>
|
---|
24 | #include <VBox/com/string.h>
|
---|
25 | #include <VBox/com/Guid.h>
|
---|
26 | #include <VBox/com/array.h>
|
---|
27 | #include <VBox/com/ErrorInfo.h>
|
---|
28 | #include <VBox/com/errorprint.h>
|
---|
29 |
|
---|
30 | #include <VBox/com/VirtualBox.h>
|
---|
31 |
|
---|
32 | #include <VBox/log.h>
|
---|
33 | #include <iprt/stream.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <iprt/time.h>
|
---|
36 | #include <iprt/getopt.h>
|
---|
37 | #include <iprt/ctype.h>
|
---|
38 |
|
---|
39 | #include "VBoxManage.h"
|
---|
40 | using namespace com;
|
---|
41 |
|
---|
42 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
43 | static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
|
---|
44 | {
|
---|
45 | switch (enmType)
|
---|
46 | {
|
---|
47 | case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
|
---|
48 | case HostNetworkInterfaceMediumType_PPP: return "PPP";
|
---|
49 | case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
|
---|
50 | }
|
---|
51 | return "Unknown";
|
---|
52 | }
|
---|
53 |
|
---|
54 | static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
|
---|
55 | {
|
---|
56 | switch (enmStatus)
|
---|
57 | {
|
---|
58 | case HostNetworkInterfaceStatus_Up: return "Up";
|
---|
59 | case HostNetworkInterfaceStatus_Down: return "Down";
|
---|
60 | }
|
---|
61 | return "Unknown";
|
---|
62 | }
|
---|
63 | #endif /* VBOX_WITH_HOSTNETIF_API */
|
---|
64 |
|
---|
65 | static const char*getDeviceTypeText(DeviceType_T enmType)
|
---|
66 | {
|
---|
67 | switch (enmType)
|
---|
68 | {
|
---|
69 | case DeviceType_HardDisk: return "HardDisk";
|
---|
70 | case DeviceType_DVD: return "DVD";
|
---|
71 | case DeviceType_Floppy: return "Floppy";
|
---|
72 | }
|
---|
73 | return "Unknown";
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * List network interfaces information (bridged/host only).
|
---|
79 | *
|
---|
80 | * @returns See produceList.
|
---|
81 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
82 | */
|
---|
83 | static HRESULT listNetworkInterfaces(const ComPtr<IVirtualBox> pVirtualBox,
|
---|
84 | bool fIsBridged)
|
---|
85 | {
|
---|
86 | HRESULT rc;
|
---|
87 | ComPtr<IHost> host;
|
---|
88 | CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
89 | com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
|
---|
90 | #if defined(VBOX_WITH_NETFLT)
|
---|
91 | if (fIsBridged)
|
---|
92 | CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
|
---|
93 | ComSafeArrayAsOutParam(hostNetworkInterfaces)));
|
---|
94 | else
|
---|
95 | CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
|
---|
96 | ComSafeArrayAsOutParam(hostNetworkInterfaces)));
|
---|
97 | #else
|
---|
98 | CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
|
---|
99 | #endif
|
---|
100 | for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
|
---|
101 | {
|
---|
102 | ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
|
---|
103 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
104 | Bstr interfaceName;
|
---|
105 | networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
|
---|
106 | RTPrintf("Name: %ls\n", interfaceName.raw());
|
---|
107 | Guid interfaceGuid;
|
---|
108 | networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
|
---|
109 | RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
|
---|
110 | #else /* VBOX_WITH_HOSTNETIF_API */
|
---|
111 | Bstr interfaceName;
|
---|
112 | networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
|
---|
113 | RTPrintf("Name: %ls\n", interfaceName.raw());
|
---|
114 | Bstr interfaceGuid;
|
---|
115 | networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
|
---|
116 | RTPrintf("GUID: %ls\n", interfaceGuid.raw());
|
---|
117 | BOOL bDHCPEnabled;
|
---|
118 | networkInterface->COMGETTER(DHCPEnabled)(&bDHCPEnabled);
|
---|
119 | RTPrintf("DHCP: %s\n", bDHCPEnabled ? "Enabled" : "Disabled");
|
---|
120 |
|
---|
121 | Bstr IPAddress;
|
---|
122 | networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
|
---|
123 | RTPrintf("IPAddress: %ls\n", IPAddress.raw());
|
---|
124 | Bstr NetworkMask;
|
---|
125 | networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
|
---|
126 | RTPrintf("NetworkMask: %ls\n", NetworkMask.raw());
|
---|
127 | Bstr IPV6Address;
|
---|
128 | networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
|
---|
129 | RTPrintf("IPV6Address: %ls\n", IPV6Address.raw());
|
---|
130 | ULONG IPV6NetworkMaskPrefixLength;
|
---|
131 | networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
|
---|
132 | RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
|
---|
133 | Bstr HardwareAddress;
|
---|
134 | networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
|
---|
135 | RTPrintf("HardwareAddress: %ls\n", HardwareAddress.raw());
|
---|
136 | HostNetworkInterfaceMediumType_T Type;
|
---|
137 | networkInterface->COMGETTER(MediumType)(&Type);
|
---|
138 | RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
|
---|
139 | HostNetworkInterfaceStatus_T Status;
|
---|
140 | networkInterface->COMGETTER(Status)(&Status);
|
---|
141 | RTPrintf("Status: %s\n", getHostIfStatusText(Status));
|
---|
142 | Bstr netName;
|
---|
143 | networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
|
---|
144 | RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
|
---|
145 | #endif
|
---|
146 | }
|
---|
147 | return rc;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * List host information.
|
---|
153 | *
|
---|
154 | * @returns See produceList.
|
---|
155 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
156 | */
|
---|
157 | static HRESULT listHostInfo(const ComPtr<IVirtualBox> pVirtualBox)
|
---|
158 | {
|
---|
159 | HRESULT rc;
|
---|
160 | ComPtr<IHost> Host;
|
---|
161 | CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
|
---|
162 |
|
---|
163 | RTPrintf("Host Information:\n\n");
|
---|
164 |
|
---|
165 | LONG64 u64UtcTime = 0;
|
---|
166 | CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
|
---|
167 | RTTIMESPEC timeSpec;
|
---|
168 | char szTime[32];
|
---|
169 | RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
|
---|
170 |
|
---|
171 | ULONG processorOnlineCount = 0;
|
---|
172 | CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
|
---|
173 | RTPrintf("Processor online count: %lu\n", processorOnlineCount);
|
---|
174 | ULONG processorCount = 0;
|
---|
175 | CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
|
---|
176 | RTPrintf("Processor count: %lu\n", processorCount);
|
---|
177 | ULONG processorSpeed = 0;
|
---|
178 | Bstr processorDescription;
|
---|
179 | for (ULONG i = 0; i < processorCount; i++)
|
---|
180 | {
|
---|
181 | CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
|
---|
182 | if (processorSpeed)
|
---|
183 | RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
|
---|
184 | else
|
---|
185 | RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
|
---|
186 | CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
|
---|
187 | RTPrintf("Processor#%u description: %ls\n", i, processorDescription.raw());
|
---|
188 | }
|
---|
189 |
|
---|
190 | ULONG memorySize = 0;
|
---|
191 | CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
|
---|
192 | RTPrintf("Memory size: %lu MByte\n", memorySize);
|
---|
193 |
|
---|
194 | ULONG memoryAvailable = 0;
|
---|
195 | CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
|
---|
196 | RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
|
---|
197 |
|
---|
198 | Bstr operatingSystem;
|
---|
199 | CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
|
---|
200 | RTPrintf("Operating system: %ls\n", operatingSystem.raw());
|
---|
201 |
|
---|
202 | Bstr oSVersion;
|
---|
203 | CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
|
---|
204 | RTPrintf("Operating system version: %ls\n", oSVersion.raw());
|
---|
205 | return rc;
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * List media information.
|
---|
211 | *
|
---|
212 | * @returns See produceList.
|
---|
213 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
214 | */
|
---|
215 | static HRESULT listMedia(const ComPtr<IVirtualBox> pVirtualBox,
|
---|
216 | const com::SafeIfaceArray<IMedium> &aMedia,
|
---|
217 | const char *pszParentUUIDStr)
|
---|
218 | {
|
---|
219 | HRESULT rc = S_OK;
|
---|
220 | for (size_t i = 0; i < aMedia.size(); ++i)
|
---|
221 | {
|
---|
222 | ComPtr<IMedium> pMedium = aMedia[i];
|
---|
223 | Bstr uuid;
|
---|
224 | pMedium->COMGETTER(Id)(uuid.asOutParam());
|
---|
225 | RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
|
---|
226 | if (pszParentUUIDStr)
|
---|
227 | RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
|
---|
228 | Bstr format;
|
---|
229 | pMedium->COMGETTER(Format)(format.asOutParam());
|
---|
230 | RTPrintf("Format: %ls\n", format.raw());
|
---|
231 | Bstr filepath;
|
---|
232 | pMedium->COMGETTER(Location)(filepath.asOutParam());
|
---|
233 | RTPrintf("Location: %ls\n", filepath.raw());
|
---|
234 |
|
---|
235 | MediumState_T enmState;
|
---|
236 | pMedium->RefreshState(&enmState);
|
---|
237 | const char *stateStr = "unknown";
|
---|
238 | switch (enmState)
|
---|
239 | {
|
---|
240 | case MediumState_NotCreated:
|
---|
241 | stateStr = "not created";
|
---|
242 | break;
|
---|
243 | case MediumState_Created:
|
---|
244 | stateStr = "created";
|
---|
245 | break;
|
---|
246 | case MediumState_LockedRead:
|
---|
247 | stateStr = "locked read";
|
---|
248 | break;
|
---|
249 | case MediumState_LockedWrite:
|
---|
250 | stateStr = "locked write";
|
---|
251 | break;
|
---|
252 | case MediumState_Inaccessible:
|
---|
253 | stateStr = "inaccessible";
|
---|
254 | break;
|
---|
255 | case MediumState_Creating:
|
---|
256 | stateStr = "creating";
|
---|
257 | break;
|
---|
258 | case MediumState_Deleting:
|
---|
259 | stateStr = "deleting";
|
---|
260 | break;
|
---|
261 | }
|
---|
262 | RTPrintf("State: %s\n", stateStr);
|
---|
263 |
|
---|
264 | MediumType_T type;
|
---|
265 | pMedium->COMGETTER(Type)(&type);
|
---|
266 | const char *typeStr = "unknown";
|
---|
267 | switch (type)
|
---|
268 | {
|
---|
269 | case MediumType_Normal:
|
---|
270 | typeStr = "normal";
|
---|
271 | break;
|
---|
272 | case MediumType_Immutable:
|
---|
273 | typeStr = "immutable";
|
---|
274 | break;
|
---|
275 | case MediumType_Writethrough:
|
---|
276 | typeStr = "writethrough";
|
---|
277 | break;
|
---|
278 | case MediumType_Shareable:
|
---|
279 | typeStr = "shareable";
|
---|
280 | break;
|
---|
281 | case MediumType_Readonly:
|
---|
282 | typeStr = "readonly";
|
---|
283 | break;
|
---|
284 | case MediumType_MultiAttach:
|
---|
285 | typeStr = "multiattach";
|
---|
286 | break;
|
---|
287 | }
|
---|
288 | RTPrintf("Type: %s\n", typeStr);
|
---|
289 |
|
---|
290 | com::SafeArray<BSTR> machineIds;
|
---|
291 | pMedium->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
|
---|
292 | for (size_t j = 0; j < machineIds.size(); ++j)
|
---|
293 | {
|
---|
294 | ComPtr<IMachine> machine;
|
---|
295 | CHECK_ERROR(pVirtualBox, FindMachine(machineIds[j], machine.asOutParam()));
|
---|
296 | ASSERT(machine);
|
---|
297 | Bstr name;
|
---|
298 | machine->COMGETTER(Name)(name.asOutParam());
|
---|
299 | RTPrintf("%s%ls (UUID: %ls)",
|
---|
300 | j == 0 ? "Usage: " : " ",
|
---|
301 | name.raw(), machineIds[j]);
|
---|
302 | com::SafeArray<BSTR> snapshotIds;
|
---|
303 | pMedium->GetSnapshotIds(machineIds[j],
|
---|
304 | ComSafeArrayAsOutParam(snapshotIds));
|
---|
305 | for (size_t k = 0; k < snapshotIds.size(); ++k)
|
---|
306 | {
|
---|
307 | ComPtr<ISnapshot> snapshot;
|
---|
308 | machine->FindSnapshot(snapshotIds[k], snapshot.asOutParam());
|
---|
309 | if (snapshot)
|
---|
310 | {
|
---|
311 | Bstr snapshotName;
|
---|
312 | snapshot->COMGETTER(Name)(snapshotName.asOutParam());
|
---|
313 | RTPrintf(" [%ls (UUID: %ls)]", snapshotName.raw(), snapshotIds[k]);
|
---|
314 | }
|
---|
315 | }
|
---|
316 | RTPrintf("\n");
|
---|
317 | }
|
---|
318 | RTPrintf("\n");
|
---|
319 |
|
---|
320 | com::SafeIfaceArray<IMedium> children;
|
---|
321 | CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
|
---|
322 | if (children.size() > 0)
|
---|
323 | {
|
---|
324 | // depth first listing of child media
|
---|
325 | rc = listMedia(pVirtualBox, children, Utf8Str(uuid).c_str());
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | return rc;
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * List virtual image backends.
|
---|
335 | *
|
---|
336 | * @returns See produceList.
|
---|
337 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
338 | */
|
---|
339 | static HRESULT listHddBackends(const ComPtr<IVirtualBox> pVirtualBox)
|
---|
340 | {
|
---|
341 | HRESULT rc;
|
---|
342 | ComPtr<ISystemProperties> systemProperties;
|
---|
343 | CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
|
---|
344 | com::SafeIfaceArray<IMediumFormat> mediumFormats;
|
---|
345 | CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
|
---|
346 |
|
---|
347 | RTPrintf("Supported hard disk backends:\n\n");
|
---|
348 | for (size_t i = 0; i < mediumFormats.size(); ++i)
|
---|
349 | {
|
---|
350 | /* General information */
|
---|
351 | Bstr id;
|
---|
352 | CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
|
---|
353 |
|
---|
354 | Bstr description;
|
---|
355 | CHECK_ERROR(mediumFormats[i],
|
---|
356 | COMGETTER(Id)(description.asOutParam()));
|
---|
357 |
|
---|
358 | ULONG caps;
|
---|
359 | CHECK_ERROR(mediumFormats[i],
|
---|
360 | COMGETTER(Capabilities)(&caps));
|
---|
361 |
|
---|
362 | RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
|
---|
363 | i, id.raw(), description.raw(), caps);
|
---|
364 |
|
---|
365 | /* File extensions */
|
---|
366 | com::SafeArray <BSTR> fileExtensions;
|
---|
367 | com::SafeArray <DeviceType_T> deviceTypes;
|
---|
368 | CHECK_ERROR(mediumFormats[i],
|
---|
369 | DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
|
---|
370 | for (size_t j = 0; j < fileExtensions.size(); ++j)
|
---|
371 | {
|
---|
372 | RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
|
---|
373 | if (j != fileExtensions.size()-1)
|
---|
374 | RTPrintf(",");
|
---|
375 | }
|
---|
376 | RTPrintf("'");
|
---|
377 |
|
---|
378 | /* Configuration keys */
|
---|
379 | com::SafeArray <BSTR> propertyNames;
|
---|
380 | com::SafeArray <BSTR> propertyDescriptions;
|
---|
381 | com::SafeArray <DataType_T> propertyTypes;
|
---|
382 | com::SafeArray <ULONG> propertyFlags;
|
---|
383 | com::SafeArray <BSTR> propertyDefaults;
|
---|
384 | CHECK_ERROR(mediumFormats[i],
|
---|
385 | DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
|
---|
386 | ComSafeArrayAsOutParam(propertyDescriptions),
|
---|
387 | ComSafeArrayAsOutParam(propertyTypes),
|
---|
388 | ComSafeArrayAsOutParam(propertyFlags),
|
---|
389 | ComSafeArrayAsOutParam(propertyDefaults)));
|
---|
390 |
|
---|
391 | RTPrintf(" properties=(");
|
---|
392 | if (propertyNames.size() > 0)
|
---|
393 | {
|
---|
394 | for (size_t j = 0; j < propertyNames.size(); ++j)
|
---|
395 | {
|
---|
396 | RTPrintf("\n name='%ls' desc='%ls' type=",
|
---|
397 | Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
|
---|
398 | switch (propertyTypes[j])
|
---|
399 | {
|
---|
400 | case DataType_Int32: RTPrintf("int"); break;
|
---|
401 | case DataType_Int8: RTPrintf("byte"); break;
|
---|
402 | case DataType_String: RTPrintf("string"); break;
|
---|
403 | }
|
---|
404 | RTPrintf(" flags=%#04x", propertyFlags[j]);
|
---|
405 | RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
|
---|
406 | if (j != propertyNames.size()-1)
|
---|
407 | RTPrintf(", ");
|
---|
408 | }
|
---|
409 | }
|
---|
410 | RTPrintf(")\n");
|
---|
411 | }
|
---|
412 | return rc;
|
---|
413 | }
|
---|
414 |
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * List USB devices attached to the host.
|
---|
418 | *
|
---|
419 | * @returns See produceList.
|
---|
420 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
421 | */
|
---|
422 | static HRESULT listUsbHost(const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
423 | {
|
---|
424 | HRESULT rc;
|
---|
425 | ComPtr<IHost> Host;
|
---|
426 | CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
|
---|
427 |
|
---|
428 | SafeIfaceArray<IHostUSBDevice> CollPtr;
|
---|
429 | CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
|
---|
430 |
|
---|
431 | RTPrintf("Host USB Devices:\n\n");
|
---|
432 |
|
---|
433 | if (CollPtr.size() == 0)
|
---|
434 | {
|
---|
435 | RTPrintf("<none>\n\n");
|
---|
436 | }
|
---|
437 | else
|
---|
438 | {
|
---|
439 | for (size_t i = 0; i < CollPtr.size(); ++i)
|
---|
440 | {
|
---|
441 | ComPtr <IHostUSBDevice> dev = CollPtr[i];
|
---|
442 |
|
---|
443 | /* Query info. */
|
---|
444 | Bstr id;
|
---|
445 | CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
|
---|
446 | USHORT usVendorId;
|
---|
447 | CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
|
---|
448 | USHORT usProductId;
|
---|
449 | CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
|
---|
450 | USHORT bcdRevision;
|
---|
451 | CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
|
---|
452 | USHORT usPort;
|
---|
453 | CHECK_ERROR_RET(dev, COMGETTER(Port)(&usPort), 1);
|
---|
454 | USHORT usVersion;
|
---|
455 | CHECK_ERROR_RET(dev, COMGETTER(Version)(&usVersion), 1);
|
---|
456 | USHORT usPortVersion;
|
---|
457 | CHECK_ERROR_RET(dev, COMGETTER(PortVersion)(&usPortVersion), 1);
|
---|
458 |
|
---|
459 | RTPrintf("UUID: %s\n"
|
---|
460 | "VendorId: %#06x (%04X)\n"
|
---|
461 | "ProductId: %#06x (%04X)\n"
|
---|
462 | "Revision: %u.%u (%02u%02u)\n"
|
---|
463 | "Port: %u\n"
|
---|
464 | "USB version/speed: %u/%u\n",
|
---|
465 | Utf8Str(id).c_str(),
|
---|
466 | usVendorId, usVendorId, usProductId, usProductId,
|
---|
467 | bcdRevision >> 8, bcdRevision & 0xff,
|
---|
468 | bcdRevision >> 8, bcdRevision & 0xff,
|
---|
469 | usPort, usVersion, usPortVersion);
|
---|
470 |
|
---|
471 | /* optional stuff. */
|
---|
472 | Bstr bstr;
|
---|
473 | CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
|
---|
474 | if (!bstr.isEmpty())
|
---|
475 | RTPrintf("Manufacturer: %ls\n", bstr.raw());
|
---|
476 | CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
|
---|
477 | if (!bstr.isEmpty())
|
---|
478 | RTPrintf("Product: %ls\n", bstr.raw());
|
---|
479 | CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
|
---|
480 | if (!bstr.isEmpty())
|
---|
481 | RTPrintf("SerialNumber: %ls\n", bstr.raw());
|
---|
482 | CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
|
---|
483 | if (!bstr.isEmpty())
|
---|
484 | RTPrintf("Address: %ls\n", bstr.raw());
|
---|
485 |
|
---|
486 | /* current state */
|
---|
487 | USBDeviceState_T state;
|
---|
488 | CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
|
---|
489 | const char *pszState = "?";
|
---|
490 | switch (state)
|
---|
491 | {
|
---|
492 | case USBDeviceState_NotSupported:
|
---|
493 | pszState = "Not supported";
|
---|
494 | break;
|
---|
495 | case USBDeviceState_Unavailable:
|
---|
496 | pszState = "Unavailable";
|
---|
497 | break;
|
---|
498 | case USBDeviceState_Busy:
|
---|
499 | pszState = "Busy";
|
---|
500 | break;
|
---|
501 | case USBDeviceState_Available:
|
---|
502 | pszState = "Available";
|
---|
503 | break;
|
---|
504 | case USBDeviceState_Held:
|
---|
505 | pszState = "Held";
|
---|
506 | break;
|
---|
507 | case USBDeviceState_Captured:
|
---|
508 | pszState = "Captured";
|
---|
509 | break;
|
---|
510 | default:
|
---|
511 | ASSERT(false);
|
---|
512 | break;
|
---|
513 | }
|
---|
514 | RTPrintf("Current State: %s\n\n", pszState);
|
---|
515 | }
|
---|
516 | }
|
---|
517 | return rc;
|
---|
518 | }
|
---|
519 |
|
---|
520 |
|
---|
521 | /**
|
---|
522 | * List USB filters.
|
---|
523 | *
|
---|
524 | * @returns See produceList.
|
---|
525 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
526 | */
|
---|
527 | static HRESULT listUsbFilters(const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
528 | {
|
---|
529 | HRESULT rc;
|
---|
530 |
|
---|
531 | RTPrintf("Global USB Device Filters:\n\n");
|
---|
532 |
|
---|
533 | ComPtr<IHost> host;
|
---|
534 | CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
|
---|
535 |
|
---|
536 | SafeIfaceArray<IHostUSBDeviceFilter> coll;
|
---|
537 | CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
|
---|
538 |
|
---|
539 | if (coll.size() == 0)
|
---|
540 | {
|
---|
541 | RTPrintf("<none>\n\n");
|
---|
542 | }
|
---|
543 | else
|
---|
544 | {
|
---|
545 | for (size_t index = 0; index < coll.size(); ++index)
|
---|
546 | {
|
---|
547 | ComPtr<IHostUSBDeviceFilter> flt = coll[index];
|
---|
548 |
|
---|
549 | /* Query info. */
|
---|
550 |
|
---|
551 | RTPrintf("Index: %zu\n", index);
|
---|
552 |
|
---|
553 | BOOL active = FALSE;
|
---|
554 | CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
|
---|
555 | RTPrintf("Active: %s\n", active ? "yes" : "no");
|
---|
556 |
|
---|
557 | USBDeviceFilterAction_T action;
|
---|
558 | CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
|
---|
559 | const char *pszAction = "<invalid>";
|
---|
560 | switch (action)
|
---|
561 | {
|
---|
562 | case USBDeviceFilterAction_Ignore:
|
---|
563 | pszAction = "Ignore";
|
---|
564 | break;
|
---|
565 | case USBDeviceFilterAction_Hold:
|
---|
566 | pszAction = "Hold";
|
---|
567 | break;
|
---|
568 | default:
|
---|
569 | break;
|
---|
570 | }
|
---|
571 | RTPrintf("Action: %s\n", pszAction);
|
---|
572 |
|
---|
573 | Bstr bstr;
|
---|
574 | CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
|
---|
575 | RTPrintf("Name: %ls\n", bstr.raw());
|
---|
576 | CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
|
---|
577 | RTPrintf("VendorId: %ls\n", bstr.raw());
|
---|
578 | CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
|
---|
579 | RTPrintf("ProductId: %ls\n", bstr.raw());
|
---|
580 | CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
|
---|
581 | RTPrintf("Revision: %ls\n", bstr.raw());
|
---|
582 | CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
|
---|
583 | RTPrintf("Manufacturer: %ls\n", bstr.raw());
|
---|
584 | CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
|
---|
585 | RTPrintf("Product: %ls\n", bstr.raw());
|
---|
586 | CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
|
---|
587 | RTPrintf("Serial Number: %ls\n\n", bstr.raw());
|
---|
588 | }
|
---|
589 | }
|
---|
590 | return rc;
|
---|
591 | }
|
---|
592 |
|
---|
593 |
|
---|
594 | /**
|
---|
595 | * List system properties.
|
---|
596 | *
|
---|
597 | * @returns See produceList.
|
---|
598 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
599 | */
|
---|
600 | static HRESULT listSystemProperties(const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
601 | {
|
---|
602 | ComPtr<ISystemProperties> systemProperties;
|
---|
603 | pVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
|
---|
604 |
|
---|
605 | Bstr str;
|
---|
606 | ULONG ulValue;
|
---|
607 | LONG64 i64Value;
|
---|
608 |
|
---|
609 | pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
|
---|
610 | RTPrintf("API version: %ls\n", str.raw());
|
---|
611 |
|
---|
612 | systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
|
---|
613 | RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
|
---|
614 | systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
|
---|
615 | RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
|
---|
616 | systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
|
---|
617 | RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
|
---|
618 | systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
|
---|
619 | RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
|
---|
620 | systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
|
---|
621 | RTPrintf("Minimum guest CPU count: %u\n", ulValue);
|
---|
622 | systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
|
---|
623 | RTPrintf("Maximum guest CPU count: %u\n", ulValue);
|
---|
624 | systemProperties->COMGETTER(InfoVDSize)(&i64Value);
|
---|
625 | RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
|
---|
626 | systemProperties->COMGETTER(SerialPortCount)(&ulValue);
|
---|
627 | RTPrintf("Maximum Serial Port count: %u\n", ulValue);
|
---|
628 | systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
|
---|
629 | RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
|
---|
630 | systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
|
---|
631 | RTPrintf("Maximum Boot Position: %u\n", ulValue);
|
---|
632 | systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
|
---|
633 | RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
|
---|
634 | systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
|
---|
635 | RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
|
---|
636 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
|
---|
637 | RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
|
---|
638 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
|
---|
639 | RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
|
---|
640 | systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
|
---|
641 | RTPrintf("Maximum IDE Port count: %u\n", ulValue);
|
---|
642 | systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
|
---|
643 | RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
|
---|
644 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
|
---|
645 | RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
|
---|
646 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
|
---|
647 | RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
|
---|
648 | systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
|
---|
649 | RTPrintf("Maximum SATA Port count: %u\n", ulValue);
|
---|
650 | systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
|
---|
651 | RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
|
---|
652 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
|
---|
653 | RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
|
---|
654 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
|
---|
655 | RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
|
---|
656 | systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
|
---|
657 | RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
|
---|
658 | systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
|
---|
659 | RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
|
---|
660 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
|
---|
661 | RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
|
---|
662 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
|
---|
663 | RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
|
---|
664 | systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
|
---|
665 | RTPrintf("Maximum SAS Port count: %u\n", ulValue);
|
---|
666 | systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
|
---|
667 | RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
|
---|
668 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
|
---|
669 | RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
|
---|
670 | systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
|
---|
671 | RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
|
---|
672 | systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
|
---|
673 | RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
|
---|
674 | systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
|
---|
675 | RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
|
---|
676 | systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
|
---|
677 | RTPrintf("Default machine folder: %ls\n", str.raw());
|
---|
678 | systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
|
---|
679 | RTPrintf("VRDE auth library: %ls\n", str.raw());
|
---|
680 | systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
|
---|
681 | RTPrintf("Webservice auth. library: %ls\n", str.raw());
|
---|
682 | systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
|
---|
683 | RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
|
---|
684 | systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
|
---|
685 | RTPrintf("Log history count: %u\n", ulValue);
|
---|
686 | systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
|
---|
687 | RTPrintf("Autostart database path: %ls\n", str.raw());
|
---|
688 | systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
|
---|
689 | RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
|
---|
690 | return S_OK;
|
---|
691 | }
|
---|
692 |
|
---|
693 |
|
---|
694 | /**
|
---|
695 | * List extension packs.
|
---|
696 | *
|
---|
697 | * @returns See produceList.
|
---|
698 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
699 | */
|
---|
700 | static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
701 | {
|
---|
702 | ComObjPtr<IExtPackManager> ptrExtPackMgr;
|
---|
703 | CHECK_ERROR2_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
|
---|
704 |
|
---|
705 | SafeIfaceArray<IExtPack> extPacks;
|
---|
706 | CHECK_ERROR2_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
|
---|
707 | RTPrintf("Extension Packs: %u\n", extPacks.size());
|
---|
708 |
|
---|
709 | HRESULT hrc = S_OK;
|
---|
710 | for (size_t i = 0; i < extPacks.size(); i++)
|
---|
711 | {
|
---|
712 | /* Read all the properties. */
|
---|
713 | Bstr bstrName;
|
---|
714 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
|
---|
715 | Bstr bstrDesc;
|
---|
716 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
|
---|
717 | Bstr bstrVersion;
|
---|
718 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
|
---|
719 | ULONG uRevision;
|
---|
720 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
|
---|
721 | Bstr bstrEdition;
|
---|
722 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
|
---|
723 | Bstr bstrVrdeModule;
|
---|
724 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
|
---|
725 | BOOL fUsable;
|
---|
726 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
|
---|
727 | Bstr bstrWhy;
|
---|
728 | CHECK_ERROR2_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
|
---|
729 |
|
---|
730 | /* Display them. */
|
---|
731 | if (i)
|
---|
732 | RTPrintf("\n");
|
---|
733 | RTPrintf("Pack no.%2zu: %ls\n"
|
---|
734 | "Version: %ls\n"
|
---|
735 | "Revision: %u\n"
|
---|
736 | "Edition: %ls\n"
|
---|
737 | "Description: %ls\n"
|
---|
738 | "VRDE Module: %ls\n"
|
---|
739 | "Usable: %RTbool\n"
|
---|
740 | "Why unusable: %ls\n",
|
---|
741 | i, bstrName.raw(),
|
---|
742 | bstrVersion.raw(),
|
---|
743 | uRevision,
|
---|
744 | bstrEdition.raw(),
|
---|
745 | bstrDesc.raw(),
|
---|
746 | bstrVrdeModule.raw(),
|
---|
747 | fUsable != FALSE,
|
---|
748 | bstrWhy.raw());
|
---|
749 |
|
---|
750 | /* Query plugins and display them. */
|
---|
751 | }
|
---|
752 | return hrc;
|
---|
753 | }
|
---|
754 |
|
---|
755 |
|
---|
756 | /**
|
---|
757 | * List machine groups.
|
---|
758 | *
|
---|
759 | * @returns See produceList.
|
---|
760 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
761 | */
|
---|
762 | static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
763 | {
|
---|
764 | SafeArray<BSTR> groups;
|
---|
765 | CHECK_ERROR2_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
|
---|
766 |
|
---|
767 | for (size_t i = 0; i < groups.size(); i++)
|
---|
768 | {
|
---|
769 | RTPrintf("\"%ls\"\n", groups[i]);
|
---|
770 | }
|
---|
771 | return S_OK;
|
---|
772 | }
|
---|
773 |
|
---|
774 |
|
---|
775 | /**
|
---|
776 | * The type of lists we can produce.
|
---|
777 | */
|
---|
778 | enum enmListType
|
---|
779 | {
|
---|
780 | kListNotSpecified = 1000,
|
---|
781 | kListVMs,
|
---|
782 | kListRunningVMs,
|
---|
783 | kListOsTypes,
|
---|
784 | kListHostDvds,
|
---|
785 | kListHostFloppies,
|
---|
786 | kListBridgedInterfaces,
|
---|
787 | #if defined(VBOX_WITH_NETFLT)
|
---|
788 | kListHostOnlyInterfaces,
|
---|
789 | #endif
|
---|
790 | kListHostCpuIDs,
|
---|
791 | kListHostInfo,
|
---|
792 | kListHddBackends,
|
---|
793 | kListHdds,
|
---|
794 | kListDvds,
|
---|
795 | kListFloppies,
|
---|
796 | kListUsbHost,
|
---|
797 | kListUsbFilters,
|
---|
798 | kListSystemProperties,
|
---|
799 | kListDhcpServers,
|
---|
800 | kListExtPacks,
|
---|
801 | kListGroups
|
---|
802 | };
|
---|
803 |
|
---|
804 |
|
---|
805 | /**
|
---|
806 | * Produces the specified listing.
|
---|
807 | *
|
---|
808 | * @returns S_OK or some COM error code that has been reported in full.
|
---|
809 | * @param enmList The list to produce.
|
---|
810 | * @param fOptLong Long (@c true) or short list format.
|
---|
811 | * @param pVirtualBox Reference to the IVirtualBox smart pointer.
|
---|
812 | */
|
---|
813 | static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &pVirtualBox)
|
---|
814 | {
|
---|
815 | HRESULT rc = S_OK;
|
---|
816 | switch (enmCommand)
|
---|
817 | {
|
---|
818 | case kListNotSpecified:
|
---|
819 | AssertFailed();
|
---|
820 | return E_FAIL;
|
---|
821 |
|
---|
822 | case kListVMs:
|
---|
823 | {
|
---|
824 | /*
|
---|
825 | * Get the list of all registered VMs
|
---|
826 | */
|
---|
827 | com::SafeIfaceArray<IMachine> machines;
|
---|
828 | rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
|
---|
829 | if (SUCCEEDED(rc))
|
---|
830 | {
|
---|
831 | /*
|
---|
832 | * Iterate through the collection
|
---|
833 | */
|
---|
834 | for (size_t i = 0; i < machines.size(); ++i)
|
---|
835 | {
|
---|
836 | if (machines[i])
|
---|
837 | rc = showVMInfo(pVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
|
---|
838 | }
|
---|
839 | }
|
---|
840 | break;
|
---|
841 | }
|
---|
842 |
|
---|
843 | case kListRunningVMs:
|
---|
844 | {
|
---|
845 | /*
|
---|
846 | * Get the list of all _running_ VMs
|
---|
847 | */
|
---|
848 | com::SafeIfaceArray<IMachine> machines;
|
---|
849 | rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
|
---|
850 | com::SafeArray<MachineState_T> states;
|
---|
851 | if (SUCCEEDED(rc))
|
---|
852 | rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
|
---|
853 | if (SUCCEEDED(rc))
|
---|
854 | {
|
---|
855 | /*
|
---|
856 | * Iterate through the collection
|
---|
857 | */
|
---|
858 | for (size_t i = 0; i < machines.size(); ++i)
|
---|
859 | {
|
---|
860 | if (machines[i])
|
---|
861 | {
|
---|
862 | MachineState_T machineState = states[i];
|
---|
863 | switch (machineState)
|
---|
864 | {
|
---|
865 | case MachineState_Running:
|
---|
866 | case MachineState_Teleporting:
|
---|
867 | case MachineState_LiveSnapshotting:
|
---|
868 | case MachineState_Paused:
|
---|
869 | case MachineState_TeleportingPausedVM:
|
---|
870 | rc = showVMInfo(pVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
|
---|
871 | break;
|
---|
872 | }
|
---|
873 | }
|
---|
874 | }
|
---|
875 | }
|
---|
876 | break;
|
---|
877 | }
|
---|
878 |
|
---|
879 | case kListOsTypes:
|
---|
880 | {
|
---|
881 | com::SafeIfaceArray<IGuestOSType> coll;
|
---|
882 | rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
|
---|
883 | if (SUCCEEDED(rc))
|
---|
884 | {
|
---|
885 | /*
|
---|
886 | * Iterate through the collection.
|
---|
887 | */
|
---|
888 | for (size_t i = 0; i < coll.size(); ++i)
|
---|
889 | {
|
---|
890 | ComPtr<IGuestOSType> guestOS;
|
---|
891 | guestOS = coll[i];
|
---|
892 | Bstr guestId;
|
---|
893 | guestOS->COMGETTER(Id)(guestId.asOutParam());
|
---|
894 | RTPrintf("ID: %ls\n", guestId.raw());
|
---|
895 | Bstr guestDescription;
|
---|
896 | guestOS->COMGETTER(Description)(guestDescription.asOutParam());
|
---|
897 | RTPrintf("Description: %ls\n", guestDescription.raw());
|
---|
898 | Bstr familyId;
|
---|
899 | guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
|
---|
900 | RTPrintf("Family ID: %ls\n", familyId.raw());
|
---|
901 | Bstr familyDescription;
|
---|
902 | guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
|
---|
903 | RTPrintf("Family Desc: %ls\n", familyDescription.raw());
|
---|
904 | BOOL is64Bit;
|
---|
905 | guestOS->COMGETTER(Is64Bit)(&is64Bit);
|
---|
906 | RTPrintf("64 bit: %RTbool\n", is64Bit);
|
---|
907 | RTPrintf("\n");
|
---|
908 | }
|
---|
909 | }
|
---|
910 | break;
|
---|
911 | }
|
---|
912 |
|
---|
913 | case kListHostDvds:
|
---|
914 | {
|
---|
915 | ComPtr<IHost> host;
|
---|
916 | CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
917 | com::SafeIfaceArray<IMedium> coll;
|
---|
918 | CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
|
---|
919 | if (SUCCEEDED(rc))
|
---|
920 | {
|
---|
921 | for (size_t i = 0; i < coll.size(); ++i)
|
---|
922 | {
|
---|
923 | ComPtr<IMedium> dvdDrive = coll[i];
|
---|
924 | Bstr uuid;
|
---|
925 | dvdDrive->COMGETTER(Id)(uuid.asOutParam());
|
---|
926 | RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
|
---|
927 | Bstr location;
|
---|
928 | dvdDrive->COMGETTER(Location)(location.asOutParam());
|
---|
929 | RTPrintf("Name: %ls\n\n", location.raw());
|
---|
930 | }
|
---|
931 | }
|
---|
932 | break;
|
---|
933 | }
|
---|
934 |
|
---|
935 | case kListHostFloppies:
|
---|
936 | {
|
---|
937 | ComPtr<IHost> host;
|
---|
938 | CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
939 | com::SafeIfaceArray<IMedium> coll;
|
---|
940 | CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
|
---|
941 | if (SUCCEEDED(rc))
|
---|
942 | {
|
---|
943 | for (size_t i = 0; i < coll.size(); ++i)
|
---|
944 | {
|
---|
945 | ComPtr<IMedium> floppyDrive = coll[i];
|
---|
946 | Bstr uuid;
|
---|
947 | floppyDrive->COMGETTER(Id)(uuid.asOutParam());
|
---|
948 | RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
|
---|
949 | Bstr location;
|
---|
950 | floppyDrive->COMGETTER(Location)(location.asOutParam());
|
---|
951 | RTPrintf("Name: %ls\n\n", location.raw());
|
---|
952 | }
|
---|
953 | }
|
---|
954 | break;
|
---|
955 | }
|
---|
956 |
|
---|
957 | case kListBridgedInterfaces:
|
---|
958 | #if defined(VBOX_WITH_NETFLT)
|
---|
959 | case kListHostOnlyInterfaces:
|
---|
960 | #endif
|
---|
961 | rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
|
---|
962 | break;
|
---|
963 |
|
---|
964 | case kListHostInfo:
|
---|
965 | rc = listHostInfo(pVirtualBox);
|
---|
966 | break;
|
---|
967 |
|
---|
968 | case kListHostCpuIDs:
|
---|
969 | {
|
---|
970 | ComPtr<IHost> Host;
|
---|
971 | CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
|
---|
972 |
|
---|
973 | RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
|
---|
974 | ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
|
---|
975 | static uint32_t const s_auCpuIdRanges[] =
|
---|
976 | {
|
---|
977 | UINT32_C(0x00000000), UINT32_C(0x0000007f),
|
---|
978 | UINT32_C(0x80000000), UINT32_C(0x8000007f),
|
---|
979 | UINT32_C(0xc0000000), UINT32_C(0xc000007f)
|
---|
980 | };
|
---|
981 | for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
|
---|
982 | {
|
---|
983 | ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
|
---|
984 | CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
|
---|
985 | if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
|
---|
986 | continue;
|
---|
987 | cLeafs++;
|
---|
988 | for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
|
---|
989 | {
|
---|
990 | CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
|
---|
991 | RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
|
---|
992 | }
|
---|
993 | }
|
---|
994 | break;
|
---|
995 | }
|
---|
996 |
|
---|
997 | case kListHddBackends:
|
---|
998 | rc = listHddBackends(pVirtualBox);
|
---|
999 | break;
|
---|
1000 |
|
---|
1001 | case kListHdds:
|
---|
1002 | {
|
---|
1003 | com::SafeIfaceArray<IMedium> hdds;
|
---|
1004 | CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
|
---|
1005 | rc = listMedia(pVirtualBox, hdds, "base");
|
---|
1006 | break;
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | case kListDvds:
|
---|
1010 | {
|
---|
1011 | com::SafeIfaceArray<IMedium> dvds;
|
---|
1012 | CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
|
---|
1013 | rc = listMedia(pVirtualBox, dvds, NULL);
|
---|
1014 | break;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | case kListFloppies:
|
---|
1018 | {
|
---|
1019 | com::SafeIfaceArray<IMedium> floppies;
|
---|
1020 | CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
|
---|
1021 | rc = listMedia(pVirtualBox, floppies, NULL);
|
---|
1022 | break;
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | case kListUsbHost:
|
---|
1026 | rc = listUsbHost(pVirtualBox);
|
---|
1027 | break;
|
---|
1028 |
|
---|
1029 | case kListUsbFilters:
|
---|
1030 | rc = listUsbFilters(pVirtualBox);
|
---|
1031 | break;
|
---|
1032 |
|
---|
1033 | case kListSystemProperties:
|
---|
1034 | rc = listSystemProperties(pVirtualBox);
|
---|
1035 | break;
|
---|
1036 |
|
---|
1037 | case kListDhcpServers:
|
---|
1038 | {
|
---|
1039 | com::SafeIfaceArray<IDHCPServer> svrs;
|
---|
1040 | CHECK_ERROR(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
|
---|
1041 | for (size_t i = 0; i < svrs.size(); ++i)
|
---|
1042 | {
|
---|
1043 | ComPtr<IDHCPServer> svr = svrs[i];
|
---|
1044 | Bstr netName;
|
---|
1045 | svr->COMGETTER(NetworkName)(netName.asOutParam());
|
---|
1046 | RTPrintf("NetworkName: %ls\n", netName.raw());
|
---|
1047 | Bstr ip;
|
---|
1048 | svr->COMGETTER(IPAddress)(ip.asOutParam());
|
---|
1049 | RTPrintf("IP: %ls\n", ip.raw());
|
---|
1050 | Bstr netmask;
|
---|
1051 | svr->COMGETTER(NetworkMask)(netmask.asOutParam());
|
---|
1052 | RTPrintf("NetworkMask: %ls\n", netmask.raw());
|
---|
1053 | Bstr lowerIp;
|
---|
1054 | svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
|
---|
1055 | RTPrintf("lowerIPAddress: %ls\n", lowerIp.raw());
|
---|
1056 | Bstr upperIp;
|
---|
1057 | svr->COMGETTER(UpperIP)(upperIp.asOutParam());
|
---|
1058 | RTPrintf("upperIPAddress: %ls\n", upperIp.raw());
|
---|
1059 | BOOL fEnabled;
|
---|
1060 | svr->COMGETTER(Enabled)(&fEnabled);
|
---|
1061 | RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
|
---|
1062 | RTPrintf("\n");
|
---|
1063 | }
|
---|
1064 | break;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | case kListExtPacks:
|
---|
1068 | rc = listExtensionPacks(pVirtualBox);
|
---|
1069 | break;
|
---|
1070 |
|
---|
1071 | case kListGroups:
|
---|
1072 | rc = listGroups(pVirtualBox);
|
---|
1073 | break;
|
---|
1074 |
|
---|
1075 | /* No default here, want gcc warnings. */
|
---|
1076 |
|
---|
1077 | } /* end switch */
|
---|
1078 |
|
---|
1079 | return rc;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | /**
|
---|
1083 | * Handles the 'list' command.
|
---|
1084 | *
|
---|
1085 | * @returns Appropriate exit code.
|
---|
1086 | * @param a Handler argument.
|
---|
1087 | */
|
---|
1088 | int handleList(HandlerArg *a)
|
---|
1089 | {
|
---|
1090 | bool fOptLong = false;
|
---|
1091 | bool fOptMultiple = false;
|
---|
1092 | enum enmListType enmOptCommand = kListNotSpecified;
|
---|
1093 |
|
---|
1094 | static const RTGETOPTDEF s_aListOptions[] =
|
---|
1095 | {
|
---|
1096 | { "--long", 'l', RTGETOPT_REQ_NOTHING },
|
---|
1097 | { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
|
---|
1098 | { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
|
---|
1099 | { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
|
---|
1100 | { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
|
---|
1101 | { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
|
---|
1102 | { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
|
---|
1103 | { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
|
---|
1104 | { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
|
---|
1105 | #if defined(VBOX_WITH_NETFLT)
|
---|
1106 | { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
|
---|
1107 | #endif
|
---|
1108 | { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
|
---|
1109 | { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
|
---|
1110 | { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
|
---|
1111 | { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
|
---|
1112 | { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
|
---|
1113 | { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
|
---|
1114 | { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
|
---|
1115 | { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
|
---|
1116 | { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
|
---|
1117 | { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
|
---|
1118 | { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
|
---|
1119 | { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
|
---|
1120 | };
|
---|
1121 |
|
---|
1122 | int ch;
|
---|
1123 | RTGETOPTUNION ValueUnion;
|
---|
1124 | RTGETOPTSTATE GetState;
|
---|
1125 | RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
|
---|
1126 | 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
|
---|
1127 | while ((ch = RTGetOpt(&GetState, &ValueUnion)))
|
---|
1128 | {
|
---|
1129 | switch (ch)
|
---|
1130 | {
|
---|
1131 | case 'l': /* --long */
|
---|
1132 | fOptLong = true;
|
---|
1133 | break;
|
---|
1134 |
|
---|
1135 | case 'm':
|
---|
1136 | fOptMultiple = true;
|
---|
1137 | if (enmOptCommand == kListNotSpecified)
|
---|
1138 | break;
|
---|
1139 | ch = enmOptCommand;
|
---|
1140 | /* fall thru */
|
---|
1141 |
|
---|
1142 | case kListVMs:
|
---|
1143 | case kListRunningVMs:
|
---|
1144 | case kListOsTypes:
|
---|
1145 | case kListHostDvds:
|
---|
1146 | case kListHostFloppies:
|
---|
1147 | case kListBridgedInterfaces:
|
---|
1148 | #if defined(VBOX_WITH_NETFLT)
|
---|
1149 | case kListHostOnlyInterfaces:
|
---|
1150 | #endif
|
---|
1151 | case kListHostInfo:
|
---|
1152 | case kListHostCpuIDs:
|
---|
1153 | case kListHddBackends:
|
---|
1154 | case kListHdds:
|
---|
1155 | case kListDvds:
|
---|
1156 | case kListFloppies:
|
---|
1157 | case kListUsbHost:
|
---|
1158 | case kListUsbFilters:
|
---|
1159 | case kListSystemProperties:
|
---|
1160 | case kListDhcpServers:
|
---|
1161 | case kListExtPacks:
|
---|
1162 | case kListGroups:
|
---|
1163 | enmOptCommand = (enum enmListType)ch;
|
---|
1164 | if (fOptMultiple)
|
---|
1165 | {
|
---|
1166 | HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
|
---|
1167 | if (FAILED(hrc))
|
---|
1168 | return 1;
|
---|
1169 | }
|
---|
1170 | break;
|
---|
1171 |
|
---|
1172 | case VINF_GETOPT_NOT_OPTION:
|
---|
1173 | return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
|
---|
1174 |
|
---|
1175 | default:
|
---|
1176 | return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | /*
|
---|
1181 | * If not in multiple list mode, we have to produce the list now.
|
---|
1182 | */
|
---|
1183 | if (enmOptCommand == kListNotSpecified)
|
---|
1184 | return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
|
---|
1185 | if (!fOptMultiple)
|
---|
1186 | {
|
---|
1187 | HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
|
---|
1188 | if (FAILED(hrc))
|
---|
1189 | return 1;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | return 0;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | #endif /* !VBOX_ONLY_DOCS */
|
---|
1196 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|