Commit 8bf9e9a5 authored by Iustin Pop's avatar Iustin Pop
Browse files

ConfigWriter: add some helper functions

This can be used to compute a node's instances easily, and a small
function to get all non-vm_capable nodes.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarGuido Trotter <>
parent b8d26c6e
......@@ -1139,6 +1139,25 @@ class ConfigWriter:
return self._UnlockedGetNodeInfo(node_name)
@locking.ssynchronized(_config_lock, shared=1)
def GetNodeInstances(self, node_name):
"""Get the instances of a node, as stored in the config.
@param node_name: the node name, e.g. I{}
@rtype: (list, list)
@return: a tuple with two lists: the primary and the secondary instances
pri = []
sec = []
for inst in self._config_data.instances.values():
if inst.primary_node == node_name:
if node_name in inst.secondary_nodes:
return (pri, sec)
def _UnlockedGetNodeList(self):
"""Return the list of nodes which are in the configuration.
......@@ -1172,6 +1191,15 @@ class ConfigWriter:
return self._UnlockedGetOnlineNodeList()
@locking.ssynchronized(_config_lock, shared=1)
def GetNonVmCapableNodeList(self):
"""Return the list of nodes which are not vm capable.
all_nodes = [self._UnlockedGetNodeInfo(node)
for node in self._UnlockedGetNodeList()]
return [ for node in all_nodes if not node.vm_capable]
@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