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

Last change on this file since 532 was 531, checked in by quentin, 16 years ago

Use more efficient python API to get VM information

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