Commit 70a6a926 authored by Adeodato Simo's avatar Adeodato Simo Committed by Iustin Pop
Browse files

Querying node groups: LU/Opcode

This adds opcodes.OpQueryGroups and cmdlib.LUQueryGroups.
Signed-off-by: default avatarAdeodato Simo <>
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarIustin Pop <>
parent 4f6014d4
......@@ -10224,6 +10224,113 @@ class LURemoveExport(NoHooksLU):
" Domain Name.")
class LUQueryGroups(NoHooksLU):
"""Logical unit for querying node groups.
# pylint: disable-msg=W0142
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
REQ_BGL = False
_FIELDS_DYNAMIC = utils.FieldSet()
_SIMPLE_FIELDS = ["name", "uuid"]
_FIELDS_STATIC = utils.FieldSet(
"node_cnt", "node_list", "pinst_cnt", "pinst_list", *_SIMPLE_FIELDS)
def CheckArguments(self):
def ExpandNames(self):
self.needed_locks = {}
def Exec(self, feedback_fn):
"""Computes the list of groups and their attributes.
all_groups = self.cfg.GetAllNodeGroupsInfo()
if not self.op.names:
my_groups = utils.NiceSort(all_groups.keys())
# Accept names to be either names or UUIDs.
all_uuid = frozenset(all_groups.keys())
name_to_uuid = dict((, g.uuid) for g in all_groups.values())
my_groups = []
missing = []
for name in self.op.names:
if name in all_uuid:
elif name in name_to_uuid:
if missing:
raise errors.OpPrereqError("Some groups do not exist: %s" % missing,
do_nodes = bool(frozenset(["node_cnt", "node_list"]).
do_instances = bool(frozenset(["pinst_cnt", "pinst_list"]).
# We need to map group->[nodes], and group->[instances]. The former is
# directly attainable, but the latter we have to do through instance->node,
# hence we need to process nodes even if we only need instance information.
if do_nodes or do_instances:
all_nodes = self.cfg.GetAllNodesInfo()
group_to_nodes = dict((all_groups[name].uuid, []) for name in my_groups)
node_to_group = {}
for node in all_nodes.values():
if in group_to_nodes:
node_to_group[] =
if do_instances:
all_instances = self.cfg.GetAllInstancesInfo()
group_to_instances = dict((all_groups[name].uuid, [])
for name in my_groups)
for instance in all_instances.values():
node = instance.primary_node
if node in node_to_group:
output = []
for name in my_groups:
group = all_groups[name]
group_output = []
for field in self.op.output_fields:
if field in self._SIMPLE_FIELDS:
val = getattr(group, field)
elif field == "node_list":
val = utils.NiceSort(group_to_nodes[group.uuid])
elif field == "node_cnt":
val = len(group_to_nodes[group.uuid])
elif field == "pinst_list":
val = utils.NiceSort(group_to_instances[group.uuid])
elif field == "pinst_cnt":
val = len(group_to_instances[group.uuid])
raise errors.ParameterError(field)
return output
class TagsLU(NoHooksLU): # pylint: disable-msg=W0223
"""Generic tags LU.
......@@ -188,6 +188,8 @@ class Processor(object):
opcodes.OpQueryInstanceData: cmdlib.LUQueryInstanceData,
opcodes.OpSetInstanceParams: cmdlib.LUSetInstanceParams,
opcodes.OpGrowDisk: cmdlib.LUGrowDisk,
# node group lu
opcodes.OpQueryGroups: cmdlib.LUQueryGroups,
# os lu
opcodes.OpDiagnoseOS: cmdlib.LUDiagnoseOS,
# exports lu
......@@ -700,6 +700,14 @@ class OpGrowDisk(OpCode):
# Node group opcodes
class OpQueryGroups(OpCode):
"""Compute the list of node groups."""
__slots__ = ["output_fields", "names"]
# OS opcodes
class OpDiagnoseOS(OpCode):
"""Compute the list of guest operating systems."""
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