Use more efficient python API to get VM information sipb-xen-remctl-auto/1.0.14
authorQuentin Smith <quentin@mit.edu>
Fri, 16 May 2008 00:31:05 +0000 (20:31 -0400)
committerQuentin Smith <quentin@mit.edu>
Fri, 16 May 2008 00:31:05 +0000 (20:31 -0400)
svn path=/trunk/packages/sipb-xen-remctl-auto/; revision=531

debian/changelog
files/usr/sbin/sipb-xen-listvms

index fbfbd5c..c3439d7 100644 (file)
@@ -1,3 +1,10 @@
+sipb-xen-remctl-auto (1.0.14) unstable; urgency=low
+
+  * Use more efficient python API to get VM information, and return it
+    in a Python dict structure.
+
+ -- Quentin Smith <quentin@mit.edu>  Thu, 15 May 2008 20:29:03 -0400
+
 sipb-xen-remctl-auto (1.0.13) unstable; urgency=low
 
   * Switch to just using the remote server.
index aa99757..7884d87 100755 (executable)
@@ -1,3 +1,40 @@
-#!/bin/sh
+#!/usr/bin/python
 
-xm uptime | sed -n 's/^d_// p'
+import sys
+sys.path.insert(0, '/usr/lib/xen-3.1-1/lib/python')
+from xen.lowlevel.xs import xs
+
+trans = xs()
+
+def live_vms():
+    domids = set(trans.ls('', '/local/domain'))
+    domids.remove('0')
+
+    vms = dict()
+
+    for domid in domids:
+        name, data = get_dom(int(domid))
+        if name.startswith('d_'):
+            name = name[2:]
+            vms[name] = data
+    return vms
+
+def get_dom(domid):
+    name = trans.read('', '/local/domain/%d/name' % domid)
+    data = dict()
+    data['domid'] = domid
+    # presence of a graphical console
+    data['console'] = trans.read('', '/local/domain/%d/device/vfb/0/state' % domid)
+    # uptime
+    data['vm'] = trans.read('', '/local/domain/%d/vm' % domid)
+    data['start_time'] = float(trans.read('', '%s/start_time' % data['vm']))
+    
+    return name, data
+
+if __name__ == '__main__':
+    vms = live_vms()
+    if '--pickle' in sys.argv[1:]:
+        import cPickle
+        cPickle.dump(vms, sys.stdout)
+    else:
+        print vms