ia64/xen-unstable

changeset 12842:9de4597e1269

[XM] Fix xm uptime TypeError exception.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Alastair Tse <atse@xensource.com>
date Thu Dec 07 11:50:11 2006 +0000 (2006-12-07)
parents 8e035701b9ff
children fb3cb6f52a29
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu Dec 07 11:45:00 2006 +0000
     1.2 +++ b/tools/python/xen/xm/main.py	Thu Dec 07 11:50:11 2006 +0000
     1.3 @@ -30,6 +30,7 @@ import socket
     1.4  import traceback
     1.5  import xmlrpclib
     1.6  import traceback
     1.7 +import time
     1.8  import datetime
     1.9  from select import select
    1.10  import xml.dom.minidom
    1.11 @@ -626,7 +627,13 @@ def parse_doms_info(info):
    1.12  
    1.13      def get_status(n, t, d):
    1.14          return DOM_STATES[t(sxp.child_value(info, n, d))]
    1.15 -    
    1.16 +
    1.17 +    start_time = get_info('start_time', float, -1)
    1.18 +    if start_time == -1:
    1.19 +        up_time = float(-1)
    1.20 +    else:
    1.21 +        up_time = time.time() - start_time
    1.22 +
    1.23      return {
    1.24          'domid'    : get_info('domid',        str,   ''),
    1.25          'name'     : get_info('name',         str,   '??'),
    1.26 @@ -634,7 +641,7 @@ def parse_doms_info(info):
    1.27          'vcpus'    : get_info('vcpus',        int,   0),
    1.28          'state'    : get_info('state',        str,    ''),
    1.29          'cpu_time' : get_info('cpu_time',     float, 0),
    1.30 -        'up_time'  : get_info('up_time',      float, -1),
    1.31 +        'up_time'  : up_time,
    1.32          'seclabel' : security.get_security_printlabel(info),
    1.33          }
    1.34  
    1.35 @@ -1209,7 +1216,7 @@ def xm_uptime(args):
    1.36  
    1.37      for dom in doms:
    1.38          d = parse_doms_info(dom)
    1.39 -        if d['domid'] > 0:
    1.40 +        if int(d['domid']) > 0:
    1.41              uptime = int(round(d['up_time']))
    1.42          else:
    1.43              f=open('/proc/uptime', 'r')
    1.44 @@ -1236,10 +1243,10 @@ def xm_uptime(args):
    1.45          if short_mode:
    1.46              now = datetime.datetime.now()
    1.47              upstring = now.strftime(" %H:%M:%S") + " up " + upstring
    1.48 -            upstring += ", " + d['name'] + " (" + str(d['domid']) + ")"
    1.49 +            upstring += ", " + d['name'] + " (" + d['domid'] + ")"
    1.50          else:
    1.51              upstring += ':%(seconds)02d' % vars()
    1.52 -            upstring = ("%(name)-32s %(domid)3d " % d) + upstring
    1.53 +            upstring = ("%(name)-32s %(domid)3s " % d) + upstring
    1.54  
    1.55          print upstring
    1.56