VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp@ 29288

Last change on this file since 29288 was 28888, checked in by vboxsync, 15 years ago

Main/Medium: new stub medium type "Shareable", plus assorted frontend changes to prepare its use.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.5 KB
Line 
1/* $Id: VBoxManageList.cpp 28888 2010-04-29 11:50:05Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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"
40using namespace com;
41
42#ifdef VBOX_WITH_HOSTNETIF_API
43static 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
54static 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
64
65static void listHardDisks(const ComPtr<IVirtualBox> aVirtualBox,
66 const com::SafeIfaceArray<IMedium> &aMedia,
67 const char *pszParentUUIDStr)
68{
69 HRESULT rc;
70 for (size_t i = 0; i < aMedia.size(); ++i)
71 {
72 ComPtr<IMedium> hdd = aMedia[i];
73 Bstr uuid;
74 hdd->COMGETTER(Id)(uuid.asOutParam());
75 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
76 RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
77 Bstr format;
78 hdd->COMGETTER(Format)(format.asOutParam());
79 RTPrintf("Format: %lS\n", format.raw());
80 Bstr filepath;
81 hdd->COMGETTER(Location)(filepath.asOutParam());
82 RTPrintf("Location: %lS\n", filepath.raw());
83
84 MediumState_T enmState;
85 hdd->RefreshState(&enmState);
86 const char *stateStr = "unknown";
87 switch (enmState)
88 {
89 case MediumState_NotCreated:
90 stateStr = "not created";
91 break;
92 case MediumState_Created:
93 stateStr = "created";
94 break;
95 case MediumState_LockedRead:
96 stateStr = "locked read";
97 break;
98 case MediumState_LockedWrite:
99 stateStr = "locked write";
100 break;
101 case MediumState_Inaccessible:
102 stateStr = "inaccessible";
103 break;
104 case MediumState_Creating:
105 stateStr = "creating";
106 break;
107 case MediumState_Deleting:
108 stateStr = "deleting";
109 break;
110 }
111 RTPrintf("State: %s\n", stateStr);
112
113 MediumType_T type;
114 hdd->COMGETTER(Type)(&type);
115 const char *typeStr = "unknown";
116 switch (type)
117 {
118 case MediumType_Normal:
119 typeStr = "normal";
120 break;
121 case MediumType_Immutable:
122 typeStr = "immutable";
123 break;
124 case MediumType_Writethrough:
125 typeStr = "writethrough";
126 break;
127 case MediumType_Shareable:
128 typeStr = "shareable";
129 break;
130 }
131 RTPrintf("Type: %s\n", typeStr);
132
133 com::SafeArray<BSTR> machineIds;
134 hdd->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
135 for (size_t j = 0; j < machineIds.size(); ++j)
136 {
137 ComPtr<IMachine> machine;
138 CHECK_ERROR(aVirtualBox, GetMachine(machineIds[j], machine.asOutParam()));
139 ASSERT(machine);
140 Bstr name;
141 machine->COMGETTER(Name)(name.asOutParam());
142 RTPrintf("%s%lS (UUID: %lS)",
143 j == 0 ? "Usage: " : " ",
144 name.raw(), machineIds[j]);
145 com::SafeArray<BSTR> snapshotIds;
146 hdd->GetSnapshotIds(machineIds[j],
147 ComSafeArrayAsOutParam(snapshotIds));
148 for (size_t k = 0; k < snapshotIds.size(); ++k)
149 {
150 ComPtr<ISnapshot> snapshot;
151 machine->GetSnapshot(snapshotIds[k], snapshot.asOutParam());
152 if (snapshot)
153 {
154 Bstr snapshotName;
155 snapshot->COMGETTER(Name)(snapshotName.asOutParam());
156 RTPrintf(" [%lS (UUID: %lS)]", snapshotName.raw(), snapshotIds[k]);
157 }
158 }
159 RTPrintf("\n");
160 }
161 RTPrintf("\n");
162
163 com::SafeIfaceArray<IMedium> children;
164 CHECK_ERROR(hdd, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
165 if (children.size() > 0)
166 {
167 // depth first listing of child media
168 listHardDisks(aVirtualBox, children, Utf8Str(uuid).raw());
169 }
170 }
171}
172
173enum enOptionCodes
174{
175 LISTVMS = 1000,
176 LISTRUNNINGVMS,
177 LISTOSTYPES,
178 LISTHOSTDVDS,
179 LISTHOSTFLOPPIES,
180 LISTBRIDGEDIFS,
181#if defined(VBOX_WITH_NETFLT)
182 LISTHOSTONLYIFS,
183#endif
184 LISTHOSTCPUIDS,
185 LISTHOSTINFO,
186 LISTHDDBACKENDS,
187 LISTHDDS,
188 LISTDVDS,
189 LISTFLOPPIES,
190 LISTUSBHOST,
191 LISTUSBFILTERS,
192 LISTSYSTEMPROPERTIES,
193 LISTDHCPSERVERS
194};
195
196static const RTGETOPTDEF g_aListOptions[]
197 = {
198 { "--long", 'l', RTGETOPT_REQ_NOTHING },
199 { "vms", LISTVMS, RTGETOPT_REQ_NOTHING },
200 { "runningvms", LISTRUNNINGVMS, RTGETOPT_REQ_NOTHING },
201 { "ostypes", LISTOSTYPES, RTGETOPT_REQ_NOTHING },
202 { "hostdvds", LISTHOSTDVDS, RTGETOPT_REQ_NOTHING },
203 { "hostfloppies", LISTHOSTFLOPPIES, RTGETOPT_REQ_NOTHING },
204 { "hostifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
205 { "bridgedifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING },
206#if defined(VBOX_WITH_NETFLT)
207 { "hostonlyifs", LISTHOSTONLYIFS, RTGETOPT_REQ_NOTHING },
208#endif
209 { "hostinfo", LISTHOSTINFO, RTGETOPT_REQ_NOTHING },
210 { "hostcpuids", LISTHOSTCPUIDS, RTGETOPT_REQ_NOTHING },
211 { "hddbackends", LISTHDDBACKENDS, RTGETOPT_REQ_NOTHING },
212 { "hdds", LISTHDDS, RTGETOPT_REQ_NOTHING },
213 { "dvds", LISTDVDS, RTGETOPT_REQ_NOTHING },
214 { "floppies", LISTFLOPPIES, RTGETOPT_REQ_NOTHING },
215 { "usbhost", LISTUSBHOST, RTGETOPT_REQ_NOTHING },
216 { "usbfilters", LISTUSBFILTERS, RTGETOPT_REQ_NOTHING },
217 { "systemproperties", LISTSYSTEMPROPERTIES, RTGETOPT_REQ_NOTHING },
218 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING },
219 };
220
221int handleList(HandlerArg *a)
222{
223 HRESULT rc = S_OK;
224
225 bool fOptLong = false;
226
227 int command = 0;
228 int c;
229
230 RTGETOPTUNION ValueUnion;
231 RTGETOPTSTATE GetState;
232 RTGetOptInit(&GetState, a->argc, a->argv, g_aListOptions, RT_ELEMENTS(g_aListOptions),
233 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
234 while ((c = RTGetOpt(&GetState, &ValueUnion)))
235 {
236 switch (c)
237 {
238 case 'l': // --long
239 fOptLong = true;
240 break;
241
242 case LISTVMS:
243 case LISTRUNNINGVMS:
244 case LISTOSTYPES:
245 case LISTHOSTDVDS:
246 case LISTHOSTFLOPPIES:
247 case LISTBRIDGEDIFS:
248#if defined(VBOX_WITH_NETFLT)
249 case LISTHOSTONLYIFS:
250#endif
251 case LISTHOSTINFO:
252 case LISTHOSTCPUIDS:
253 case LISTHDDBACKENDS:
254 case LISTHDDS:
255 case LISTDVDS:
256 case LISTFLOPPIES:
257 case LISTUSBHOST:
258 case LISTUSBFILTERS:
259 case LISTSYSTEMPROPERTIES:
260 case LISTDHCPSERVERS:
261 if (command)
262 return errorSyntax(USAGE_LIST, "Too many subcommands for \"list\" command.\n");
263
264 command = c;
265 break;
266
267 case VINF_GETOPT_NOT_OPTION:
268 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
269 break;
270
271 default:
272 if (c > 0)
273 {
274 if (RT_C_IS_GRAPH(c))
275 return errorSyntax(USAGE_LIST, "unhandled option: -%c", c);
276 else
277 return errorSyntax(USAGE_LIST, "unhandled option: %i", c);
278 }
279 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
280 return errorSyntax(USAGE_LIST, "unknown option: %s", ValueUnion.psz);
281 else if (ValueUnion.pDef)
282 return errorSyntax(USAGE_LIST, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
283 else
284 return errorSyntax(USAGE_LIST, "%Rrs", c);
285 }
286 }
287
288 if (!command)
289 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
290
291 /* which object? */
292 switch (command)
293 {
294 case LISTVMS:
295 {
296 /*
297 * Get the list of all registered VMs
298 */
299 com::SafeIfaceArray <IMachine> machines;
300 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
301 if (SUCCEEDED(rc))
302 {
303 /*
304 * Iterate through the collection
305 */
306 for (size_t i = 0; i < machines.size(); ++i)
307 {
308 if (machines[i])
309 rc = showVMInfo(a->virtualBox,
310 machines[i],
311 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
312 }
313 }
314 }
315 break;
316
317 case LISTRUNNINGVMS:
318 {
319 /*
320 * Get the list of all _running_ VMs
321 */
322 com::SafeIfaceArray <IMachine> machines;
323 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
324 if (SUCCEEDED(rc))
325 {
326 /*
327 * Iterate through the collection
328 */
329 for (size_t i = 0; i < machines.size(); ++i)
330 {
331 if (machines[i])
332 {
333 MachineState_T machineState;
334 rc = machines[i]->COMGETTER(State)(&machineState);
335 if (SUCCEEDED(rc))
336 {
337 switch (machineState)
338 {
339 case MachineState_Running:
340 case MachineState_Teleporting:
341 case MachineState_LiveSnapshotting:
342 case MachineState_Paused:
343 case MachineState_TeleportingPausedVM:
344 rc = showVMInfo(a->virtualBox,
345 machines[i],
346 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
347 }
348 }
349 }
350 }
351 }
352 }
353 break;
354
355 case LISTOSTYPES:
356 {
357 com::SafeIfaceArray <IGuestOSType> coll;
358 rc = a->virtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
359 if (SUCCEEDED(rc))
360 {
361 /*
362 * Iterate through the collection.
363 */
364 for (size_t i = 0; i < coll.size(); ++i)
365 {
366 ComPtr<IGuestOSType> guestOS;
367 guestOS = coll[i];
368 Bstr guestId;
369 guestOS->COMGETTER(Id)(guestId.asOutParam());
370 RTPrintf("ID: %lS\n", guestId.raw());
371 Bstr guestDescription;
372 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
373 RTPrintf("Description: %lS\n\n", guestDescription.raw());
374 }
375 }
376 }
377 break;
378
379 case LISTHOSTDVDS:
380 {
381 ComPtr<IHost> host;
382 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
383 com::SafeIfaceArray <IMedium> coll;
384 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
385 if (SUCCEEDED(rc))
386 {
387 for (size_t i = 0; i < coll.size(); ++i)
388 {
389 ComPtr<IMedium> dvdDrive = coll[i];
390 Bstr uuid;
391 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
392 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
393 Bstr name;
394 dvdDrive->COMGETTER(Name)(name.asOutParam());
395 RTPrintf("Name: %lS\n\n", name.raw());
396 }
397 }
398 }
399 break;
400
401 case LISTHOSTFLOPPIES:
402 {
403 ComPtr<IHost> host;
404 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
405 com::SafeIfaceArray <IMedium> coll;
406 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
407 if (SUCCEEDED(rc))
408 {
409 for (size_t i = 0; i < coll.size(); ++i)
410 {
411 ComPtr<IMedium> floppyDrive = coll[i];
412 Bstr uuid;
413 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
414 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
415 Bstr name;
416 floppyDrive->COMGETTER(Name)(name.asOutParam());
417 RTPrintf("Name: %lS\n\n", name.raw());
418 }
419 }
420 }
421 break;
422
423 case LISTBRIDGEDIFS:
424#if defined(VBOX_WITH_NETFLT)
425 case LISTHOSTONLYIFS:
426#endif
427 {
428 ComPtr<IHost> host;
429 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
430 com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
431#if defined(VBOX_WITH_NETFLT)
432 if (command == LISTBRIDGEDIFS)
433 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
434 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
435 else
436 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
437 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
438#else
439 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
440#endif
441 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
442 {
443 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
444#ifndef VBOX_WITH_HOSTNETIF_API
445 Bstr interfaceName;
446 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
447 RTPrintf("Name: %lS\n", interfaceName.raw());
448 Guid interfaceGuid;
449 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
450 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
451#else /* VBOX_WITH_HOSTNETIF_API */
452 Bstr interfaceName;
453 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
454 RTPrintf("Name: %lS\n", interfaceName.raw());
455 Bstr interfaceGuid;
456 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
457 RTPrintf("GUID: %lS\n", interfaceGuid.raw());
458 BOOL bDhcpEnabled;
459 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
460 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
461
462 Bstr IPAddress;
463 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
464 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
465 Bstr NetworkMask;
466 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
467 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
468 Bstr IPV6Address;
469 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
470 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
471 ULONG IPV6NetworkMaskPrefixLength;
472 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
473 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
474 Bstr HardwareAddress;
475 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
476 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
477 HostNetworkInterfaceMediumType_T Type;
478 networkInterface->COMGETTER(MediumType)(&Type);
479 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
480 HostNetworkInterfaceStatus_T Status;
481 networkInterface->COMGETTER(Status)(&Status);
482 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
483 Bstr netName;
484 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
485 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
486
487#endif
488 }
489 }
490 break;
491
492 case LISTHOSTINFO:
493 {
494 ComPtr<IHost> Host;
495 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
496
497 RTPrintf("Host Information:\n\n");
498
499 LONG64 uTCTime = 0;
500 CHECK_ERROR(Host, COMGETTER(UTCTime)(&uTCTime));
501 RTTIMESPEC timeSpec;
502 RTTimeSpecSetMilli(&timeSpec, uTCTime);
503 char szTime[32] = {0};
504 RTTimeSpecToString(&timeSpec, szTime, sizeof(szTime));
505 RTPrintf("Host time: %s\n", szTime);
506
507 ULONG processorOnlineCount = 0;
508 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
509 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
510 ULONG processorCount = 0;
511 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
512 RTPrintf("Processor count: %lu\n", processorCount);
513 ULONG processorSpeed = 0;
514 Bstr processorDescription;
515 for (ULONG i = 0; i < processorCount; i++)
516 {
517 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
518 if (processorSpeed)
519 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
520 else
521 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
522 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
523 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
524 }
525
526 ULONG memorySize = 0;
527 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
528 RTPrintf("Memory size: %lu MByte\n", memorySize);
529
530 ULONG memoryAvailable = 0;
531 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
532 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
533
534 Bstr operatingSystem;
535 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
536 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
537
538 Bstr oSVersion;
539 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
540 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
541 }
542 break;
543
544 case LISTHOSTCPUIDS:
545 {
546 ComPtr<IHost> Host;
547 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
548
549 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
550 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
551 static uint32_t const s_auCpuIdRanges[] =
552 {
553 UINT32_C(0x00000000), UINT32_C(0x0000007f),
554 UINT32_C(0x80000000), UINT32_C(0x8000007f),
555 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
556 };
557 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
558 {
559 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
560 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
561 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
562 continue;
563 cLeafs++;
564 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
565 {
566 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
567 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
568 }
569 }
570 }
571 break;
572
573 case LISTHDDBACKENDS:
574 {
575 ComPtr<ISystemProperties> systemProperties;
576 CHECK_ERROR(a->virtualBox,
577 COMGETTER(SystemProperties)(systemProperties.asOutParam()));
578 com::SafeIfaceArray <IMediumFormat> mediumFormats;
579 CHECK_ERROR(systemProperties,
580 COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
581
582 RTPrintf("Supported hard disk backends:\n\n");
583 for (size_t i = 0; i < mediumFormats.size(); ++i)
584 {
585 /* General information */
586 Bstr id;
587 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
588
589 Bstr description;
590 CHECK_ERROR(mediumFormats[i],
591 COMGETTER(Id)(description.asOutParam()));
592
593 ULONG caps;
594 CHECK_ERROR(mediumFormats[i],
595 COMGETTER(Capabilities)(&caps));
596
597 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
598 i, id.raw(), description.raw(), caps);
599
600 /* File extensions */
601 com::SafeArray <BSTR> fileExtensions;
602 CHECK_ERROR(mediumFormats[i],
603 COMGETTER(FileExtensions)(ComSafeArrayAsOutParam(fileExtensions)));
604 for (size_t j = 0; j < fileExtensions.size(); ++j)
605 {
606 RTPrintf("%ls", Bstr(fileExtensions[j]).raw());
607 if (j != fileExtensions.size()-1)
608 RTPrintf(",");
609 }
610 RTPrintf("'");
611
612 /* Configuration keys */
613 com::SafeArray <BSTR> propertyNames;
614 com::SafeArray <BSTR> propertyDescriptions;
615 com::SafeArray <DataType_T> propertyTypes;
616 com::SafeArray <ULONG> propertyFlags;
617 com::SafeArray <BSTR> propertyDefaults;
618 CHECK_ERROR(mediumFormats[i],
619 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
620 ComSafeArrayAsOutParam(propertyDescriptions),
621 ComSafeArrayAsOutParam(propertyTypes),
622 ComSafeArrayAsOutParam(propertyFlags),
623 ComSafeArrayAsOutParam(propertyDefaults)));
624
625 RTPrintf(" properties=(");
626 if (propertyNames.size() > 0)
627 {
628 for (size_t j = 0; j < propertyNames.size(); ++j)
629 {
630 RTPrintf("\n name='%ls' desc='%ls' type=",
631 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
632 switch (propertyTypes[j])
633 {
634 case DataType_Int32: RTPrintf("int"); break;
635 case DataType_Int8: RTPrintf("byte"); break;
636 case DataType_String: RTPrintf("string"); break;
637 }
638 RTPrintf(" flags=%#04x", propertyFlags[j]);
639 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
640 if (j != propertyNames.size()-1)
641 RTPrintf(", ");
642 }
643 }
644 RTPrintf(")\n");
645 }
646 }
647 break;
648
649 case LISTHDDS:
650 {
651 com::SafeIfaceArray<IMedium> hdds;
652 CHECK_ERROR(a->virtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
653 listHardDisks(a->virtualBox, hdds, "base");
654 }
655 break;
656
657 case LISTDVDS:
658 {
659 com::SafeIfaceArray<IMedium> dvds;
660 CHECK_ERROR(a->virtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
661 for (size_t i = 0; i < dvds.size(); ++i)
662 {
663 ComPtr<IMedium> dvdImage = dvds[i];
664 Bstr uuid;
665 dvdImage->COMGETTER(Id)(uuid.asOutParam());
666 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
667 Bstr filePath;
668 dvdImage->COMGETTER(Location)(filePath.asOutParam());
669 RTPrintf("Path: %lS\n", filePath.raw());
670 MediumState_T enmState;
671 dvdImage->RefreshState(&enmState);
672 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
673
674 com::SafeArray<BSTR> machineIds;
675 dvdImage->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
676 for (size_t j = 0; j < machineIds.size(); ++j)
677 {
678 ComPtr<IMachine> machine;
679 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
680 ASSERT(machine);
681 Bstr name;
682 machine->COMGETTER(Name)(name.asOutParam());
683 machine->COMGETTER(Id)(uuid.asOutParam());
684 RTPrintf("%s%lS (UUID: %lS)\n",
685 j == 0 ? "Usage: " : " ",
686 name.raw(), machineIds[j]);
687 }
688 RTPrintf("\n");
689 }
690 }
691 break;
692
693 case LISTFLOPPIES:
694 {
695 com::SafeIfaceArray<IMedium> floppies;
696 CHECK_ERROR(a->virtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
697 for (size_t i = 0; i < floppies.size(); ++i)
698 {
699 ComPtr<IMedium> floppyImage = floppies[i];
700 Bstr uuid;
701 floppyImage->COMGETTER(Id)(uuid.asOutParam());
702 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
703 Bstr filePath;
704 floppyImage->COMGETTER(Location)(filePath.asOutParam());
705 RTPrintf("Path: %lS\n", filePath.raw());
706 MediumState_T enmState;
707 floppyImage->RefreshState(&enmState);
708 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
709
710 com::SafeArray<BSTR> machineIds;
711 floppyImage->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
712 for (size_t j = 0; j < machineIds.size(); ++j)
713 {
714 ComPtr<IMachine> machine;
715 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
716 ASSERT(machine);
717 Bstr name;
718 machine->COMGETTER(Name)(name.asOutParam());
719 machine->COMGETTER(Id)(uuid.asOutParam());
720 RTPrintf("%s%lS (UUID: %lS)\n",
721 j == 0 ? "Usage: " : " ",
722 name.raw(), machineIds[j]);
723 }
724 RTPrintf("\n");
725 }
726 }
727 break;
728
729 case LISTUSBHOST:
730 {
731 ComPtr<IHost> Host;
732 CHECK_ERROR_RET(a->virtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
733
734 SafeIfaceArray <IHostUSBDevice> CollPtr;
735 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
736
737 RTPrintf("Host USB Devices:\n\n");
738
739 if (CollPtr.size() == 0)
740 {
741 RTPrintf("<none>\n\n");
742 }
743 else
744 {
745 for (size_t i = 0; i < CollPtr.size(); ++i)
746 {
747 ComPtr <IHostUSBDevice> dev = CollPtr[i];
748
749 /* Query info. */
750 Bstr id;
751 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
752 USHORT usVendorId;
753 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
754 USHORT usProductId;
755 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
756 USHORT bcdRevision;
757 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
758
759 RTPrintf("UUID: %S\n"
760 "VendorId: 0x%04x (%04X)\n"
761 "ProductId: 0x%04x (%04X)\n"
762 "Revision: %u.%u (%02u%02u)\n",
763 Utf8Str(id).raw(),
764 usVendorId, usVendorId, usProductId, usProductId,
765 bcdRevision >> 8, bcdRevision & 0xff,
766 bcdRevision >> 8, bcdRevision & 0xff);
767
768 /* optional stuff. */
769 Bstr bstr;
770 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
771 if (!bstr.isEmpty())
772 RTPrintf("Manufacturer: %lS\n", bstr.raw());
773 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
774 if (!bstr.isEmpty())
775 RTPrintf("Product: %lS\n", bstr.raw());
776 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
777 if (!bstr.isEmpty())
778 RTPrintf("SerialNumber: %lS\n", bstr.raw());
779 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
780 if (!bstr.isEmpty())
781 RTPrintf("Address: %lS\n", bstr.raw());
782
783 /* current state */
784 USBDeviceState_T state;
785 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
786 const char *pszState = "?";
787 switch (state)
788 {
789 case USBDeviceState_NotSupported:
790 pszState = "Not supported"; break;
791 case USBDeviceState_Unavailable:
792 pszState = "Unavailable"; break;
793 case USBDeviceState_Busy:
794 pszState = "Busy"; break;
795 case USBDeviceState_Available:
796 pszState = "Available"; break;
797 case USBDeviceState_Held:
798 pszState = "Held"; break;
799 case USBDeviceState_Captured:
800 pszState = "Captured"; break;
801 default:
802 ASSERT(false);
803 break;
804 }
805 RTPrintf("Current State: %s\n\n", pszState);
806 }
807 }
808 }
809 break;
810
811 case LISTUSBFILTERS:
812 {
813 RTPrintf("Global USB Device Filters:\n\n");
814
815 ComPtr <IHost> host;
816 CHECK_ERROR_RET(a->virtualBox, COMGETTER(Host)(host.asOutParam()), 1);
817
818 SafeIfaceArray <IHostUSBDeviceFilter> coll;
819 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
820
821 if (coll.size() == 0)
822 {
823 RTPrintf("<none>\n\n");
824 }
825 else
826 {
827 for (size_t index = 0; index < coll.size(); ++index)
828 {
829 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
830
831 /* Query info. */
832
833 RTPrintf("Index: %zu\n", index);
834
835 BOOL active = FALSE;
836 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
837 RTPrintf("Active: %s\n", active ? "yes" : "no");
838
839 USBDeviceFilterAction_T action;
840 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
841 const char *pszAction = "<invalid>";
842 switch (action)
843 {
844 case USBDeviceFilterAction_Ignore:
845 pszAction = "Ignore";
846 break;
847 case USBDeviceFilterAction_Hold:
848 pszAction = "Hold";
849 break;
850 default:
851 break;
852 }
853 RTPrintf("Action: %s\n", pszAction);
854
855 Bstr bstr;
856 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
857 RTPrintf("Name: %lS\n", bstr.raw());
858 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
859 RTPrintf("VendorId: %lS\n", bstr.raw());
860 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
861 RTPrintf("ProductId: %lS\n", bstr.raw());
862 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
863 RTPrintf("Revision: %lS\n", bstr.raw());
864 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
865 RTPrintf("Manufacturer: %lS\n", bstr.raw());
866 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
867 RTPrintf("Product: %lS\n", bstr.raw());
868 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
869 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
870 }
871 }
872 }
873 break;
874
875 case LISTSYSTEMPROPERTIES:
876 {
877 ComPtr<ISystemProperties> systemProperties;
878 a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
879
880 Bstr str;
881 ULONG ulValue;
882 ULONG64 ul64Value;
883
884 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
885 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
886 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
887 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
888 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
889 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
890 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
891 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
892 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
893 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
894 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
895 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
896 systemProperties->COMGETTER(MaxVDISize)(&ul64Value);
897 RTPrintf("Maximum VDI size: %lu Megabytes\n", ul64Value);
898 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
899 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
900 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
901 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
902 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
903 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
904 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
905 RTPrintf("Maximum Boot Position: %u\n", ulValue);
906 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_IDE, &ulValue);
907 RTPrintf("Maximum IDE Controllers: %u\n", ulValue);
908 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
909 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
910 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
911 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
912 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SATA, &ulValue);
913 RTPrintf("Maximum SATA Controllers: %u\n", ulValue);
914 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
915 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
916 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
917 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
918 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SCSI, &ulValue);
919 RTPrintf("Maximum SCSI Controllers: %u\n", ulValue);
920 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
921 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
922 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
923 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
924 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SAS, &ulValue);
925 RTPrintf("Maximum SAS Controllers: %u\n", ulValue);
926 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
927 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
928 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
929 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
930 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_Floppy, &ulValue);
931 RTPrintf("Maximum Floppy Controllers: %u\n", ulValue);
932 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
933 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
934 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
935 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
936 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
937 RTPrintf("Default machine folder: %lS\n", str.raw());
938 systemProperties->COMGETTER(DefaultHardDiskFolder)(str.asOutParam());
939 RTPrintf("Default hard disk folder: %lS\n", str.raw());
940 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(str.asOutParam());
941 RTPrintf("VRDP authentication library: %lS\n", str.raw());
942 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
943 RTPrintf("Webservice auth. library: %lS\n", str.raw());
944 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
945 RTPrintf("Log history count: %u\n", ulValue);
946
947 }
948 break;
949 case LISTDHCPSERVERS:
950 {
951 com::SafeIfaceArray<IDHCPServer> svrs;
952 CHECK_ERROR(a->virtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
953 for (size_t i = 0; i < svrs.size(); ++i)
954 {
955 ComPtr<IDHCPServer> svr = svrs[i];
956 Bstr netName;
957 svr->COMGETTER(NetworkName)(netName.asOutParam());
958 RTPrintf("NetworkName: %lS\n", netName.raw());
959 Bstr ip;
960 svr->COMGETTER(IPAddress)(ip.asOutParam());
961 RTPrintf("IP: %lS\n", ip.raw());
962 Bstr netmask;
963 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
964 RTPrintf("NetworkMask: %lS\n", netmask.raw());
965 Bstr lowerIp;
966 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
967 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
968 Bstr upperIp;
969 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
970 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
971 BOOL bEnabled;
972 svr->COMGETTER(Enabled)(&bEnabled);
973 RTPrintf("Enabled: %s\n", bEnabled ? "Yes" : "No");
974 RTPrintf("\n");
975 }
976 }
977 break;
978 } // end switch
979
980 return SUCCEEDED(rc) ? 0 : 1;
981}
982
983#endif /* !VBOX_ONLY_DOCS */
984/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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