vboxshell.py revision 63702c0d2795cf416c91489cd9042d5d1063e159
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# Copyright (C) 2009 Sun Microsystems, Inc.
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# available from http://www.virtualbox.org. This file is free software;
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# you can redistribute it and/or modify it under the terms of the GNU
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# General Public License (GPL) as published by the Free Software
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# Clara, CA 95054 USA or visit http://www.sun.com if you need
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# additional information or have any questions.
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync#################################################################################
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# This program is a simple interactive shell for VirtualBox. You can query #
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# information and issue commands from a simple command line. #
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# It also provides you with examples on how to use VirtualBox's Python API. #
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# This shell is even somewhat documented and supports TAB-completion and #
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# history if you have Python readline installed. #
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync################################################################################
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# Simple implementation of IConsoleCallback, one can use it as skeleton
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync# for custom implementations
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync def onMousePointerShapeChange(self, visible, alpha, xHot, yHot, width, height, shape):
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync print "%s: onMousePointerShapeChange: visible=%d" %(self.mach.name, visible)
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync def onMouseCapabilityChange(self, supportsAbsolute, supportsRelative, needsHostCursor):
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync print "%s: onMouseCapabilityChange: supportsAbsolute = %d, supportsRelative = %d, needsHostCursor = %d" %(self.mach.name, supportsAbsolute, supportsRelative, needsHostCursor)
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync def onKeyboardLedsChange(self, numLock, capsLock, scrollLock):
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync print "%s: onKeyboardLedsChange capsLock=%d" %(self.mach.name, capsLock)
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync print "%s: onStateChange state=%d" %(self.mach.name, state)
a54b8f61d5d9f7e6f13cc710f4d1906ee7778322vboxsync print "%s: onAdditionsStateChange" %(self.mach.name)
return True
class VBoxMonitor:
import readline
import rlcompleter
if g_hasreadline:
matches = []
except Exception,e:
return matches
if not g_hasreadline:
comps = {}
comps[k] = None
def split_no_quotes(s):
while not p.completed:
except KeyboardInterrupt:
if mach:
if perf:
except Exception,e:
if g_verbose:
if var:
exec cmds
f = "/tmp/screenshot.png"
size = (w,h)
except Exception,e:
if g_verbose:
except Exception, e:
if g_verbose:
mach = None
mach = m
mach = m
return mach
for i in names:
if m.teleporterEnabled:
if mach == None:
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 " 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 %s bus: %d" % (controller.name, getControllerType(controller.controllerType), controller.bus)
if attaches:
for a in attaches:
m = a.medium
if m.hostDrive:
if a.passthrough:
if m.hostDrive:
if mach == None:
except Exception, e:
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 mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
if mach == None:
exec expr
except Exception, e:
if g_verbose:
value = None
if mach == None:
key = None
if obj == None:
if key == None:
for k in keys:
global g_verbose
print "Processor #%d speed: %dMHz %s" %(i,host.getProcessorSpeed(i), host.getProcessorDescription(i))
print " %s (vendorId=%d productId=%d serial=%s) %s" %(ud.product, ud.vendorId, ud.productId, ud.serialNumber, getUSBStateString(ud.state))
if mach == None:
if mach == None:
if mach == None:
except IOError,e:
print line,
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:
'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)\'', 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],
'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>', teleportCmd, 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],
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:
if vbox is not None:
while True:
except KeyboardInterrupt:
except EOFError:
except Exception,e:
if g_verbose:
style = None
if autopath: