Commit d654aae1 authored by Michael Hanselmann's avatar Michael Hanselmann

RAPI client: Support renaming instances

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent d56e7dc7
......@@ -971,6 +971,33 @@ class GanetiRapiClient(object):
("/%s/instances/%s/migrate" %
(GANETI_RAPI_VERSION, instance)), None, body)
def RenameInstance(self, instance, new_name, ip_check=None, name_check=None):
"""Changes the name of an instance.
@type instance: string
@param instance: Instance name
@type new_name: string
@param new_name: New instance name
@type ip_check: bool
@param ip_check: Whether to ensure instance's IP address is inactive
@type name_check: bool
@param name_check: Whether to ensure instance's name is resolvable
"""
body = {
"new_name": new_name,
}
if ip_check is not None:
body["ip_check"] = ip_check
if name_check is not None:
body["name_check"] = name_check
return self._SendRequest(HTTP_PUT,
("/%s/instances/%s/rename" %
(GANETI_RAPI_VERSION, instance)), None, body)
def GetJobs(self):
"""Gets all jobs for the cluster.
......
......@@ -741,6 +741,35 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(data["mode"], mode)
self.assertEqual(data["cleanup"], cleanup)
def testRenameInstanceDefaults(self):
new_name = "newnametha7euqu"
self.rapi.AddResponse("8791")
job_id = self.client.RenameInstance("inst18821", new_name)
self.assertEqual(job_id, 8791)
self.assertHandler(rlib2.R_2_instances_name_rename)
self.assertItems(["inst18821"])
data = serializer.LoadJson(self.rapi.GetLastRequestData())
self.assertEqualValues(data, {"new_name": new_name, })
def testRenameInstance(self):
new_name = "new-name-yiux1iin"
for ip_check in [False, True]:
for name_check in [False, True]:
self.rapi.AddResponse("24776")
job_id = self.client.RenameInstance("inst20967", new_name,
ip_check=ip_check,
name_check=name_check)
self.assertEqual(job_id, 24776)
self.assertHandler(rlib2.R_2_instances_name_rename)
self.assertItems(["inst20967"])
data = serializer.LoadJson(self.rapi.GetLastRequestData())
self.assertEqual(len(data), 3)
self.assertEqual(data["new_name"], new_name)
self.assertEqual(data["ip_check"], ip_check)
self.assertEqual(data["name_check"], name_check)
def testGetJobs(self):
self.rapi.AddResponse('[ { "id": "123", "uri": "\\/2\\/jobs\\/123" },'
' { "id": "124", "uri": "\\/2\\/jobs\\/124" } ]')
......
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