Commit e0ac6ce6 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Support migrating instances


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 5823e0d2
......@@ -931,6 +931,29 @@ class GanetiRapiClient(object):
("/%s/instances/%s/export" %
(GANETI_RAPI_VERSION, instance)), None, body)
def MigrateInstance(self, instance, mode=None, cleanup=None):
"""Starts up an instance.
@type instance: string
@param instance: Instance name
@type mode: string
@param mode: Migration mode
@type cleanup: bool
@param cleanup: Whether to clean up a previously failed migration
"""
body = {}
if mode is not None:
body["mode"] = mode
if cleanup is not None:
body["cleanup"] = cleanup
return self._SendRequest(HTTP_PUT,
("/%s/instances/%s/migrate" %
(GANETI_RAPI_VERSION, instance)), None, body)
def GetJobs(self):
"""Gets all jobs for the cluster.
......
......@@ -698,6 +698,31 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
self.assertEqual(data["destination"], "nodeX")
self.assertEqual(data["shutdown"], True)
def testMigrateInstanceDefaults(self):
self.rapi.AddResponse("24873")
job_id = self.client.MigrateInstance("inst91")
self.assertEqual(job_id, 24873)
self.assertHandler(rlib2.R_2_instances_name_migrate)
self.assertItems(["inst91"])
data = serializer.LoadJson(self.rapi.GetLastRequestData())
self.assertFalse(data)
def testMigrateInstance(self):
for mode in constants.HT_MIGRATION_MODES:
for cleanup in [False, True]:
self.rapi.AddResponse("31910")
job_id = self.client.MigrateInstance("inst289", mode=mode,
cleanup=cleanup)
self.assertEqual(job_id, 31910)
self.assertHandler(rlib2.R_2_instances_name_migrate)
self.assertItems(["inst289"])
data = serializer.LoadJson(self.rapi.GetLastRequestData())
self.assertEqual(len(data), 2)
self.assertEqual(data["mode"], mode)
self.assertEqual(data["cleanup"], cleanup)
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