VirtualBox

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

Last change on this file since 28815 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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