Skip to contentSkip to conversation

Fix the xm uptime command

PATCH In review Masaki Kanno 2 participants 2 messages Dec 6, 2006 – Dec 7, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix the xm uptime command

Hi,

I saw the following Traceback message.

# xm uptime
Name                              ID Uptime
Unexpected error: exceptions.TypeError

Please report to [email protected] Traceback (most recent call last):
File "/usr/sbin/xm", line 10, in ?
main.main(sys.argv)
File "/usr/lib/python/xen/xm/main.py", line 1606, in main
rc = cmd(args)
File "/usr/lib/python/xen/xm/main.py", line 1169, in xm_uptime

    upstring = ("%(name)-32s %(domid)3d " % d) + upstring

TypeError: int argument required

This patch fixes the xm uptime command.

# xm uptime
Name                              ID Uptime
Domain-0                           0 19:25:56
vm1                                1  7:05:45
# xm uptime -s
 18:37:35 up 19:26, Domain-0 (0)
 18:37:35 up  7:05, vm1 (1)

Best regards,
Kan

tools/python/xen/xm/main.py +12 -5
diff -r 0bea8e773508 tools/python/xen/xm/main.py
@@ -29,6 +29,7 @@ import traceback
 import traceback
 import xmlrpclib
 import traceback
+import time
 import datetime
 from select import select
 
@@ -577,7 +578,13 @@ def parse_doms_info(info):
 
     def get_status(n, t, d):
         return DOM_STATES[t(sxp.child_value(info, n, d))]
-    
+
+    start_time = get_info('start_time', float, -1)
+    if start_time == -1:
+        up_time = float(-1)
+    else:
+        up_time = time.time() - start_time
+
     return {
         'domid'    : get_info('domid',        str,   ''),
         'name'     : get_info('name',         str,   '??'),
@@ -585,7 +592,7 @@ def parse_doms_info(info):
         'vcpus'    : get_info('vcpus',        int,   0),
         'state'    : get_info('state',        str,    ''),
         'cpu_time' : get_info('cpu_time',     float, 0),
-        'up_time'  : get_info('up_time',      float, -1),
+        'up_time'  : up_time,
         'seclabel' : security.get_security_printlabel(info),
         }
 
@@ -1134,7 +1141,7 @@ def xm_uptime(args):
 
     for dom in doms:
         d = parse_doms_info(dom)
-        if d['domid'] > 0:
+        if int(d['domid']) > 0:
             uptime = int(round(d['up_time']))
         else:
             f=open('/proc/uptime', 'r')
@@ -1161,10 +1168,10 @@ def xm_uptime(args):
         if short_mode:
             now = datetime.datetime.now()
             upstring = now.strftime(" %H:%M:%S") + " up " + upstring
-            upstring += ", " + d['name'] + " (" + str(d['domid']) + ")"
+            upstring += ", " + d['name'] + " (" + d['domid'] + ")"
         else:
             upstring += ':%(seconds)02d' % vars()
-            upstring = ("%(name)-32s %(domid)3d " % d) + upstring
+            upstring = ("%(name)-32s %(domid)3s " % d) + upstring
 
         print upstring
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 7 lines · Masaki Kanno

Hi,

I saw the following Traceback message.

# xm uptime
Name                              ID Uptime
Unexpected error: exceptions.TypeError

[Snip..]

Quoted 2 lines

Thanks for the patch. Applied to unstable.

Cheers,

Alastair