Commit f5eaa3c1 authored by Iustin Pop's avatar Iustin Pop
Browse files

Optimise use of repeated/looping GetNodeInfo

This adds a new ConfigWriter.GetMultiNodeInfo function and replaces
multiple/looping calls to GetNodeInfo with it.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent a4338da2
......@@ -3306,8 +3306,7 @@ class LUClusterSetParams(LogicalUnit):
if self.op.drbd_helper:
# checks given drbd helper on all nodes
helpers = self.rpc.call_drbd_helper(node_list)
for node in node_list:
ninfo = self.cfg.GetNodeInfo(node)
for (node, ninfo) in self.cfg.GetMultiNodeInfo(node_list):
if ninfo.offline:
self.LogInfo("Not checking drbd helper on offline node %s", node)
......@@ -3866,9 +3865,7 @@ class LUOobCommand(NoHooksLU):
if self.op.command in self._SKIP_MASTER:
assert self.master_node not in self.op.node_names
for node_name in self.op.node_names:
node = self.cfg.GetNodeInfo(node_name)
for (node_name, node) in self.cfg.GetMultiNodeInfo(self.op.node_names):
if node is None:
raise errors.OpPrereqError("Node %s not found" % node_name,
......@@ -4616,7 +4613,7 @@ class _InstanceQuery(_QueryBase):
if query.IQ_NODES in self.requested_data:
node_names = set(itertools.chain(*map(operator.attrgetter("all_nodes"),
nodes = dict((name, lu.cfg.GetNodeInfo(name)) for name in node_names)
nodes = dict(lu.cfg.GetMultiNodeInfo(node_names))
groups = dict((uuid, lu.cfg.GetNodeGroup(uuid))
for uuid in set(map(operator.attrgetter("group"),
......@@ -4796,9 +4793,7 @@ class LUNodeAdd(LogicalUnit):
self.changed_primary_ip = False
for existing_node_name in node_list:
existing_node = cfg.GetNodeInfo(existing_node_name)
for existing_node_name, existing_node in cfg.GetMultiNodeInfo(node_list):
if self.op.readd and node == existing_node_name:
if existing_node.secondary_ip != secondary_ip:
raise errors.OpPrereqError("Readded node doesn't have the same IP"
......@@ -7429,10 +7424,8 @@ class TLMigrateInstance(Tasklet):
# directly, or through an iallocator.
self.all_nodes = [self.source_node, self.target_node]
self.nodes_ip = {
self.source_node: self.cfg.GetNodeInfo(self.source_node).secondary_ip,
self.target_node: self.cfg.GetNodeInfo(self.target_node).secondary_ip,
self.nodes_ip = dict((name, node.secondary_ip) for (name, node)
in self.cfg.GetMultiNodeInfo(self.all_nodes))
if self.failover:
feedback_fn("Failover instance %s" %
......@@ -9396,9 +9389,8 @@ class TLReplaceDisks(Tasklet):
# Get secondary node IP addresses
self.node_secondary_ip = \
dict((node_name, self.cfg.GetNodeInfo(node_name).secondary_ip)
for node_name in touched_nodes)
self.node_secondary_ip = dict((name, node.secondary_ip) for (name, node)
in self.cfg.GetMultiNodeInfo(touched_nodes))
def Exec(self, feedback_fn):
"""Execute disk replacement.
......@@ -10377,9 +10369,9 @@ class LUInstanceQueryData(NoHooksLU):
cluster = self.cfg.GetClusterInfo()
for instance in self.wanted_instances:
pnode = self.cfg.GetNodeInfo(instance.primary_node)
pri_nodes = self.cfg.GetMultiNodeInfo(i.primary_node
for i in self.wanted_instances)
for instance, (_, pnode) in zip(self.wanted_instances, pri_nodes):
if self.op.static or pnode.offline:
remote_state = None
if pnode.offline:
......@@ -1447,6 +1447,19 @@ class ConfigWriter:
for node in self._UnlockedGetNodeList()]
return [ for node in all_nodes if not node.vm_capable]
@locking.ssynchronized(_config_lock, shared=1)
def GetMultiNodeInfo(self, nodes):
"""Get the configuration of multiple nodes.
@param nodes: list of node names
@rtype: list
@return: list of tuples of (node, node_info), where node_info is
what would GetNodeInfo return for the node, in the original
return [(name, self._UnlockedGetNodeInfo(name)) for name in nodes]
@locking.ssynchronized(_config_lock, shared=1)
def GetAllNodesInfo(self):
"""Get the configuration of all nodes.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment