Commit 4da7909a authored by Adeodato Simo's avatar Adeodato Simo
Browse files

Add modification of node groups (OpCode/LU/CLI)

With this commit, only modification of the "ndparams" attribute is
Signed-off-by: default avatarAdeodato Simo <>
Reviewed-by: default avatarGuido Trotter <>
parent 483be60d
......@@ -105,6 +105,36 @@ def ListGroups(opts, args):
return 0
def SetGroupParams(opts, args):
"""Modifies a node group's parameters.
@param opts: the command line options seletect by the user
@type args: list
@param args: should contain only one element, the node group name
@rtype: int
@return: the desired exit code
all_changes = {
"ndparams": opts.ndparams,
if all_changes.values().count(None) == len(all_changes):
ToStderr("Please give at least one of the parameters.")
return 1
op = opcodes.OpSetGroupParams(group_name=args[0], **all_changes)
result = SubmitOrSend(op, opts)
if result:
ToStdout("Modified node group %s", args[0])
for param, data in result:
ToStdout(" - %-5s -> %s", param, data)
return 0
def RemoveGroup(opts, args):
"""Remove a node group from the cluster.
......@@ -146,6 +176,10 @@ commands = {
"Lists the node groups in the cluster. The available fields are (see"
" the man page for details): %s. The default list is (in order): %s." %
(utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
"modify": (
SetGroupParams, ARGS_ONE_GROUP,
"<group_name>", "Alters the parameters of a node group"),
"remove": (
"[--dry-run] <group_name>",
......@@ -10341,6 +10341,66 @@ class LUQueryGroups(NoHooksLU):
return output
class LUSetGroupParams(LogicalUnit):
"""Modifies the parameters of a node group.
HPATH = None
HTYPE = None
("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
REQ_BGL = False
def CheckArguments(self):
all_changes = [
if all_changes.count(None) == len(all_changes):
raise errors.OpPrereqError("Please pass at least one modification",
def ExpandNames(self):
# This 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.
""" = self.cfg.GetNodeGroup(self.group_uuid)
if is None:
raise errors.OpExecError("Could not retrieve group '%s' (UUID: %s)" %
(self.op.group_name, self.group_uuid))
if self.op.ndparams:
utils.ForceDictType(self.op.ndparams, constants.NDS_PARAMETER_TYPES)
self.new_ndparams =
def Exec(self, feedback_fn):
"""Modifies the node group.
result = []
if self.op.ndparams: = self.new_ndparams
result.append(("ndparams", str(
self.cfg.Update(, feedback_fn)
return result
class LURemoveGroup(LogicalUnit):
HPATH = "group-remove"
......@@ -191,6 +191,7 @@ class Processor(object):
# node group lu
opcodes.OpAddGroup: cmdlib.LUAddGroup,
opcodes.OpQueryGroups: cmdlib.LUQueryGroups,
opcodes.OpSetGroupParams: cmdlib.LUSetGroupParams,
opcodes.OpRemoveGroup: cmdlib.LURemoveGroup,
opcodes.OpRenameGroup: cmdlib.LURenameGroup,
# os lu
......@@ -737,6 +737,16 @@ class OpQueryGroups(OpCode):
__slots__ = ["output_fields", "names"]
class OpSetGroupParams(OpCode):
"""Change the parameters of a node group."""
OP_DSC_FIELD = "group_name"
__slots__ = [
class OpRemoveGroup(OpCode):
"""Remove a node group from the cluster."""
......@@ -34,6 +34,18 @@ The ``--node-parameters`` option allows you to set default node
parameters for nodes in the group. Please see **ganeti**(7) for more
information about supported key=value pairs.
| **modify**
| [--node-parameters=*NDPARAMS*]
| {*group*}
Modifies some parameters from the node group.
The ``--node-parameters`` option is documented in the **add** command
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