Mgmt migrate instance call for reddwarf.

This commit is contained in:
Sudarshan Acharya 2012-09-24 12:41:47 -05:00
parent d69e8f8a56
commit e5c60373c0
6 changed files with 51 additions and 9 deletions

View File

@ -93,7 +93,8 @@ class MgmtInstanceController(InstanceController):
instance = models.MgmtInstance.load(context=context, id=id)
_actions = {
'stop': self._action_stop,
'reboot': self._action_reboot
'reboot': self._action_reboot,
'migrate': self._action_migrate
}
selected_action = None
for key in body:
@ -121,6 +122,11 @@ class MgmtInstanceController(InstanceController):
instance.reboot()
return wsgi.Result(None, 202)
def _action_migrate(self, context, instance, body):
LOG.debug("Migrating instance %s." % instance.id)
instance.migrate()
return wsgi.Result(None, 202)
@admin_context
def root(self, req, tenant_id, id):
"""Return the date and time root was enabled on an instance,

View File

@ -477,6 +477,12 @@ class Instance(BuiltInstance):
self.update_db(task_status=InstanceTasks.REBOOTING)
task_api.API(self.context).restart(self.id)
def migrate(self):
self._validate_can_perform_action()
LOG.info("Migrating instance %s..." % self.id)
self.update_db(task_status=InstanceTasks.MIGRATING)
task_api.API(self.context).migrate(self.id)
def _validate_can_perform_action(self):
"""
Raises exception if an instance action cannot currently be performed.

View File

@ -66,6 +66,7 @@ class InstanceTasks(object):
REBOOTING = InstanceTask(0x03, 'REBOOTING', 'Rebooting the instance.')
RESIZING = InstanceTask(0x04, 'RESIZING', 'Resizing the instance.')
BUILDING = InstanceTask(0x05, 'BUILDING', 'The instance is building.')
MIGRATING = InstanceTask(0x06, 'MIGRATING', 'Migrating the instance.')
BUILDING_ERROR_DNS = InstanceTask(0x50, 'BUILDING', 'Build error: DNS.',
is_error=True)

View File

@ -77,6 +77,10 @@ class API(ManagerAPI):
LOG.debug("Making async call to restart instance: %s" % instance_id)
self._cast("restart", instance_id=instance_id)
def migrate(self, instance_id):
LOG.debug("Making async call to migrate instance: %s" % instance_id)
self._cast("migrate", instance_id=instance_id)
def delete_instance(self, instance_id):
LOG.debug("Making async call to delete instance: %s" % instance_id)
self._cast("delete_instance", instance_id=instance_id)

View File

@ -57,6 +57,10 @@ class TaskManager(service.Manager):
instance_tasks = models.BuiltInstanceTasks.load(context, instance_id)
instance_tasks.restart()
def migrate(self, context, instance_id):
instance_tasks = models.BuiltInstanceTasks.load(context, instance_id)
instance_tasks.migrate()
def delete_instance(self, context, instance_id):
try:
instance_tasks = models.BuiltInstanceTasks.load(context,

View File

@ -336,6 +336,14 @@ class BuiltInstanceTasks(BuiltInstance):
def resize_flavor(self, new_flavor_id, old_memory_size,
new_memory_size):
self._resize_flavor(new_flavor_id, old_memory_size,
new_memory_size)
def migrate(self):
self._resize_flavor()
def _resize_flavor(self, new_flavor_id=None, old_memory_size=None,
new_memory_size=None):
def resize_status_msg():
return "instance_id=%s, status=%s, flavor_id=%s, "\
"dest. flavor id=%s)" % (self.db_info.id,
@ -349,7 +357,12 @@ class BuiltInstanceTasks(BuiltInstance):
try:
LOG.debug("Instance %s calling Compute resize..."
% self.db_info.id)
self.server.resize(new_flavor_id)
if new_flavor_id:
self.server.resize(new_flavor_id)
else:
LOG.debug("Migrating instance %s without flavor change ..."
% self.db_info.id)
self.server.migrate()
# Do initial check and confirm the status is appropriate.
self._refresh_compute_server_info()
@ -369,12 +382,17 @@ class BuiltInstanceTasks(BuiltInstance):
time_out=60 * 2)
# Do check to make sure the status and flavor id are correct.
if (str(self.server.flavor['id']) != str(new_flavor_id) or
self.server.status != "VERIFY_RESIZE"):
msg = "Assertion failed! flavor_id=%s and not %s"
actual_flavor = self.server.flavor['id']
expected_flavor = new_flavor_id
raise ReddwarfError(msg % (actual_flavor, expected_flavor))
if new_flavor_id:
if (str(self.server.flavor['id']) != str(new_flavor_id) or
self.server.status != "VERIFY_RESIZE"):
msg = "Assertion failed! flavor_id=%s and not %s"
actual_flavor = self.server.flavor['id']
expected_flavor = new_flavor_id
raise ReddwarfError(msg % (actual_flavor, expected_flavor))
else:
if (self.server.status != "VERIFY_RESIZE"):
msg = "Migration failed! status=%s and not %s"
raise ReddwarfError(msg % (self.server.status, 'VERIFY_RESIZE'))
# Confirm the resize with Nova.
LOG.debug("Instance %s calling Compute confirm resize..."
@ -397,7 +415,10 @@ class BuiltInstanceTasks(BuiltInstance):
# else MySQL could stay turned off on an otherwise usable
# instance.
LOG.debug("Instance %s starting mysql..." % self.db_info.id)
self.guest.start_mysql_with_conf_changes(new_memory_size)
if new_flavor_id:
self.guest.start_mysql_with_conf_changes(new_memory_size)
else:
self.guest.restart()
finally:
self.update_db(task_status=inst_models.InstanceTasks.NONE)