VirtualBox

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

Last change on this file since 33766 was 33766, checked in by vboxsync, 14 years ago

VBoxManage: Implemented 'list extpacks', 'extpack install' and 'extpack uninstall'.

  • 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 33766 2010-11-04 14:05:28Z 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 /* VBOX_WITH_HOSTNETIF_API */
64
65static const char*getDeviceTypeText(DeviceType_T enmType)
66{
67 switch (enmType)
68 {
69 case DeviceType_HardDisk: return "HardDisk";
70 case DeviceType_DVD: return "DVD";
71 case DeviceType_Floppy: return "Floppy";
72 }
73 return "Unknown";
74}
75
76static void listMedia(const ComPtr<IVirtualBox> aVirtualBox,
77 const com::SafeIfaceArray<IMedium> &aMedia,
78 const char *pszParentUUIDStr)
79{
80 HRESULT rc;
81 for (size_t i = 0; i < aMedia.size(); ++i)
82 {
83 ComPtr<IMedium> pMedium = aMedia[i];
84 Bstr uuid;
85 pMedium->COMGETTER(Id)(uuid.asOutParam());
86 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
87 if (pszParentUUIDStr)
88 RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
89 Bstr format;
90 pMedium->COMGETTER(Format)(format.asOutParam());
91 RTPrintf("Format: %lS\n", format.raw());
92 Bstr filepath;
93 pMedium->COMGETTER(Location)(filepath.asOutParam());
94 RTPrintf("Location: %lS\n", filepath.raw());
95
96 MediumState_T enmState;
97 pMedium->RefreshState(&enmState);
98 const char *stateStr = "unknown";
99 switch (enmState)
100 {
101 case MediumState_NotCreated:
102 stateStr = "not created";
103 break;
104 case MediumState_Created:
105 stateStr = "created";
106 break;
107 case MediumState_LockedRead:
108 stateStr = "locked read";
109 break;
110 case MediumState_LockedWrite:
111 stateStr = "locked write";
112 break;
113 case MediumState_Inaccessible:
114 stateStr = "inaccessible";
115 break;
116 case MediumState_Creating:
117 stateStr = "creating";
118 break;
119 case MediumState_Deleting:
120 stateStr = "deleting";
121 break;
122 }
123 RTPrintf("State: %s\n", stateStr);
124
125 MediumType_T type;
126 pMedium->COMGETTER(Type)(&type);
127 const char *typeStr = "unknown";
128 switch (type)
129 {
130 case MediumType_Normal:
131 typeStr = "normal";
132 break;
133 case MediumType_Immutable:
134 typeStr = "immutable";
135 break;
136 case MediumType_Writethrough:
137 typeStr = "writethrough";
138 break;
139 case MediumType_Shareable:
140 typeStr = "shareable";
141 break;
142 case MediumType_Readonly:
143 typeStr = "readonly";
144 break;
145 }
146 RTPrintf("Type: %s\n", typeStr);
147
148 com::SafeArray<BSTR> machineIds;
149 pMedium->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
150 for (size_t j = 0; j < machineIds.size(); ++j)
151 {
152 ComPtr<IMachine> machine;
153 CHECK_ERROR(aVirtualBox, FindMachine(machineIds[j], machine.asOutParam()));
154 ASSERT(machine);
155 Bstr name;
156 machine->COMGETTER(Name)(name.asOutParam());
157 RTPrintf("%s%lS (UUID: %lS)",
158 j == 0 ? "Usage: " : " ",
159 name.raw(), machineIds[j]);
160 com::SafeArray<BSTR> snapshotIds;
161 pMedium->GetSnapshotIds(machineIds[j],
162 ComSafeArrayAsOutParam(snapshotIds));
163 for (size_t k = 0; k < snapshotIds.size(); ++k)
164 {
165 ComPtr<ISnapshot> snapshot;
166 machine->FindSnapshot(snapshotIds[k], snapshot.asOutParam());
167 if (snapshot)
168 {
169 Bstr snapshotName;
170 snapshot->COMGETTER(Name)(snapshotName.asOutParam());
171 RTPrintf(" [%lS (UUID: %lS)]", snapshotName.raw(), snapshotIds[k]);
172 }
173 }
174 RTPrintf("\n");
175 }
176 RTPrintf("\n");
177
178 com::SafeIfaceArray<IMedium> children;
179 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
180 if (children.size() > 0)
181 {
182 // depth first listing of child media
183 listMedia(aVirtualBox, children, Utf8Str(uuid).c_str());
184 }
185 }
186}
187
188
189/**
190 * List extension packs.
191 *
192 * @returns See produceList.
193 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
194 */
195static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &rptrVirtualBox)
196{
197 ComObjPtr<IExtPackManager> ptrExtPackMgr;
198 CHECK_ERROR2_RET(rptrVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
199
200 SafeIfaceArray<IExtPack> extPacks;
201 CHECK_ERROR2_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
202 RTPrintf("Extension Packs: %u\n", extPacks.size());
203
204 HRESULT hrc = S_OK;
205 for (size_t i = 0; i < extPacks.size(); i++)
206 {
207 /* Read all the properties. */
208 Bstr bstrName;
209 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
210 Bstr bstrDesc;
211 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
212 Bstr bstrVersion;
213 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
214 ULONG uRevision;
215 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
216 BOOL fUsable;
217 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
218 Bstr bstrWhy;
219 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
220
221 /* Display them. */
222 if (i)
223 RTPrintf("\n");
224 RTPrintf("Pack no.%2zu: %lS\n"
225 "Version: %lS\n"
226 "Revision: %u\n"
227 "Description: %lS\n"
228 "Usable: %RTbool\n"
229 "Why unusable: %lS\n",
230 i, bstrName.raw(),
231 bstrVersion.raw(),
232 uRevision,
233 bstrDesc.raw(),
234 fUsable != FALSE,
235 bstrWhy.raw());
236 }
237 return hrc;
238}
239
240
241/**
242 * The type of lists we can produce.
243 */
244enum enmListType
245{
246 kListNotSpecified = 1000,
247 kListVMs,
248 kListRunningVMs,
249 kListOsTypes,
250 kListHostDvds,
251 kListHostFloppies,
252 kListBridgedInterfaces,
253#if defined(VBOX_WITH_NETFLT)
254 kListHostOnlyInterfaces,
255#endif
256 kListHostCpuIDs,
257 kListHostInfo,
258 kListHddBackends,
259 kListHdds,
260 kListDvds,
261 kListFloppies,
262 kListUsbHost,
263 kListUsbFilters,
264 kListSystemProperties,
265 kListDhcpServers,
266 kListVrdeLibraries,
267 kListExtPacks
268};
269
270
271/**
272 * Produces the specified listing.
273 *
274 * @returns S_OK or some COM error code that has been reported in full.
275 * @param enmList The list to produce.
276 * @param fOptLong Long (@c true) or short list format.
277 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
278 */
279static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &rptrVirtualBox)
280{
281 HRESULT rc = S_OK;
282 switch (enmCommand)
283 {
284 case kListNotSpecified:
285 AssertFailed();
286 return E_FAIL;
287
288 case kListVMs:
289 {
290 /*
291 * Get the list of all registered VMs
292 */
293 com::SafeIfaceArray<IMachine> machines;
294 rc = rptrVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
295 if (SUCCEEDED(rc))
296 {
297 /*
298 * Iterate through the collection
299 */
300 for (size_t i = 0; i < machines.size(); ++i)
301 {
302 if (machines[i])
303 rc = showVMInfo(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
304 }
305 }
306 break;
307 }
308
309 case kListRunningVMs:
310 {
311 /*
312 * Get the list of all _running_ VMs
313 */
314 com::SafeIfaceArray<IMachine> machines;
315 rc = rptrVirtualBox->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(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
337 break;
338 }
339 }
340 }
341 }
342 }
343 break;
344 }
345
346 case kListOsTypes:
347 {
348 com::SafeIfaceArray<IGuestOSType> coll;
349 rc = rptrVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
350 if (SUCCEEDED(rc))
351 {
352 /*
353 * Iterate through the collection.
354 */
355 for (size_t i = 0; i < coll.size(); ++i)
356 {
357 ComPtr<IGuestOSType> guestOS;
358 guestOS = coll[i];
359 Bstr guestId;
360 guestOS->COMGETTER(Id)(guestId.asOutParam());
361 RTPrintf("ID: %lS\n", guestId.raw());
362 Bstr guestDescription;
363 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
364 RTPrintf("Description: %lS\n\n", guestDescription.raw());
365 }
366 }
367 break;
368 }
369
370 case kListHostDvds:
371 {
372 ComPtr<IHost> host;
373 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
374 com::SafeIfaceArray<IMedium> coll;
375 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
376 if (SUCCEEDED(rc))
377 {
378 for (size_t i = 0; i < coll.size(); ++i)
379 {
380 ComPtr<IMedium> dvdDrive = coll[i];
381 Bstr uuid;
382 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
383 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
384 Bstr name;
385 dvdDrive->COMGETTER(Name)(name.asOutParam());
386 RTPrintf("Name: %lS\n\n", name.raw());
387 }
388 }
389 break;
390 }
391
392 case kListHostFloppies:
393 {
394 ComPtr<IHost> host;
395 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
396 com::SafeIfaceArray<IMedium> coll;
397 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
398 if (SUCCEEDED(rc))
399 {
400 for (size_t i = 0; i < coll.size(); ++i)
401 {
402 ComPtr<IMedium> floppyDrive = coll[i];
403 Bstr uuid;
404 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
405 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
406 Bstr name;
407 floppyDrive->COMGETTER(Name)(name.asOutParam());
408 RTPrintf("Name: %lS\n\n", name.raw());
409 }
410 }
411 break;
412 }
413
414 /** @todo function. */
415 case kListBridgedInterfaces:
416#if defined(VBOX_WITH_NETFLT)
417 case kListHostOnlyInterfaces:
418#endif
419 {
420 ComPtr<IHost> host;
421 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
422 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
423#if defined(VBOX_WITH_NETFLT)
424 if (enmCommand == kListBridgedInterfaces)
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#endif
479 }
480 break;
481 }
482
483 /** @todo function. */
484 case kListHostInfo:
485 {
486 ComPtr<IHost> Host;
487 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
488
489 RTPrintf("Host Information:\n\n");
490
491 LONG64 u64UtcTime = 0;
492 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
493 RTTIMESPEC timeSpec;
494 char szTime[32];
495 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
496
497 ULONG processorOnlineCount = 0;
498 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
499 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
500 ULONG processorCount = 0;
501 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
502 RTPrintf("Processor count: %lu\n", processorCount);
503 ULONG processorSpeed = 0;
504 Bstr processorDescription;
505 for (ULONG i = 0; i < processorCount; i++)
506 {
507 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
508 if (processorSpeed)
509 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
510 else
511 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
512 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
513 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
514 }
515
516 ULONG memorySize = 0;
517 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
518 RTPrintf("Memory size: %lu MByte\n", memorySize);
519
520 ULONG memoryAvailable = 0;
521 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
522 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
523
524 Bstr operatingSystem;
525 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
526 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
527
528 Bstr oSVersion;
529 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
530 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
531 break;
532 }
533
534 case kListHostCpuIDs:
535 {
536 ComPtr<IHost> Host;
537 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
538
539 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
540 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
541 static uint32_t const s_auCpuIdRanges[] =
542 {
543 UINT32_C(0x00000000), UINT32_C(0x0000007f),
544 UINT32_C(0x80000000), UINT32_C(0x8000007f),
545 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
546 };
547 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
548 {
549 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
550 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
551 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
552 continue;
553 cLeafs++;
554 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
555 {
556 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
557 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
558 }
559 }
560 break;
561 }
562
563 /** @todo function. */
564 case kListHddBackends:
565 {
566 ComPtr<ISystemProperties> systemProperties;
567 CHECK_ERROR(rptrVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
568 com::SafeIfaceArray<IMediumFormat> mediumFormats;
569 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
570
571 RTPrintf("Supported hard disk backends:\n\n");
572 for (size_t i = 0; i < mediumFormats.size(); ++i)
573 {
574 /* General information */
575 Bstr id;
576 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
577
578 Bstr description;
579 CHECK_ERROR(mediumFormats[i],
580 COMGETTER(Id)(description.asOutParam()));
581
582 ULONG caps;
583 CHECK_ERROR(mediumFormats[i],
584 COMGETTER(Capabilities)(&caps));
585
586 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
587 i, id.raw(), description.raw(), caps);
588
589 /* File extensions */
590 com::SafeArray <BSTR> fileExtensions;
591 com::SafeArray <DeviceType_T> deviceTypes;
592 CHECK_ERROR(mediumFormats[i],
593 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
594 for (size_t j = 0; j < fileExtensions.size(); ++j)
595 {
596 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
597 if (j != fileExtensions.size()-1)
598 RTPrintf(",");
599 }
600 RTPrintf("'");
601
602 /* Configuration keys */
603 com::SafeArray <BSTR> propertyNames;
604 com::SafeArray <BSTR> propertyDescriptions;
605 com::SafeArray <DataType_T> propertyTypes;
606 com::SafeArray <ULONG> propertyFlags;
607 com::SafeArray <BSTR> propertyDefaults;
608 CHECK_ERROR(mediumFormats[i],
609 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
610 ComSafeArrayAsOutParam(propertyDescriptions),
611 ComSafeArrayAsOutParam(propertyTypes),
612 ComSafeArrayAsOutParam(propertyFlags),
613 ComSafeArrayAsOutParam(propertyDefaults)));
614
615 RTPrintf(" properties=(");
616 if (propertyNames.size() > 0)
617 {
618 for (size_t j = 0; j < propertyNames.size(); ++j)
619 {
620 RTPrintf("\n name='%ls' desc='%ls' type=",
621 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
622 switch (propertyTypes[j])
623 {
624 case DataType_Int32: RTPrintf("int"); break;
625 case DataType_Int8: RTPrintf("byte"); break;
626 case DataType_String: RTPrintf("string"); break;
627 }
628 RTPrintf(" flags=%#04x", propertyFlags[j]);
629 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
630 if (j != propertyNames.size()-1)
631 RTPrintf(", ");
632 }
633 }
634 RTPrintf(")\n");
635 }
636 break;
637 }
638
639 case kListHdds:
640 {
641 com::SafeIfaceArray<IMedium> hdds;
642 CHECK_ERROR(rptrVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
643 listMedia(rptrVirtualBox, hdds, "base");
644 break;
645 }
646
647 case kListDvds:
648 {
649 com::SafeIfaceArray<IMedium> dvds;
650 CHECK_ERROR(rptrVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
651 listMedia(rptrVirtualBox, dvds, NULL);
652 break;
653 }
654
655 case kListFloppies:
656 {
657 com::SafeIfaceArray<IMedium> floppies;
658 CHECK_ERROR(rptrVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
659 listMedia(rptrVirtualBox, floppies, NULL);
660 break;
661 }
662
663 /** @todo function. */
664 case kListUsbHost:
665 {
666 ComPtr<IHost> Host;
667 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
668
669 SafeIfaceArray<IHostUSBDevice> CollPtr;
670 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
671
672 RTPrintf("Host USB Devices:\n\n");
673
674 if (CollPtr.size() == 0)
675 {
676 RTPrintf("<none>\n\n");
677 }
678 else
679 {
680 for (size_t i = 0; i < CollPtr.size(); ++i)
681 {
682 ComPtr <IHostUSBDevice> dev = CollPtr[i];
683
684 /* Query info. */
685 Bstr id;
686 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
687 USHORT usVendorId;
688 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
689 USHORT usProductId;
690 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
691 USHORT bcdRevision;
692 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
693
694 RTPrintf("UUID: %S\n"
695 "VendorId: %#06x (%04X)\n"
696 "ProductId: %#06x (%04X)\n"
697 "Revision: %u.%u (%02u%02u)\n",
698 Utf8Str(id).c_str(),
699 usVendorId, usVendorId, usProductId, usProductId,
700 bcdRevision >> 8, bcdRevision & 0xff,
701 bcdRevision >> 8, bcdRevision & 0xff);
702
703 /* optional stuff. */
704 Bstr bstr;
705 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
706 if (!bstr.isEmpty())
707 RTPrintf("Manufacturer: %lS\n", bstr.raw());
708 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
709 if (!bstr.isEmpty())
710 RTPrintf("Product: %lS\n", bstr.raw());
711 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
712 if (!bstr.isEmpty())
713 RTPrintf("SerialNumber: %lS\n", bstr.raw());
714 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
715 if (!bstr.isEmpty())
716 RTPrintf("Address: %lS\n", bstr.raw());
717
718 /* current state */
719 USBDeviceState_T state;
720 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
721 const char *pszState = "?";
722 switch (state)
723 {
724 case USBDeviceState_NotSupported:
725 pszState = "Not supported";
726 break;
727 case USBDeviceState_Unavailable:
728 pszState = "Unavailable";
729 break;
730 case USBDeviceState_Busy:
731 pszState = "Busy";
732 break;
733 case USBDeviceState_Available:
734 pszState = "Available";
735 break;
736 case USBDeviceState_Held:
737 pszState = "Held";
738 break;
739 case USBDeviceState_Captured:
740 pszState = "Captured";
741 break;
742 default:
743 ASSERT(false);
744 break;
745 }
746 RTPrintf("Current State: %s\n\n", pszState);
747 }
748 }
749 break;
750 }
751
752 /** @todo function. */
753 case kListUsbFilters:
754 {
755 RTPrintf("Global USB Device Filters:\n\n");
756
757 ComPtr<IHost> host;
758 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
759
760 SafeIfaceArray<IHostUSBDeviceFilter> coll;
761 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
762
763 if (coll.size() == 0)
764 {
765 RTPrintf("<none>\n\n");
766 }
767 else
768 {
769 for (size_t index = 0; index < coll.size(); ++index)
770 {
771 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
772
773 /* Query info. */
774
775 RTPrintf("Index: %zu\n", index);
776
777 BOOL active = FALSE;
778 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
779 RTPrintf("Active: %s\n", active ? "yes" : "no");
780
781 USBDeviceFilterAction_T action;
782 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
783 const char *pszAction = "<invalid>";
784 switch (action)
785 {
786 case USBDeviceFilterAction_Ignore:
787 pszAction = "Ignore";
788 break;
789 case USBDeviceFilterAction_Hold:
790 pszAction = "Hold";
791 break;
792 default:
793 break;
794 }
795 RTPrintf("Action: %s\n", pszAction);
796
797 Bstr bstr;
798 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
799 RTPrintf("Name: %lS\n", bstr.raw());
800 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
801 RTPrintf("VendorId: %lS\n", bstr.raw());
802 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
803 RTPrintf("ProductId: %lS\n", bstr.raw());
804 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
805 RTPrintf("Revision: %lS\n", bstr.raw());
806 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
807 RTPrintf("Manufacturer: %lS\n", bstr.raw());
808 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
809 RTPrintf("Product: %lS\n", bstr.raw());
810 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
811 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
812 }
813 }
814 break;
815 }
816
817 /** @todo function. */
818 case kListSystemProperties:
819 {
820 ComPtr<ISystemProperties> systemProperties;
821 rptrVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
822
823 Bstr str;
824 ULONG ulValue;
825 LONG64 i64Value;
826
827 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
828 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
829 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
830 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
831 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
832 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
833 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
834 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
835 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
836 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
837 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
838 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
839 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
840 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
841 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
842 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
843 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
844 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
845 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
846 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
847 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
848 RTPrintf("Maximum Boot Position: %u\n", ulValue);
849 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_IDE, &ulValue);
850 RTPrintf("Maximum IDE Controllers: %u\n", ulValue);
851 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
852 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
853 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
854 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
855 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SATA, &ulValue);
856 RTPrintf("Maximum SATA Controllers: %u\n", ulValue);
857 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
858 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
859 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
860 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
861 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SCSI, &ulValue);
862 RTPrintf("Maximum SCSI Controllers: %u\n", ulValue);
863 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
864 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
865 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
866 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
867 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SAS, &ulValue);
868 RTPrintf("Maximum SAS Controllers: %u\n", ulValue);
869 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
870 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
871 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
872 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
873 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_Floppy, &ulValue);
874 RTPrintf("Maximum Floppy Controllers: %u\n", ulValue);
875 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
876 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
877 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
878 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
879 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
880 RTPrintf("Default machine folder: %lS\n", str.raw());
881 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
882 RTPrintf("VRDE auth library: %lS\n", str.raw());
883 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
884 RTPrintf("Webservice auth. library: %lS\n", str.raw());
885 systemProperties->COMGETTER(DefaultVRDELibrary)(str.asOutParam());
886 RTPrintf("Remote desktop library: %lS\n", str.raw());
887 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
888 RTPrintf("Log history count: %u\n", ulValue);
889 break;
890 }
891
892 case kListDhcpServers:
893 {
894 com::SafeIfaceArray<IDHCPServer> svrs;
895 CHECK_ERROR(rptrVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
896 for (size_t i = 0; i < svrs.size(); ++i)
897 {
898 ComPtr<IDHCPServer> svr = svrs[i];
899 Bstr netName;
900 svr->COMGETTER(NetworkName)(netName.asOutParam());
901 RTPrintf("NetworkName: %lS\n", netName.raw());
902 Bstr ip;
903 svr->COMGETTER(IPAddress)(ip.asOutParam());
904 RTPrintf("IP: %lS\n", ip.raw());
905 Bstr netmask;
906 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
907 RTPrintf("NetworkMask: %lS\n", netmask.raw());
908 Bstr lowerIp;
909 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
910 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
911 Bstr upperIp;
912 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
913 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
914 BOOL fEnabled;
915 svr->COMGETTER(Enabled)(&fEnabled);
916 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
917 RTPrintf("\n");
918 }
919 break;
920 }
921
922 case kListVrdeLibraries:
923 {
924 SafeArray<BSTR> libs;
925 CHECK_ERROR(rptrVirtualBox, VRDEListLibraries(ComSafeArrayAsOutParam(libs)));
926 if (SUCCEEDED(rc))
927 {
928 for (size_t i = 0; i < libs.size(); ++i)
929 {
930 Bstr bstrName(libs[i]);
931 RTPrintf("%lS\n", bstrName.raw());
932 }
933 }
934 break;
935 }
936
937 case kListExtPacks:
938 rc = listExtensionPacks(rptrVirtualBox);
939 break;
940
941 /* No default here, want gcc warnings. */
942
943 } /* end switch */
944
945 return rc;
946}
947
948/**
949 * Handles the 'list' command.
950 *
951 * @returns Appropriate exit code.
952 * @param a Handler argument.
953 */
954int handleList(HandlerArg *a)
955{
956 bool fOptLong = false;
957 bool fOptMultiple = false;
958 enum enmListType enmOptCommand = kListNotSpecified;
959
960 static const RTGETOPTDEF s_aListOptions[] =
961 {
962 { "--long", 'l', RTGETOPT_REQ_NOTHING },
963 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
964 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
965 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
966 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
967 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
968 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
969 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
970 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
971#if defined(VBOX_WITH_NETFLT)
972 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
973#endif
974 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
975 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
976 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
977 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
978 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
979 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
980 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
981 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
982 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
983 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
984 { "vrdelibraries", kListVrdeLibraries, RTGETOPT_REQ_NOTHING },
985 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
986 };
987
988 int ch;
989 RTGETOPTUNION ValueUnion;
990 RTGETOPTSTATE GetState;
991 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
992 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
993 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
994 {
995 switch (ch)
996 {
997 case 'l': /* --long */
998 fOptLong = true;
999 break;
1000
1001 case 'm':
1002 fOptMultiple = true;
1003 if (enmOptCommand == kListNotSpecified)
1004 break;
1005 ch = enmOptCommand;
1006 /* fall thru */
1007
1008 case kListVMs:
1009 case kListRunningVMs:
1010 case kListOsTypes:
1011 case kListHostDvds:
1012 case kListHostFloppies:
1013 case kListBridgedInterfaces:
1014#if defined(VBOX_WITH_NETFLT)
1015 case kListHostOnlyInterfaces:
1016#endif
1017 case kListHostInfo:
1018 case kListHostCpuIDs:
1019 case kListHddBackends:
1020 case kListHdds:
1021 case kListDvds:
1022 case kListFloppies:
1023 case kListUsbHost:
1024 case kListUsbFilters:
1025 case kListSystemProperties:
1026 case kListDhcpServers:
1027 case kListVrdeLibraries:
1028 case kListExtPacks:
1029 enmOptCommand = (enum enmListType)ch;
1030 if (fOptMultiple)
1031 {
1032 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
1033 if (FAILED(hrc))
1034 return 1;
1035 }
1036 break;
1037
1038 case VINF_GETOPT_NOT_OPTION:
1039 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1040
1041 default:
1042 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1043 }
1044 }
1045
1046 /*
1047 * If not in multiple list mode, we have to produce the list now.
1048 */
1049 if (enmOptCommand == kListNotSpecified)
1050 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1051 if (!fOptMultiple)
1052 {
1053 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
1054 if (FAILED(hrc))
1055 return 1;
1056 }
1057
1058 return 0;
1059}
1060
1061#endif /* !VBOX_ONLY_DOCS */
1062/* 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