VirtualBox

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

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

Frontends/VBoxManage: make "list hdds" show full state information and dump all children as well.

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