VirtualBox

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

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

Main: NAT API and corresponding commands have been added at VBoxManage frontend. Please see #1899 for details.

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