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

Last change on this file since 551 was 551, checked in by broder, 17 years ago

Use YAML on listvms

  • Property svn:executable set to *
File size: 1014 bytes
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
7import yaml
8
9trans = xs()
10
11def live_vms():
12    domids = set(trans.ls('', '/local/domain'))
13    domids.discard('0')
14
15    vms = dict()
16
17    for domid in domids:
18        name, data = get_dom(int(domid))
19        if name.startswith('d_'):
20            name = name[2:]
21            vms[name] = data
22    return vms
23
24def get_dom(domid):
25    name = trans.read('', '/local/domain/%d/name' % domid)
26    data = dict()
27    data['domid'] = domid
28    # presence of a graphical console
29    data['console'] = trans.read('', '/local/domain/%d/device/vfb/0/state' % domid)
30    # uptime
31    data['vm'] = trans.read('', '/local/domain/%d/vm' % domid)
32    data['start_time'] = float(trans.read('', '%s/start_time' % data['vm']))
33    data['uptime'] = time.time()-data['start_time']
34   
35    return name, data
36
37if __name__ == '__main__':
38    vms = live_vms()
39    print yaml.safe_dump(vms, default_flow_style=False)
Note: See TracBrowser for help on using the repository browser.