Commit 94497dd1 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rapi: Add resource for modifying node



A separate patch will add “auto-promote” through
“/2/nodes/[node_name]/role”.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent b3d2ee31
......@@ -1326,6 +1326,28 @@ be a job id.
It supports the bool ``force`` argument.
``/2/nodes/[node_name]/modify``
+++++++++++++++++++++++++++++++++
Modifies the parameters of a node. Supports the following commands:
``POST``.
``POST``
~~~~~~~
Returns a job ID.
Body parameters:
.. opcode_params:: OP_NODE_SET_PARAMS
:exclude: node_name
Job result:
.. opcode_result:: OP_NODE_SET_PARAMS
``/2/nodes/[node_name]/storage``
++++++++++++++++++++++++++++++++
......
......@@ -1449,6 +1449,21 @@ class GanetiRapiClient(object): # pylint: disable=R0904
("/%s/nodes/%s/role" %
(GANETI_RAPI_VERSION, node)), query, role)
def ModifyNode(self, group, **kwargs):
"""Modifies a node.
More details for parameters can be found in the RAPI documentation.
@type group: string
@param group: Node name
@rtype: string
@return: job id
"""
return self._SendRequest(HTTP_POST,
("/%s/nodes/%s/modify" %
(GANETI_RAPI_VERSION, group)), None, kwargs)
def GetNodeStorageUnits(self, node, storage_type, output_fields):
"""Gets the storage units for a node.
......
......@@ -177,6 +177,8 @@ def GetHandlers(node_name_pattern, instance_name_pattern,
rlib2.R_2_nodes_name_evacuate,
re.compile(r"^/2/nodes/(%s)/migrate$" % node_name_pattern):
rlib2.R_2_nodes_name_migrate,
re.compile(r"^/2/nodes/(%s)/modify$" % node_name_pattern):
rlib2.R_2_nodes_name_modify,
re.compile(r"^/2/nodes/(%s)/storage$" % node_name_pattern):
rlib2.R_2_nodes_name_storage,
re.compile(r"^/2/nodes/(%s)/storage/modify$" % node_name_pattern):
......
......@@ -497,6 +497,25 @@ class R_2_nodes_name_migrate(baserlib.R_Generic):
return baserlib.SubmitJob([op])
class R_2_nodes_name_modify(baserlib.R_Generic):
"""/2/nodes/[node_name]/modify resource.
"""
def POST(self):
"""Changes parameters of a node.
@return: a job id
"""
baserlib.CheckType(self.request_body, dict, "Body contents")
op = baserlib.FillOpcode(opcodes.OpNodeSetParams, self.request_body, {
"instance_name": self.items[0],
})
return baserlib.SubmitJob([op])
class R_2_nodes_name_storage(baserlib.R_Generic):
"""/2/nodes/[node_name]/storage resource.
......
......@@ -973,6 +973,14 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertQuery("force", ["1"])
self.assertEqual("\"master-candidate\"", self.rapi.GetLastRequestData())
def testModifyNode(self):
self.rapi.AddResponse("3783")
job_id = self.client.ModifyNode("node16979.example.com", drained=True)
self.assertEqual(job_id, 3783)
self.assertHandler(rlib2.R_2_nodes_name_modify)
self.assertItems(["node16979.example.com"])
self.assertEqual(self.rapi.CountPending(), 0)
def testGetNodeStorageUnits(self):
self.rapi.AddResponse("42")
self.assertEqual(42,
......
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