vboxshell.py revision c792fe5d6a56055c4d060db36316c4dac5311c7e
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# Copyright (C) 2009 Sun Microsystems, Inc.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# available from http://www.virtualbox.org. This file is free software;
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# you can redistribute it and/or modify it under the terms of the GNU
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# General Public License (GPL) as published by the Free Software
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# Clara, CA 95054 USA or visit http://www.sun.com if you need
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# additional information or have any questions.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync#################################################################################
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# This program is a simple interactive shell for VirtualBox. You can query #
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# information and issue commands from a simple command line. #
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# It also provides you with examples on how to use VirtualBox's Python API. #
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# This shell is even somewhat documented and supports TAB-completion and #
f0ab104f070bc7f569404826fea1828ed985638cvboxsync# history if you have Python readline installed. #
f0ab104f070bc7f569404826fea1828ed985638cvboxsync################################################################################
f0ab104f070bc7f569404826fea1828ed985638cvboxsync """ This class provides a wrapper over IPerformanceCollector in order to
f0ab104f070bc7f569404826fea1828ed985638cvboxsync get more 'pythonic' interface.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync To begin collection of metrics use setup() method.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync To get collected data use query() method.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync It is possible to disable metric collection without changing collection
f0ab104f070bc7f569404826fea1828ed985638cvboxsync parameters with disable() method. The enable() method resumes metric
f0ab104f070bc7f569404826fea1828ed985638cvboxsync collection.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync """ Initializes the instance.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync Pass an instance of IVirtualBox as parameter.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync """ Discards all previously collected values for the specified
f0ab104f070bc7f569404826fea1828ed985638cvboxsync metrics, sets the period of collection and the number of retained
f0ab104f070bc7f569404826fea1828ed985638cvboxsync samples, enables collection.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync self.collector.setupMetrics(names, objects, period, nsamples)
f0ab104f070bc7f569404826fea1828ed985638cvboxsync """ Resumes metric collection for the specified metrics.
f0ab104f070bc7f569404826fea1828ed985638cvboxsync """ Suspends metric collection for the specified metrics.
out = []
'values_as_string':'['+', '.join([fmt % (int(values[j])/scale, units[i]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))])+']'
return out
class GuestMonitor:
return true
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):
return s.split()
if mach:
if perf:
except Exception,e:
if g_verbose:
if var:
exec cmds
import time
import xpcom
except Exception,e:
if g_verbose:
except Exception, e:
if g_verbose:
mach = None
mach = m
mach = m
return mach
for i in commands:
if mach == None:
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:
exec expr
except Exception, e:
if g_verbose:
global g_verbose
if mach == None:
exec expr
except Exception, e:
if g_verbose:
'eval':['Evaluate arbitrary Python construction: eval for m in getMachines(ctx): print m.name,"has",m.memorySize,"M"', evalCmd],
'guest':['Execute command for guest: guest Win32 console.mouse.putMouseEvent(20, 20, 0, 0)', guestCmd],
'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd],
c = aliases[c]
if ci == None:
while True:
except KeyboardInterrupt:
except EOFError:
except Exception,e:
if g_verbose:
style = None