5 from xen.lowlevel import xs
10 domids = set(xsc.ls('', '/local/domain'))
17 name, data = get_dom(int(domid))
18 except (xs.Error, TypeError):
19 continue # went down since we started
20 if name is not None and name.startswith('d_'):
26 name = xsc.read('', '/local/domain/%d/name' % domid)
29 # presence of a graphical console
30 data['console'] = xsc.read('', '/local/domain/%d/device/vfb/0/state' % domid)
32 data['vm'] = xsc.read('', '/local/domain/%d/vm' % domid)
33 data['start_time'] = float(xsc.read('', '%s/start_time' % data['vm']))
34 data['uptime'] = time.time()-data['start_time']
36 vbds = xsc.ls('', '/local/domain/%d/device/vbd' % domid)
38 dev = '/local/domain/%d/device/vbd/%s' % (domid, vbd)
39 if xsc.read('', '%s/device-type' % dev) == 'cdrom':
40 data['cdrom'] = xsc.read('', '%s/params' % xsc.read('', '%s/backend' % dev))
44 if __name__ == '__main__':
46 if '--json' in sys.argv[1:]:
48 print cjson.encode(vms)
49 elif '--pickle' in sys.argv[1:]:
51 cPickle.dump(vms, sys.stdout, cPickle.HIGHEST_PROTOCOL)
54 print yaml.dump(vms, Dumper=yaml.CSafeDumper, default_flow_style=False)