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

Expose OpAssignGroupNodes over RAPI and RAPI client

Signed-off-by: default avatarAdeodato Simo <dato@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 3eff8ae6
......@@ -519,6 +519,24 @@ Body parameters:
New node group name.
``/2/groups/[group_name]/assign-nodes``
+++++++++++++++++++++++++++++++++++++++
Assigns nodes to a group.
Supports the following commands: ``PUT``.
``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.
``/2/instances``
++++++++++++++++
......
......@@ -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,
rlib2.R_2_groups_name_modify,
re.compile(r'^/2/groups/(%s)/rename$' % group_name_pattern):
rlib2.R_2_groups_name_rename,
re.compile(r'^/2/groups/(%s)/assign-nodes$' % group_name_pattern):
rlib2.R_2_groups_name_assign_nodes,
"/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):
self.assertTrue(self.rapi.GetLastHandler().dryRun())
def assertUseForce(self):
self.assertTrue(self.rapi.GetLastHandler().useForce())
def testEncodeQuery(self):
query = [
("a", None),
......@@ -1045,6 +1048,15 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(job_id, 12348)
self.assertHandler(rlib2.R_2_groups_name_modify)
def testAssignGroupNodes(self):
self.rapi.AddResponse("12349")
job_id = self.client.AssignGroupNodes("mygroup", ["node1", "node2"],
force=True, dry_run=True)
self.assertEqual(job_id, 12349)
self.assertHandler(rlib2.R_2_groups_name_assign_nodes)
self.assertDryRun()
self.assertUseForce()
def testModifyCluster(self):
for mnh in [None, False, True]:
self.rapi.AddResponse("14470")
......
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