Make the listvms remctl include domains that get stuck in pygrub 0.4.13
authorMitchell E Berger <mitchb@mit.edu>
Wed, 23 Nov 2011 14:14:26 +0000 (09:14 -0500)
committerMitchell E Berger <mitchb@mit.edu>
Fri, 25 Nov 2011 02:05:27 +0000 (21:05 -0500)
debian/changelog
host/usr/sbin/invirt-listvms

index 32bc4a7..9a903b8 100644 (file)
@@ -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 <mitchb@mit.edu>  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
 invirt-remote (0.4.12) unstable; urgency=low
 
   * Add DB/LVM disk consistency checker and web/checkdisks remctl
index 9c22f59..aeea6d7 100755 (executable)
@@ -11,13 +11,27 @@ def live_vms():
     domids.discard('0')
 
     vms = dict()
     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
 
     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
             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['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)
     # 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
         data['autoinstall'] = True
 
     return name, data