From: Quentin Smith Date: Fri, 16 May 2008 00:31:05 +0000 (-0400) Subject: Use more efficient python API to get VM information X-Git-Tag: sipb-xen-remctl-auto/1.0.14^0 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/commitdiff_plain/e620ec46d10ab91f275abddfb0da7c54075df99f Use more efficient python API to get VM information svn path=/trunk/packages/sipb-xen-remctl-auto/; revision=531 --- diff --git a/debian/changelog b/debian/changelog index fbfbd5c..c3439d7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 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. diff --git a/files/usr/sbin/sipb-xen-listvms b/files/usr/sbin/sipb-xen-listvms index aa99757..7884d87 100755 --- a/files/usr/sbin/sipb-xen-listvms +++ b/files/usr/sbin/sipb-xen-listvms @@ -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