Apply filter properly in LUQuery{Nodes, Instances} v2.0.0alpha0
authorGuido Trotter <ultrotter@google.com>
Thu, 18 Sep 2008 11:13:10 +0000 (11:13 +0000)
committerGuido Trotter <ultrotter@google.com>
Thu, 18 Sep 2008 11:13:10 +0000 (11:13 +0000)
Currently when not locking all nodes/instances are returned, regardless
if the user asked only for some of them. With this patch we return to
the previous behaviour:
  - if no names are specified return info on all current ones
  - if some names are specified and are not found give an error
  - otherwise return only info on the specified names

Reviewed-by: iustinp

lib/cmdlib.py

index e4f143d..3c86387 100644 (file)
@@ -1457,6 +1457,12 @@ class LUQueryNodes(NoHooksLU):
     all_info = self.cfg.GetAllNodesInfo()
     if self.do_locking:
       nodenames = self.acquired_locks[locking.LEVEL_NODE]
+    elif self.wanted != locking.ALL_SET:
+      nodenames = self.wanted
+      missing = set(nodenames).difference(all_info.keys())
+      if missing:
+        raise self.OpExecError(
+          "Some nodes were removed before retrieving their data: %s" % missing)
     else:
       nodenames = all_info.keys()
     nodelist = [all_info[name] for name in nodenames]
@@ -2606,6 +2612,13 @@ class LUQueryInstances(NoHooksLU):
     all_info = self.cfg.GetAllInstancesInfo()
     if self.do_locking:
       instance_names = self.acquired_locks[locking.LEVEL_INSTANCE]
+    elif self.wanted != locking.ALL_SET:
+      instance_names = self.wanted
+      missing = set(instance_names).difference(all_info.keys())
+      if missing:
+        raise self.OpExecError(
+          "Some instances were removed before retrieving their data: %s"
+          % missing)
     else:
       instance_names = all_info.keys()
     instance_list = [all_info[iname] for iname in instance_names]