Merge "Adding live migration subcommand"

This commit is contained in:
Jenkins 2012-02-02 22:14:51 +00:00 committed by Gerrit Code Review
commit ae10b4bf58
5 changed files with 73 additions and 0 deletions

@ -216,6 +216,16 @@ class Server(base.Resource):
except Exception:
return {}
def live_migrate(self, host,
block_migration=False,
disk_over_commit=False):
"""
Migrates a running instance to a new machine.
"""
self.manager.live_migrate(self, host,
block_migration,
disk_over_commit)
class ServerManager(local_base.BootingManagerWithFind):
resource_class = Server
@ -553,6 +563,21 @@ class ServerManager(local_base.BootingManagerWithFind):
for k in keys:
self._delete("/servers/%s/metadata/%s" % (base.getid(server), k))
def live_migrate(self, server, host, block_migration, disk_over_commit):
"""
Migrates a running instance to a new machine.
:param server: instance id which comes from nova list.
:param host: destination host name.
:param block_migration: if True, do block_migration.
:param disk_over_commit: if True, Allow overcommit.
"""
self._action('os-migrateLive', server,
{'host': host,
'block_migration': block_migration,
'disk_over_commit': disk_over_commit})
def _action(self, action, server, info=None, **kwargs):
"""
Perform a server "action" -- reboot/rebuild/resize/etc.

@ -1501,3 +1501,19 @@ def _print_aggregate_details(aggregate):
columns = ['Id', 'Name', 'Availability Zone', 'Operational State',
'Hosts', 'Metadata']
utils.print_list([aggregate], columns)
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
@utils.arg('host', metavar='<host>', help='destination host name.')
@utils.arg('--block_migrate', action='store_true', dest='block_migrate',
default=False,
help='True in case of block_migration.\
(Default=False:live_migration)')
@utils.arg('--disk_over_commit', action='store_true', dest='disk_over_commit',
default=False,
help='Allow overcommit.(Default=Flase)')
def do_live_migration(cs, args):
"""Migrates a running instance to a new machine."""
_find_server(cs, args.server).live_migrate(args.host,
args.block_migrate,
args.disk_over_commit)

@ -322,6 +322,10 @@ class FakeHTTPClient(base_client.HTTPClient):
return (202, {'output': 'foo'})
elif action == 'os-getVNCConsole':
assert body[action].keys() == ['type']
elif action == 'os-migrateLive':
assert set(body[action].keys()) == set(['host',
'block_migration',
'disk_over_commit'])
else:
raise AssertionError("Unexpected server action: %s" % action)
return (202, _body)

@ -265,3 +265,12 @@ class ServersTest(utils.TestCase):
cs.servers.create_image(s, '123')
cs.assert_called('POST', '/servers/1234/action')
cs.servers.create_image(s, '123', {})
def test_live_migrate_server(self):
s = cs.servers.get(1234)
s.live_migrate(host='hostname', block_migration=False,
disk_over_commit=False)
cs.assert_called('POST', '/servers/1234/action')
cs.servers.live_migrate(s, host='hostname', block_migration=False,
disk_over_commit=False)
cs.assert_called('POST', '/servers/1234/action')

@ -366,3 +366,22 @@ class ShellTest(utils.TestCase):
def test_aggregate_details(self):
self.run_command('aggregate-details 1')
self.assert_called('GET', '/os-aggregates/1')
def test_live_migration(self):
self.run_command('live-migration sample-server hostname')
self.assert_called('POST', '/servers/1234/action',
{'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}})
self.run_command('live-migration sample-server hostname \
--block_migrate')
self.assert_called('POST', '/servers/1234/action',
{'os-migrateLive': {'host': 'hostname',
'block_migration': True,
'disk_over_commit': False}})
self.run_command('live-migration sample-server hostname \
--block_migrate --disk_over_commit')
self.assert_called('POST', '/servers/1234/action',
{'os-migrateLive': {'host': 'hostname',
'block_migration': True,
'disk_over_commit': True}})