Commit 5823e0d2 authored by Michael Hanselmann's avatar Michael Hanselmann

RAPI: Support migrating instances

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent b2e8a4d9
......@@ -629,6 +629,26 @@ Body parameters:
Destination X509 CA (remote export only).
``/2/instances/[instance_name]/migrate``
++++++++++++++++++++++++++++++++++++++++
Migrates an instance.
Supports the following commands: ``PUT``.
``PUT``
~~~~~~~
Returns a job ID.
Body parameters:
``mode`` (string)
Migration mode.
``cleanup`` (bool)
Whether a previously failed migration should be cleaned up.
``/2/instances/[instance_name]/tags``
+++++++++++++++++++++++++++++++++++++
......
......@@ -209,6 +209,8 @@ def GetHandlers(node_name_pattern, instance_name_pattern, job_id_pattern):
rlib2.R_2_instances_name_prepare_export,
re.compile(r'^/2/instances/(%s)/export$' % instance_name_pattern):
rlib2.R_2_instances_name_export,
re.compile(r'^/2/instances/(%s)/migrate$' % instance_name_pattern):
rlib2.R_2_instances_name_migrate,
"/2/jobs": rlib2.R_2_jobs,
re.compile(r'/2/jobs/(%s)$' % job_id_pattern):
......
......@@ -991,6 +991,38 @@ class R_2_instances_name_export(baserlib.R_Generic):
return baserlib.SubmitJob([op])
def _ParseMigrateInstanceRequest(name, data):
"""Parses a request for an instance migration.
@rtype: L{opcodes.OpMigrateInstance}
@return: Instance migration opcode
"""
mode = baserlib.CheckParameter(data, "mode", default=None)
cleanup = baserlib.CheckParameter(data, "cleanup", exptype=bool,
default=False)
return opcodes.OpMigrateInstance(instance_name=name, mode=mode,
cleanup=cleanup)
class R_2_instances_name_migrate(baserlib.R_Generic):
"""/2/instances/[instance_name]/migrate resource.
"""
def PUT(self):
"""Migrates an instance.
@return: a job id
"""
baserlib.CheckType(self.request_body, dict, "Body contents")
op = _ParseMigrateInstanceRequest(self.items[0], self.request_body)
return baserlib.SubmitJob([op])
class _R_Tags(baserlib.R_Generic):
""" Quasiclass for tagging resources
......
......@@ -223,5 +223,36 @@ class TestParseExportInstanceRequest(testutils.GanetiTestCase):
{ "remove_instance": "False", })
class TestParseMigrateInstanceRequest(testutils.GanetiTestCase):
def setUp(self):
testutils.GanetiTestCase.setUp(self)
self.Parse = rlib2._ParseMigrateInstanceRequest
def test(self):
name = "instYooho6ek"
for cleanup in [False, True]:
for mode in constants.HT_MIGRATION_MODES:
data = {
"cleanup": cleanup,
"mode": mode,
}
op = self.Parse(name, data)
self.assert_(isinstance(op, opcodes.OpMigrateInstance))
self.assertEqual(op.instance_name, name)
self.assertEqual(op.mode, mode)
self.assertEqual(op.cleanup, cleanup)
def testDefaults(self):
name = "instnohZeex0"
op = self.Parse(name, {})
self.assert_(isinstance(op, opcodes.OpMigrateInstance))
self.assertEqual(op.instance_name, name)
self.assertEqual(op.mode, None)
self.assertFalse(op.cleanup)
if __name__ == '__main__':
testutils.GanetiTestProgram()
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