Commit 4fe5cf90 authored by Adeodato Simo's avatar Adeodato Simo

Group operations: OpCode and LU for renaming a group

Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 94bd652a
......@@ -193,6 +193,16 @@ not exist, and the hook is only executed in the master node.
:pre-execution: master node
:post-execution: master node
OP_RENAME_GROUP
+++++++++++++++
Renames a node group.
:directory: group-rename
:env. vars: OLD_NAME, NEW_NAME
:pre-execution: master node and all nodes in the group
:post-execution: master node and all nodes in the group
Instance operations
~~~~~~~~~~~~~~~~~~~
......
......@@ -10533,6 +10533,78 @@ class LURemoveGroup(LogicalUnit):
self.remove_locks[locking.LEVEL_NODEGROUP] = self.group_uuid
class LURenameGroup(LogicalUnit):
HPATH = "group-rename"
HTYPE = constants.HTYPE_GROUP
_OP_PARAMS = [
("old_name", ht.NoDefault, ht.TNonEmptyString),
("new_name", ht.NoDefault, ht.TNonEmptyString),
]
REQ_BGL = False
def ExpandNames(self):
# This raises errors.OpPrereqError on its own:
self.group_uuid = self.cfg.LookupNodeGroup(self.op.old_name)
self.needed_locks = {
locking.LEVEL_NODEGROUP: [self.group_uuid],
}
def CheckPrereq(self):
"""Check prerequisites.
This checks that the given old_name exists as a node group, and that
new_name doesn't.
"""
try:
new_name_uuid = self.cfg.LookupNodeGroup(self.op.new_name)
except errors.OpPrereqError:
pass
else:
raise errors.OpPrereqError("Desired new name '%s' clashes with existing"
" node group (UUID: %s)" %
(self.op.new_name, new_name_uuid),
errors.ECODE_EXISTS)
def BuildHooksEnv(self):
"""Build hooks env.
"""
env = {
"OLD_NAME": self.op.old_name,
"NEW_NAME": self.op.new_name,
}
mn = self.cfg.GetMasterNode()
all_nodes = self.cfg.GetAllNodesInfo()
run_nodes = [mn]
all_nodes.pop(mn, None)
for node in all_nodes.values():
if node.group == self.group_uuid:
run_nodes.append(node.name)
return env, run_nodes, run_nodes
def Exec(self, feedback_fn):
"""Rename the node group.
"""
group = self.cfg.GetNodeGroup(self.group_uuid)
if group is None:
raise errors.OpExecError("Could not retrieve group '%s' (UUID: %s)" %
(self.op.old_name, self.group_uuid))
group.name = self.op.new_name
self.cfg.Update(group, feedback_fn)
return self.op.new_name
class TagsLU(NoHooksLU): # pylint: disable-msg=W0223
"""Generic tags LU.
......
......@@ -192,6 +192,7 @@ class Processor(object):
opcodes.OpAddGroup: cmdlib.LUAddGroup,
opcodes.OpQueryGroups: cmdlib.LUQueryGroups,
opcodes.OpRemoveGroup: cmdlib.LURemoveGroup,
opcodes.OpRenameGroup: cmdlib.LURenameGroup,
# os lu
opcodes.OpDiagnoseOS: cmdlib.LUDiagnoseOS,
# exports lu
......
......@@ -740,6 +740,13 @@ class OpRemoveGroup(OpCode):
__slots__ = ["group_name"]
class OpRenameGroup(OpCode):
"""Rename a node group in the cluster."""
OP_ID = "OP_GROUP_RENAME"
OP_DSC_FIELD = "old_name"
__slots__ = ["old_name", "new_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