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

RAPI client: Support migrating instances

Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
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):
job_id = self.client.MigrateInstance("inst91")
self.assertEqual(job_id, 24873)
data = serializer.LoadJson(self.rapi.GetLastRequestData())
def testMigrateInstance(self):
for mode in constants.HT_MIGRATION_MODES:
for cleanup in [False, True]:
job_id = self.client.MigrateInstance("inst289", mode=mode,
self.assertEqual(job_id, 31910)
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