X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/blobdiff_plain/8fa7103160f7a8e6663f88be13cb7a40e3032764..74bf6f0c14efbc2e33fd9f8d79bdb807286725ca:/host/usr/sbin/invirt-listvms diff --git a/host/usr/sbin/invirt-listvms b/host/usr/sbin/invirt-listvms index c16a883..aeea6d7 100755 --- a/host/usr/sbin/invirt-listvms +++ b/host/usr/sbin/invirt-listvms @@ -11,13 +11,27 @@ def live_vms(): domids.discard('0') vms = dict() + xenserver = None for domid in domids: try: name, data = get_dom(int(domid)) except (xs.Error, TypeError): continue # went down since we started - if name is not None and name.startswith('d_'): + if name is None: # xenstore may not be fully populated if it hung early + try: + if xenserver is None: + from xen.xm.main import SERVER_LEGACY_XMLRPC, parseServer + from xen.util.xmlrpcclient import ServerProxy + serverType, serverURI = parseServer() + if serverType != SERVER_LEGACY_XMLRPC: + continue # we can't handle a XenAPI server yet + xenserver = ServerProxy(serverURI) + name = filter(lambda x: isinstance(x, list) and x[0]=='name', + xenserver.xend.domain(int(domid)))[0][1] + except: + continue # we have nothing we can show about this domain + if name.startswith('d_'): name = name[2:] vms[name] = data return vms @@ -30,9 +44,27 @@ def get_dom(domid): data['console'] = xsc.read('', '/local/domain/%d/device/vfb/0/state' % domid) # uptime data['vm'] = xsc.read('', '/local/domain/%d/vm' % domid) - data['start_time'] = float(xsc.read('', '%s/start_time' % data['vm'])) - data['uptime'] = time.time()-data['start_time'] - + start_time = xsc.read('', '%s/start_time' % data['vm']) + if start_time is not None: + data['start_time'] = float(start_time) + data['uptime'] = time.time()-data['start_time'] + else: + data['uptime'] = 0 + # CD or autoinstall, if we're using either + vbds = xsc.ls('', '/local/domain/%d/device/vbd' % domid) + if vbds is not None: + for vbd in vbds: + dev = '/local/domain/%d/device/vbd/%s' % (domid, vbd) + dev_type = xsc.read('', '%s/device-type' % dev) + dev_params = xsc.read('', '%s/params' % xsc.read('', '%s/backend' % dev)) + if dev_type == 'cdrom': + data['cdrom'] = dev_params + elif dev_type == 'disk' and dev_params == '/dev/xenvg/s_install_hda': + data['autoinstall'] = True + cmdline = xsc.read('', '%s/image/cmdline' % data['vm']) + if cmdline is not None and 'auto=true' in cmdline: + data['autoinstall'] = True + return name, data if __name__ == '__main__':