From 3ddd94f919e69a30ab2c495070a7d01617a5e3a2 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Tue, 26 Jul 2011 11:31:42 +0200 Subject: [PATCH] cmdlib: Factorize mapping instance LVs to node/volume Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cmdlib.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 29dfcc91d..f36ec4524 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -677,6 +677,19 @@ def _ReleaseLocks(lu, level, names=None, keep=None): assert not lu.glm.is_owned(level), "No locks should be owned" +def _MapInstanceDisksToNodes(instances): + """Creates a map from (node, volume) to instance name. + + @type instances: list of L{objects.Instance} + @rtype: dict; tuple of (node name, volume name) as key, instance name as value + + """ + return dict(((node, vol), inst.name) + for inst in instances + for (node, vols) in inst.MapLVsByNode().items() + for vol in vols) + + def _RunPostHook(lu, node_name): """Runs the post-hook for an opcode on a single node. @@ -4254,11 +4267,7 @@ class LUNodeQueryvols(NoHooksLU): volumes = self.rpc.call_node_volumes(nodenames) ilist = self.cfg.GetAllInstancesInfo() - - vol2inst = dict(((node, vol), inst.name) - for inst in ilist.values() - for (node, vols) in inst.MapLVsByNode().items() - for vol in vols) + vol2inst = _MapInstanceDisksToNodes(ilist.values()) output = [] for node in nodenames: -- GitLab