Commit 94bd652a authored by Adeodato Simo's avatar Adeodato Simo
Browse files

Group operations: OpCode and LU for removing a group

Signed-off-by: default avatarAdeodato Simo <>
Reviewed-by: default avatarMichael Hanselmann <>
parent b1ee5610
......@@ -181,6 +181,18 @@ Adds a node group to the cluster.
:pre-execution: master node
:post-execution: master node
Removes a node group from the cluster. Since the node group must be
empty for removal to succeed, the concept of "nodes in the group" does
not exist, and the hook is only executed in the master node.
:directory: group-remove
:env. vars: GROUP_NAME
:pre-execution: master node
:post-execution: master node
Instance operations
......@@ -10466,6 +10466,73 @@ class LUQueryGroups(NoHooksLU):
return output
class LURemoveGroup(LogicalUnit):
HPATH = "group-remove"
REQ_BGL = False
def ExpandNames(self):
# This will raises errors.OpPrereqError on its own:
self.group_uuid = self.cfg.LookupNodeGroup(self.op.group_name)
self.needed_locks = {
locking.LEVEL_NODEGROUP: [self.group_uuid],
def CheckPrereq(self):
"""Check prerequisites.
This checks that the given group name exists as a node group, that is
empty (i.e., contains no nodes), and that is not the last group of the
# Verify that the group is empty.
group_nodes = [
for node in self.cfg.GetAllNodesInfo().values()
if == self.group_uuid]
if group_nodes:
raise errors.OpPrereqError("Group '%s' not empty, has the following"
" nodes: %s" %
# Verify the cluster would not be left group-less.
if len(self.cfg.GetNodeGroupList()) == 1:
raise errors.OpPrereqError("Group '%s' is the last group in the cluster,"
" which cannot be left without at least one"
" group" % self.op.group_name,
def BuildHooksEnv(self):
"""Build hooks env.
env = {
"GROUP_NAME": self.op.group_name,
mn = self.cfg.GetMasterNode()
return env, [mn], [mn]
def Exec(self, feedback_fn):
"""Remove the node group.
except errors.ConfigurationError:
raise errors.OpExecError("Group '%s' with UUID %s disappeared" %
(self.op.group_name, self.group_uuid))
self.remove_locks[locking.LEVEL_NODEGROUP] = self.group_uuid
class TagsLU(NoHooksLU): # pylint: disable-msg=W0223
"""Generic tags LU.
......@@ -191,6 +191,7 @@ class Processor(object):
# node group lu
opcodes.OpAddGroup: cmdlib.LUAddGroup,
opcodes.OpQueryGroups: cmdlib.LUQueryGroups,
opcodes.OpRemoveGroup: cmdlib.LURemoveGroup,
# os lu
opcodes.OpDiagnoseOS: cmdlib.LUDiagnoseOS,
# exports lu
......@@ -733,6 +733,13 @@ class OpQueryGroups(OpCode):
__slots__ = ["output_fields", "names"]
class OpRemoveGroup(OpCode):
"""Remove a node group from the cluster."""
OP_DSC_FIELD = "group_name"
__slots__ = ["group_name"]
# 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