gnt-node volumes: Fix instance names
authorMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 08:27:09 +0000 (10:27 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 09:00:00 +0000 (11:00 +0200)
Commit 84d7e26b changed “objects.Instance.MapLVsByN” to not just return
the LV name, but to include the volume group name (e.g.
“xenvg/d67e8700….disk0_data”). This in turn broke the mapping of volume
names in LUNodeQueryvols, stopping instance names from displayed in
“gnt-node volumes”.

This patch fixes the issue and does some cleanup.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/cmdlib.py

index b3a40a2..1e754af 100644 (file)
@@ -40,6 +40,7 @@ import socket
 import tempfile
 import shutil
 import itertools
+import operator
 
 from ganeti import ssh
 from ganeti import utils
@@ -3770,10 +3771,12 @@ class LUNodeQueryvols(NoHooksLU):
     nodenames = self.acquired_locks[locking.LEVEL_NODE]
     volumes = self.rpc.call_node_volumes(nodenames)
 
-    ilist = [self.cfg.GetInstanceInfo(iname) for iname
-             in self.cfg.GetInstanceList()]
+    ilist = self.cfg.GetAllInstancesInfo()
 
-    lv_by_node = dict([(inst, inst.MapLVsByNode()) for inst in ilist])
+    vol2inst = dict(((node, vol), inst.name)
+                    for inst in ilist.values()
+                    for (node, vols) in inst.MapLVsByNode().items()
+                    for vol in vols)
 
     output = []
     for node in nodenames:
@@ -3785,8 +3788,8 @@ class LUNodeQueryvols(NoHooksLU):
         self.LogWarning("Can't compute volume data on node %s: %s", node, msg)
         continue
 
-      node_vols = nresult.payload[:]
-      node_vols.sort(key=lambda vol: vol['dev'])
+      node_vols = sorted(nresult.payload,
+                         key=operator.itemgetter("dev"))
 
       for vol in node_vols:
         node_output = []
@@ -3802,14 +3805,7 @@ class LUNodeQueryvols(NoHooksLU):
           elif field == "size":
             val = int(float(vol['size']))
           elif field == "instance":
-            for inst in ilist:
-              if node not in lv_by_node[inst]:
-                continue
-              if vol['name'] in lv_by_node[inst][node]:
-                val = inst.name
-                break
-            else:
-              val = '-'
+            val = vol2inst.get((node, vol["vg"] + "/" + vol["name"]), "-")
           else:
             raise errors.ParameterError(field)
           node_output.append(str(val))