From 74bf6f0c14efbc2e33fd9f8d79bdb807286725ca Mon Sep 17 00:00:00 2001 From: Mitchell E Berger Date: Wed, 23 Nov 2011 09:14:26 -0500 Subject: [PATCH] Make the listvms remctl include domains that get stuck in pygrub --- debian/changelog | 6 ++++++ host/usr/sbin/invirt-listvms | 44 ++++++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index 32bc4a7..9a903b8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-remote (0.4.13) unstable; urgency=low + + * Make the listvms remctl include domains that get stuck in pygrub + + -- Mitchell Berger Wed, 23 Nov 2011 09:12:00 -0500 + invirt-remote (0.4.12) unstable; urgency=low * Add DB/LVM disk consistency checker and web/checkdisks remctl diff --git a/host/usr/sbin/invirt-listvms b/host/usr/sbin/invirt-listvms index 9c22f59..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,19 +44,25 @@ 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) - 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 - if 'auto=true' in xsc.read('', '%s/image/cmdline' % data['vm']): + 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 -- 1.7.9.5