VirtualBox

Changeset 26583 in vbox


Ignore:
Timestamp:
Feb 16, 2010 3:11:22 PM (15 years ago)
Author:
vboxsync
Message:

Python: gueststats command, API to get enums values list

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r26571 r26583  
    295295        return 'off'
    296296
    297 def guestStats(ctx,mach):
     297def perfStats(ctx,mach):
    298298    if not ctx['perf']:
    299299        return
     
    381381    else:
    382382        reportError(ctx,session,rc)
     383
     384
     385def guestStats(ctx,session,console,args):
     386    guest = console.guest
     387    # we need to set up guest statistics
     388    if len(args) > 0 :
     389        update = args[0]
     390    else:
     391        update = 1
     392    if guest.statisticsUpdateInterval != update:
     393        guest.statisticsUpdateInterval = update
     394        try:
     395            time.sleep(float(update)+0.1)
     396        except:
     397            # to allow sleep interruption
     398            pass
     399    all_stats = ctx['ifaces'].all_values('GuestStatisticType')
     400    cpu = 0
     401    for s in all_stats.keys():
     402        try:
     403            val = guest.getStatistic( cpu, all_stats[s])
     404            print "%s: %d" %(s, val)
     405        except:
     406            # likely not implemented
     407            pass
    383408
    384409def cmdExistingVm(ctx,mach,cmd,args):
     
    397422        print "Session to '%s' in wrong state: %s" %(mach.name, session.state)
    398423        return
    399     # unfortunately IGuest is suppressed, thus WebServices knows not about it
    400     # this is an example how to handle local only functionality
    401     if ctx['remote'] and cmd == 'stats2':
     424    # this could be an example how to handle local only (i.e. unavailable
     425    # in Webservices) functionality
     426    if ctx['remote'] and cmd == 'some_local_only_command':
    402427        print 'Trying to use local only functionality, ignored'
    403428        return
     
    407432         'powerdown':       lambda: console.powerDown(),
    408433         'powerbutton':     lambda: console.powerButton(),
    409          'stats':           lambda: guestStats(ctx, mach),
     434         'stats':           lambda: perfStats(ctx, mach),
    410435         'guest':           lambda: guestExec(ctx, mach, console, args),
    411436         'monitorGuest':    lambda: monitorGuest(ctx, mach, console, args),
    412437         'save':            lambda: progressBar(ctx,console.saveState()),
    413438         'screenshot':      lambda: takeScreenshot(ctx,console,args),
    414          'teleport':        lambda: teleport(ctx,session,console,args)
     439         'teleport':        lambda: teleport(ctx,session,console,args),
     440         'gueststats':      lambda: guestStats(ctx, mach, console, args),
    415441         }
    416442    try:
     
    747773    return 0
    748774
     775def gueststatsCmd(ctx, args):
     776    if (len(args) < 2):
     777        print "usage: gueststats name <check interval>"
     778        return 0
     779    mach = argsToMach(ctx,args)
     780    if mach == None:
     781        return 0
     782    cmdExistingVm(ctx, mach, 'gueststats', args[2:])
     783    return 0
     784
    749785
    750786def setvarCmd(ctx, args):
     
    11291165
    11301166commands = {'help':['Prints help information', helpCmd, 0],
    1131             'start':['Start virtual machine by name or uuid', startCmd, 0],
     1167            'start':['Start virtual machine by name or uuid: start Linux', startCmd, 0],
    11321168            'create':['Create virtual machine', createCmd, 0],
    11331169            'remove':['Remove virtual machine', removeCmd, 0],
     
    11611197            'closeportal':['Close teleportation portal (see openportal,teleport): closeportal Win', closeportalCmd, 0],
    11621198            'getextra':['Get extra data, empty key lists all: getextra <vm|global> <key>', getExtraDataCmd, 0],
    1163             'setextra':['Set extra data, empty value removes key: setextra <vm|global> <key> <value>', setExtraDataCmd, 0]           
     1199            'setextra':['Set extra data, empty value removes key: setextra <vm|global> <key> <value>', setExtraDataCmd, 0],
     1200            'gueststats':['Print available guest stats (only Windows guests with additions so far): gueststats Win32', gueststatsCmd, 0],
    11641201            }
    11651202
  • trunk/src/VBox/Main/glue/constants-python.xsl

    r22043 r26583  
    5959              </xsl:for-each>}
    6060
     61   _ValuesSym = {<xsl:for-each select="//enum">
     62                '<xsl:value-of select="@name"/>':{
     63                  <xsl:for-each select="const">'<xsl:value-of select="@name"/>': '<xsl:value-of select="@name"/>'<xsl:if test="not(position()=last())">,</xsl:if>
     64                  </xsl:for-each>}<xsl:if test="not(position()=last())">,</xsl:if>
     65
     66              </xsl:for-each>}
     67
    6168   _ValuesFlat = {<xsl:for-each select="//enum">
    6269                   <xsl:variable name="ename">
     
    9299         raise AttributeError
    93100
     101   def all_values(self,enum_name):
     102      if self.isSym:
     103        vals = self._ValuesSym.get(enum_name)
     104      else:
     105        vals = self._Values.get(enum_name)
     106      if vals is not None:
     107         return vals
     108      else:
     109         return {}
     110
    94111</xsl:template>
    95112</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette