5 from xen.lowlevel import xs
10 domids = set(xsc.ls('', '/local/domain'))
18 name, data = get_dom(int(domid))
19 except (xs.Error, TypeError):
20 continue # went down since we started
21 if name is None: # xenstore may not be fully populated if it hung early
24 from xen.xm.main import SERVER_LEGACY_XMLRPC, parseServer
25 from xen.util.xmlrpcclient import ServerProxy
26 serverType, serverURI = parseServer()
27 if serverType != SERVER_LEGACY_XMLRPC:
28 continue # we can't handle a XenAPI server yet
29 xenserver = ServerProxy(serverURI)
30 name = filter(lambda x: isinstance(x, list) and x[0]=='name',
31 xenserver.xend.domain(int(domid)))[0][1]
33 continue # we have nothing we can show about this domain
34 if name.startswith('d_'):
40 name = xsc.read('', '/local/domain/%d/name' % domid)
43 # presence of a graphical console
44 data['console'] = xsc.read('', '/local/domain/%d/device/vfb/0/state' % domid)
46 data['vm'] = xsc.read('', '/local/domain/%d/vm' % domid)
47 start_time = xsc.read('', '%s/start_time' % data['vm'])
48 if start_time is not None:
49 data['start_time'] = float(start_time)
50 data['uptime'] = time.time()-data['start_time']
53 # CD or autoinstall, if we're using either
54 vbds = xsc.ls('', '/local/domain/%d/device/vbd' % domid)
57 dev = '/local/domain/%d/device/vbd/%s' % (domid, vbd)
58 dev_type = xsc.read('', '%s/device-type' % dev)
59 dev_params = xsc.read('', '%s/params' % xsc.read('', '%s/backend' % dev))
60 if dev_type == 'cdrom':
61 data['cdrom'] = dev_params
62 elif dev_type == 'disk' and dev_params == '/dev/xenvg/s_install_hda':
63 data['autoinstall'] = True
64 cmdline = xsc.read('', '%s/image/cmdline' % data['vm'])
65 if cmdline is not None and 'auto=true' in cmdline:
66 data['autoinstall'] = True
70 if __name__ == '__main__':
72 if '--json' in sys.argv[1:]:
74 print cjson.encode(vms)
75 elif '--pickle' in sys.argv[1:]:
77 cPickle.dump(vms, sys.stdout, cPickle.HIGHEST_PROTOCOL)
80 print yaml.dump(vms, Dumper=yaml.CSafeDumper, default_flow_style=False)