source: trunk/packages/sipb-xen-remctl-auto/files/usr/sbin/sipb-xen-listvms @ 533

Last change on this file since 533 was 533, checked in by quentin, 17 years ago

Compute uptime on the server so time drift doesn't cause problems

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/python
2
3import sys
4import time
5sys.path.insert(0, '/usr/lib/xen-3.1-1/lib/python')
6from xen.lowlevel.xs import xs
7
8trans = xs()
9
10def live_vms():
11    domids = set(trans.ls('', '/local/domain'))
12    domids.discard('0')
13
14    vms = dict()
15
16    for domid in domids:
17        name, data = get_dom(int(domid))
18        if name.startswith('d_'):
19            name = name[2:]
20            vms[name] = data
21    return vms
22
23def get_dom(domid):
24    name = trans.read('', '/local/domain/%d/name' % domid)
25    data = dict()
26    data['domid'] = domid
27    # presence of a graphical console
28    data['console'] = trans.read('', '/local/domain/%d/device/vfb/0/state' % domid)
29    # uptime
30    data['vm'] = trans.read('', '/local/domain/%d/vm' % domid)
31    data['start_time'] = float(trans.read('', '%s/start_time' % data['vm']))
32    data['uptime'] = time.time()-data['start_time']
33   
34    return name, data
35
36if __name__ == '__main__':
37    vms = live_vms()
38    if '--pickle' in sys.argv[1:]:
39        import cPickle
40        cPickle.dump(vms, sys.stdout, cPickle.HIGHEST_PROTOCOL)
41    else:
42        print vms
Note: See TracBrowser for help on using the repository browser.