Commit 4245446f authored by Adeodato Simo's avatar Adeodato Simo
Browse files

Expose OpAssignGroupNodes over RAPI and RAPI client

Signed-off-by: default avatarAdeodato Simo <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 3eff8ae6
......@@ -519,6 +519,24 @@ Body parameters:
New node group name.
Assigns nodes to a group.
Supports the following commands: ``PUT``.
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
Body parameters:
``nodes`` (list, required)
One or more nodes to assign to the group.
......@@ -1531,3 +1531,32 @@ class GanetiRapiClient(object):
return self._SendRequest(HTTP_PUT,
("/%s/groups/%s/rename" %
(GANETI_RAPI_VERSION, group)), None, body)
def AssignGroupNodes(self, group, nodes, force=False, dry_run=False):
"""Assigns nodes to a group.
@type group: string
@param group: Node gropu name
@type nodes: list of strings
@param nodes: List of nodes to assign to the group
@rtype: int
@return: job id
query = []
if force:
query.append(("force", 1))
if dry_run:
query.append(("dry-run", 1))
body = {
"nodes": nodes,
return self._SendRequest(HTTP_PUT,
("/%s/groups/%s/assign-nodes" %
(GANETI_RAPI_VERSION, group)), query, body)
......@@ -223,6 +223,8 @@ def GetHandlers(node_name_pattern, instance_name_pattern,
re.compile(r'^/2/groups/(%s)/rename$' % group_name_pattern):
re.compile(r'^/2/groups/(%s)/assign-nodes$' % group_name_pattern):
"/2/jobs": rlib2.R_2_jobs,
re.compile(r"^/2/jobs/(%s)$" % job_id_pattern):
......@@ -685,6 +685,25 @@ class R_2_groups_name_rename(baserlib.R_Generic):
return baserlib.SubmitJob([op])
class R_2_groups_name_assign_nodes(baserlib.R_Generic):
"""/2/groups/[groupe_name]/assign-nodes resource.
def PUT(self):
"""Assigns nodes to a group.
@return: a job id
op = baserlib.FillOpcode(opcodes.OpAssignGroupNodes, self.request_body, {
"group_name": self.items[0],
"dry_run": self.dryRun(),
"force": self.useForce(),
return baserlib.SubmitJob([op])
def _ParseInstanceCreateRequestVersion1(data, dry_run):
"""Parses an instance creation request version 1.
......@@ -351,6 +351,9 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
def assertDryRun(self):
def assertUseForce(self):
def testEncodeQuery(self):
query = [
("a", None),
......@@ -1045,6 +1048,15 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(job_id, 12348)
def testAssignGroupNodes(self):
job_id = self.client.AssignGroupNodes("mygroup", ["node1", "node2"],
force=True, dry_run=True)
self.assertEqual(job_id, 12349)
def testModifyCluster(self):
for mnh in [None, False, True]:
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