ia64/xen-unstable

changeset 11086:457c427c28fc

New xm uptime command.

From Alex Brett <alex.brett@xensource.com>

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Sat Aug 12 12:25:42 2006 +0100 (2006-08-12)
parents 44aa6f86830d
children 857854460d36
files docs/src/user.tex tools/python/xen/xm/main.py
line diff
     1.1 --- a/docs/src/user.tex	Fri Aug 11 18:09:13 2006 +0100
     1.2 +++ b/docs/src/user.tex	Sat Aug 12 12:25:42 2006 +0100
     1.3 @@ -1090,6 +1090,9 @@ The \path{xm list} command also supports
     1.4  \path{-l} switch is used.  This outputs the full details of the
     1.5  running domains in \xend's SXP configuration format.
     1.6  
     1.7 +If you want to know how long your domains have been running for, then 
     1.8 +you can use the \verb_# xm uptime_ command.
     1.9 +
    1.10  
    1.11  You can get access to the console of a particular domain using 
    1.12  the \verb_# xm console_ command  (e.g.\ \verb_# xm console myVM_). 
     2.1 --- a/tools/python/xen/xm/main.py	Fri Aug 11 18:09:13 2006 +0100
     2.2 +++ b/tools/python/xen/xm/main.py	Sat Aug 12 12:25:42 2006 +0100
     2.3 @@ -31,6 +31,7 @@ import warnings
     2.4  warnings.filterwarnings('ignore', category=FutureWarning)
     2.5  import xmlrpclib
     2.6  import traceback
     2.7 +import datetime
     2.8  
     2.9  import xen.xend.XendProtocol
    2.10  
    2.11 @@ -70,6 +71,7 @@ save_help =    "save <DomId> <File>     
    2.12  shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
    2.13  top_help =     "top                              Monitor system and domains in real-time"
    2.14  unpause_help = "unpause <DomId>                  Unpause a paused domain"
    2.15 +uptime_help  = "uptime [-s|--short] [DomId, ...] List uptime for domains"
    2.16  
    2.17  help_spacer = """
    2.18     """
    2.19 @@ -149,6 +151,7 @@ short_command_list = [
    2.20      "shutdown",
    2.21      "top",
    2.22      "unpause",
    2.23 +    "uptime",
    2.24      "vcpu-set",
    2.25      ]
    2.26  
    2.27 @@ -172,6 +175,7 @@ domain_commands = [
    2.28      "sysrq",
    2.29      "top",
    2.30      "unpause",
    2.31 +    "uptime",
    2.32      "vcpu-list",
    2.33      "vcpu-pin",
    2.34      "vcpu-set",
    2.35 @@ -412,6 +416,7 @@ def parse_doms_info(info):
    2.36          'vcpus'    : get_info('online_vcpus', int,   0),
    2.37          'state'    : get_info('state',        str,   '??'),
    2.38          'cpu_time' : get_info('cpu_time',     float, 0),
    2.39 +        'up_time'  : get_info('up_time',      float, -1),
    2.40          'seclabel' : security.get_security_printlabel(info),
    2.41          }
    2.42  
    2.43 @@ -818,6 +823,59 @@ def xm_console(args):
    2.44      domid = int(sxp.child_value(info, 'domid', '-1'))
    2.45      console.execConsole(domid)
    2.46  
    2.47 +def xm_uptime(args):
    2.48 +    short_mode = 0
    2.49 +
    2.50 +    try:
    2.51 +        (options, params) = getopt.gnu_getopt(args, 's', ['short'])
    2.52 +    except getopt.GetoptError, opterr:
    2.53 +        err(opterr)
    2.54 +        sys.exit(1)
    2.55 +
    2.56 +    for (k, v) in options:
    2.57 +        if k in ['-s', '--short']:
    2.58 +            short_mode = 1
    2.59 +
    2.60 +    doms = getDomains(params)
    2.61 +
    2.62 +    if short_mode == 0:
    2.63 +        print 'Name                              ID Uptime'
    2.64 +
    2.65 +    for dom in doms:
    2.66 +        d = parse_doms_info(dom)
    2.67 +        if d['dom'] > 0:
    2.68 +            uptime = int(round(d['up_time']))
    2.69 +        else:
    2.70 +            f=open('/proc/uptime', 'r')
    2.71 +            upfile = f.read()
    2.72 +            uptime = int(round(float(upfile.split(' ')[0])))
    2.73 +            f.close()
    2.74 +
    2.75 +        days = int(uptime / 86400)
    2.76 +        uptime -= (days * 86400)
    2.77 +        hours = int(uptime / 3600)
    2.78 +        uptime -= (hours * 3600)
    2.79 +        minutes = int(uptime / 60)
    2.80 +        uptime -= (minutes * 60)
    2.81 +        seconds = uptime
    2.82 +            
    2.83 +        upstring = ""
    2.84 +        if days > 0:
    2.85 +            upstring += str(days) + " day"
    2.86 +            if days > 1:
    2.87 +                upstring += "s"
    2.88 +            upstring += ", "
    2.89 +        upstring += '%(hours)2d:%(minutes)02d' % vars()
    2.90 +
    2.91 +        if short_mode:
    2.92 +            now = datetime.datetime.now()
    2.93 +            upstring = now.strftime(" %H:%M:%S") + " up " + upstring
    2.94 +            upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
    2.95 +        else:
    2.96 +            upstring += ':%(seconds)02d' % vars()
    2.97 +            upstring = ("%(name)-32s %(dom)3d " % d) + upstring
    2.98 +
    2.99 +        print upstring
   2.100  
   2.101  def xm_top(args):
   2.102      arg_check(args, "top", 0)
   2.103 @@ -1117,6 +1175,7 @@ commands = {
   2.104      "save": xm_save,
   2.105      "reboot": xm_reboot,
   2.106      "shutdown": xm_shutdown,
   2.107 +    "uptime": xm_uptime,
   2.108      "list": xm_list,
   2.109      # memory commands
   2.110      "mem-max": xm_mem_max,