vboxshell.py revision 5e444fec9316799a1da6f3e830aa685162c6754e
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# Copyright (C) 2009-2010 Oracle Corporation
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# available from http://www.virtualbox.org. This file is free software;
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# you can redistribute it and/or modify it under the terms of the GNU
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# General Public License (GPL) as published by the Free Software
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync#################################################################################
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# This program is a simple interactive shell for VirtualBox. You can query #
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# information and issue commands from a simple command line. #
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# It also provides you with examples on how to use VirtualBox's Python API. #
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# This shell is even somewhat documented, supports TAB-completion and #
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# history if you have Python readline installed. #
48f33dfd8f615d457106bf76ae2d09b8b9167c1avboxsync# Finally, shell allows arbitrary custom extensions, just create #
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# .VirtualBox/shexts/ and drop your extensions there. #
452fd0f33b11dc60aad994e3001c74415179d401vboxsync################################################################################
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# Simple implementation of IConsoleCallback, one can use it as skeleton
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync# for custom implementations
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync def onMousePointerShapeChange(self, visible, alpha, xHot, yHot, width, height, shape):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onMousePointerShapeChange: visible=%d shape=%d bytes" %(self.mach.name, visible,len(shape))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync def onMouseCapabilityChange(self, supportsAbsolute, supportsRelative, needsHostCursor):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onMouseCapabilityChange: supportsAbsolute = %d, supportsRelative = %d, needsHostCursor = %d" %(self.mach.name, supportsAbsolute, supportsRelative, needsHostCursor)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync def onKeyboardLedsChange(self, numLock, capsLock, scrollLock):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onKeyboardLedsChange capsLock=%d" %(self.mach.name, capsLock)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onStateChange state=%d" %(self.mach.name, state)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onAdditionsStateChange" %(self.mach.name)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onNetworkAdapterChange" %(self.mach.name)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onStorageControllerChange" %(self.mach.name)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onUSBControllerChange" %(self.mach.name)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync def onUSBDeviceStateChange(self, device, attached, error):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onUSBDeviceStateChange" %(self.mach.name)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onRuntimeError fatal=%d message=%s" %(self.mach.name, fatal, message)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%s: onShowWindow: %d" %(self.mach.name, winId)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "onExtraDataCanChange: %s %s=>%s" %(id, key, value)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # Witty COM bridge thinks if someone wishes to return tuple, hresult
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # is one of values we want to return
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "onExtraDataChange: %s %s=>%s" %(id, key, value)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync def onGuestPropertyChange(self, id, name, newValue, flags):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "onGuestPropertyChange: %s: %s=%s" %(id, name, newValue)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync taken from:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496812
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return rlcompleter.Completer.complete(self,text,state)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return not self.canBePath(phrase,word) and not self.canBeCommand(phrase, word)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Compute matches when text is a simple name.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync Return a list of all names currently defined
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync in self.namespace that match.
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # although it has autoconversion, we need to cast
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # explicitly for subscripts to work
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync readline.set_completer_delims(re.sub("[\\./-]", "", delims)) # remove some of the delimiters
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # OSX need it
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # see http://www.certif.com/spec_help/readline.html
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync readline.parse_and_bind ("bind ^W ed-delete-prev-word")
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # Doesn't work well
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # readline.parse_and_bind ("bind ^R em-inc-search-prev")
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Interrupted."
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Canceling task..."
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print colored("Error in %s: %s" %(ei.component, ei.text), 'red')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync mach = vb.createMachine(name, kind, base, "", False)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # update cache
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # update cache
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync progress = vb.openRemoteSession(session, uuid, type, "")
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # we ignore exceptions to allow starting VM even if
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # perf collector cannot be started
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # if session not opened, close doesn't make sense
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsyncdef getMachines(ctx, invalidate = False, simple=False):
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ctx['_machlist'] = ctx['global'].getArray(ctx['vb'], 'machines')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync ctx['_machlistsimple'] = cacheMachines(ctx,ctx['_machlist'])
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return 'yes'
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return 'no'
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # not infinity, but close enough
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # We need to catch all exceptions here, otherwise callback will never be unregistered
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync cb = ctx['global'].createCallback('IVirtualBoxCallback', VBoxMonitor, [vbox, isMscom])
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync # not infinity, but close enough
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync # We need to catch all exceptions here, otherwise callback will never be unregistered
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync (fbw, fbh, fbbpp) = display.getScreenResolution(screen)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Saving screenshot (%d x %d) screen %d in %s..." %(w,h,screen,f)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync im = Image.frombuffer(mode, size, str(data), "raw", mode, 0, 1)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Use host:port format for teleport target"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync progress = console.teleport(host, port, passwd, maxDowntime)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if progressBar(ctx, progress, 100) and int(progress.resultCode) == 0:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Success!"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # we need to set up guest statistics
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # to allow sleep interruption
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync all_stats = ctx['ifaces'].all_values('GuestStatisticType')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # likely not implemented
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync machine.mountMedium(args[0], args[1], args[2], args[3], args[4])
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print " %s: %s (vendorId=%d productId=%d serial=%s) %s" %(ud.id, colored(ud.product,'blue'), ud.vendorId, ud.productId, ud.serialNumber,asEnumElem(ctx, 'USBDeviceState', ud.state))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print " %s: %s (vendorId=%d productId=%d serial=%s)" %(ud.id, colored(ud.product,'blue'), ud.vendorId, ud.productId, ud.serialNumber)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print " name=%s host=%s %s %s" %(sf.name, sf.hostPath, cond(sf.accessible, "accessible", "not accessible"), cond(sf.writable, "writable", "read-only"))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Additions active, version %d.%d" %(vers >> 16, vers & 0xffff)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Support seamless: %s" %(asFlag(guest.supportsSeamless))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Support graphics: %s" %(asFlag(guest.supportsGraphics))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Statistic update interval: %d" %(guest.statisticsUpdateInterval)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "No additions"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync usbs = ctx['global'].getArray(console, 'USBDevices')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Attached USB:"
8f35148193cfa7ae5fd29370c1a09105e655c08dvboxsync rusbs = ctx['global'].getArray(console, 'remoteUSBDevices')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Remote USB:"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Transient shared folders:"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync sfs = rusbs = ctx['global'].getArray(console, 'sharedFolders')
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync printErr(ctx, "Session to '%s' not open: %s" %(mach.name,str(e)))
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if session.state != ctx['ifaces'].SessionState_Open:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Session to '%s' in wrong state: %s" %(mach.name, session.state)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # this could be an example how to handle local only (i.e. unavailable
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync # in Webservices) functionality
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if ctx['remote'] and cmd == 'some_local_only_command':
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print 'Trying to use local only functionality, ignored'
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'guest': lambda: guestExec(ctx, mach, console, args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'guestlambda': lambda: args[0](ctx, mach, console, args[1:]),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'monitorGuest': lambda: monitorGuest(ctx, mach, console, args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'save': lambda: progressBar(ctx,console.saveState()),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'screenshot': lambda: takeScreenshot(ctx,console,args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'teleport': lambda: teleport(ctx,session,console,args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'gueststats': lambda: guestStats(ctx, console, args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'plugcpu': lambda: plugCpu(ctx, session.machine, session, args),
48f33dfd8f615d457106bf76ae2d09b8b9167c1avboxsync 'unplugcpu': lambda: unplugCpu(ctx, session.machine, session, args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync 'mountiso': lambda: mountIso(ctx, session.machine, session, args),
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync session = ctx['global'].openMachineSession(mach.id)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync session = ctx['global'].openMachineSession(mach.id)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync return None
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if m == None:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Machine '%s' is unknown, use list command to find available machines" %(id)
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "Help page:"
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync if c == None:
febf3f1de573e25fb134b8453a22b0732b4c52e2vboxsync print "%sMachine '%s' [%s], machineState=%s, sessionState=%s" %(tele,colVm(ctx,m.name),m.id,asEnumElem(ctx, "MachineState", m.state), asEnumElem(ctx,"SessionState", m.sessionState))
if mach == None:
print " Firmware [firmwareType]: %s (%s)" %(asEnumElem(ctx,"FirmwareType", mach.firmwareType),mach.firmwareType)
print " Clipboard mode [clipboardMode]: %s (%s)" %(asEnumElem(ctx,"ClipboardMode", mach.clipboardMode), mach.clipboardMode)
print " Machine status [n/a]: %s (%s)" % (asEnumElem(ctx,"SessionState", mach.sessionState), mach.sessionState)
print " Hardware virtualization [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_Enabled,value)]: " + asState(hwVirtEnabled)
print " VPID support [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_VPID,value)]: " + asState(hwVirtVPID)
hwVirtNestedPaging = mach.getHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_NestedPaging)
print " Nested paging [mach.setHWVirtExProperty(ctx['global'].constants.HWVirtExPropertyType_NestedPaging,value)]: " + asState(hwVirtNestedPaging)
print " Hardware 2d video acceleration [accelerate2DVideoEnabled]: " + asState(mach.accelerate2DVideoEnabled)
print " Audio [via audioAdapter]: chip %s; host driver %s" %(asEnumElem(ctx,"AudioControllerType", mach.audioAdapter.audioController), asEnumElem(ctx,"AudioDriverType", mach.audioAdapter.audioDriver))
print " Keyboard [keyboardHidType]: %s (%s)" %(asEnumElem(ctx,"KeyboardHidType", mach.keyboardHidType), mach.keyboardHidType)
print " Pointing device [pointingHidType]: %s (%s)" %(asEnumElem(ctx,"PointingHidType", mach.pointingHidType), mach.pointingHidType)
if controllers:
print " '%s': bus %s type %s" % (controller.name, asEnumElem(ctx,"StorageBus", controller.bus), asEnumElem(ctx,"StorageControllerType", controller.controllerType))
if attaches:
for a in attaches:
print " Controller: '%s' port/device: %d:%d type: %s (%s):" % (a.controller, a.port, a.device, asEnumElem(ctx,"DeviceType", a.type), a.type)
m = a.medium
if m.hostDrive:
if a.passthrough:
if m.hostDrive:
if mach == None:
except Exception, e:
if mach == None:
while True:
except KeyboardInterrupt:
if prompt:
if not line:
raise EOFError
return line
import getpass
if mach == None:
print "usage: gcat [vmname|uuid] local_file | guestProgram, such as gcat linux /home/nike/.bashrc | sh -c 'cat >'"
if mach == None:
env = []
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if enabled:
if mach == None:
if mach == None:
if mach == None:
if plug:
if mach == None:
if mach == None:
exec expr
if mach == None:
value = None
if mach == None:
key = None
if obj == None:
if key == None:
for k in keys:
global g_verbose
global g_hascolors
print " processor #%d speed: %dMHz %s" %(i,host.getProcessorSpeed(i), host.getProcessorDescription(i))
if mach == None:
if mach == None:
if mach == None:
while True:
if mach == None:
while True:
for mt in m:
exec expr
except Exception, e:
if g_verbose:
except IOError,e:
except Exception,e:
if g_verbose:
except KeyboardInterrupt:
url = None
import sys
if mach is None:
scancodes = {
extScancodes = {
return [code]
return extCode
return codes
import time
pressed = []
for c in pressed:
pressed = []
if not group:
for c in pressed:
pressed = []
import sys
if mach is None:
if verbose:
if inBytes:
print " %s (%s)%s %s [logical %s]" %(colPath(ctx,hdd.location), hdd.format, optId(verbose,hdd.id),colSizeM(ctx,asSize(hdd.size, True)), colSizeM(ctx,asSize(hdd.logicalSize, False)))
print " %s (%s)%s %s" %(colPath(ctx,dvd.location), dvd.format,optId(verbose,dvd.id),colSizeM(ctx,asSize(dvd.size, True)))
print " %s (%s)%s %s" %(colPath(ctx,floppy.location), floppy.format,optId(verbose,floppy.id), colSizeM(ctx,asSize(floppy.size, True)))
for a in atts:
hdd = vb.openHardDisk(loc, ctx['global'].constants.AccessMode_ReadWrite, setImageId, imageId, setParentId, parentId)
if mach is None:
cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_HardDisk,hdd.id))
for a in atts:
if a.medium:
if mach is None:
for m in machs:
except Exception, e:
if mach is None:
cmdClosedVm(ctx, mach, lambda ctx,mach,args: mach.attachDevice(ctr, port, slot, ctx['global'].constants.DeviceType_DVD,dvd.id))
if mach is None:
if mach is None:
if mach is None:
if type != None:
if type == None:
type = None
if mach is None:
if bus is None:
if mach is None:
if mach is None:
if mach is None:
except KeyboardInterrupt:
if mach is None:
if persistent:
cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: console.createSharedFolder(name, path, writable)])
if mach is None:
if not found:
cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: console.removeSharedFolder(name)])
if mach is None:
cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.takeSnapshot(name,desc)))
cmdAnyVm(ctx, mach, lambda ctx,mach,console,args: progressBar(ctx, console.deleteSnapshot(snap.id)))
alias = {
socksndbuf/sockrcvbuf - sets amount of kb for socket sending/receiving buffer
msg = 'mtu:{0} socket(snd:{1}, rcv:{2}) tcpwnd(snd:{3}, rcv:{4})'.format(mtu, socksndbuf, sockrcvbuf, tcpsndwnd, tcprcvwnd);
msg = 'passdomain:{0}, proxy:{1}, usehostresolver:{2}'.format(yesno[int(nat.dnsPassDomain)], yesno[int(nat.dnsProxy)], yesno[int(nat.dnsUseHostResolver)])
if server is None:
if server is None:
if prefix is None:
if bootfile is None:
msg = []
pfcmd = {
'func': lambda: nat.addRedirect(args[3], proto[args[2]], args[4], int(args[5]), args[6], int(args[7]))
natcommands = {
if mach == None:
if len(args) < 3 or not args[2].isdigit() or int(args[2]) not in range(0, ctx['vb'].systemProperties.networkAdapterCount):
print 'please specify adapter num {0} isn\'t in range [0-{1}]'.format(args[2], ctx['vb'].systemProperties.networkAdapterCount)
cmdargs = []
session = None
elif report is not None:
for r in report:
print msg
usage: nic <vm> <nicnum> attachment [Null|NAT|Bridged <interface>|Internal <name>|HostOnly <interface>]
import types
(r, p) = nicAttachmentType[t]
niccomand = {
if vm is None:
print 'please specify adapter num %d isn\'t in range [0-%d]'%(args[2], ctx['vb'].systemProperties.networkAdapterCount)
session = None
if report is not None:
'eval':['Evaluate arbitrary Python construction: eval \'for m in getMachines(ctx): print m.name,"has",m.memorySize,"M"\'', evalCmd, 0],
'guest':['Execute command for guest: guest Win32 \'console.mouse.putMouseEvent(20, 20, 0, 0, 0)\'', guestCmd, 0],
'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd, 0],
'monitorVBox':['Monitor what happens with Virtual Box for some time: monitorVBox 10', monitorVBoxCmd, 0],
'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win32 0 8080 80', portForwardCmd, 0],
'findLog':['Show entries matching pattern in log file of the VM, : findLog Win32 PDM|CPUM', findLogCmd, 0],
'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0],
'teleport':['Teleport VM to another box (see openportal): teleport Win anotherhost:8000 <passwd> <maxDowntime>', teleportCmd, 0],
'typeGuest':['Type arbitrary text in guest: typeGuest Linux "^lls\\n&UP;&BKSP;ess /etc/hosts\\nq^c" 0.7', typeGuestCmd, 0],
'openportal':['Open portal for teleportation of VM from another box (see teleport): openportal Win 8000 <passwd>', openportalCmd, 0],
'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0],
'setextra':['Set extra data, empty value removes key: setextra <vm|global> <key> <value>', setExtraDataCmd, 0],
'gueststats':['Print available guest stats (only Windows guests with additions so far): gueststats Win32', gueststatsCmd, 0],
'unplugcpu':['Remove a CPU from a running VM (additions required, Windows cannot unplug): unplugcpu Linux 1', unplugcpuCmd, 0],
'registerHdd': ['Register HDD image with VirtualBox instance: registerHdd /disk.vdi', registerHddCmd, 0],
'unregisterHdd': ['Unregister HDD image with VirtualBox instance: unregisterHdd /disk.vdi', unregisterHddCmd, 0],
'attachHdd': ['Attach HDD to the VM: attachHdd win /disk.vdi "IDE Controller" 0:1', attachHddCmd, 0],
'registerIso': ['Register CD/DVD image with VirtualBox instance: registerIso /os.iso', registerIsoCmd, 0],
'unregisterIso': ['Unregister CD/DVD image with VirtualBox instance: unregisterIso /os.iso', unregisterIsoCmd, 0],
'attachIso': ['Attach CD/DVD to the VM: attachIso win /os.iso "IDE Controller" 0:1', attachIsoCmd, 0],
'mountIso': ['Mount CD/DVD to the running VM: mountIso win /os.iso "IDE Controller" 0:1', mountIsoCmd, 0],
'unmountIso': ['Unmount CD/DVD from running VM: unmountIso win "IDE Controller" 0:1', unmountIsoCmd, 0],
'attachUsb': ['Attach USB device to the VM (use listUsb to show available devices): attachUsb win uuid', attachUsbCmd, 0],
'shareFolder': ['Make host\'s folder visible to guest: shareFolder win /share share writable', shareFolderCmd, 0],
c = aliases[c]
if ci == None:
# file ~/.VirtualBox/shellext.py with content like
# Also one can put shell extensions into ~/.VirtualBox/shexts and
if g_verbose:
for e in exts:
commands['connect'] = ["Connect to remote VBox instance: connect http://server:18083 user password", connectCmd, 0]
if vbox is not None:
global g_hascolors
while True:
except KeyboardInterrupt:
except EOFError:
except Exception,e:
if g_verbose:
if g_hasreadline:
if mach == None:
style = None
if autopath: