summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorKravchenko Pavel <kpavel@il.ibm.com>2013-02-04 18:21:18 +0200
committerKravchenko Pavel <kpavel@il.ibm.com>2013-02-04 18:21:18 +0200
commit064fefb810eab07d4ddde3dd50537a6236567423 (patch)
treee7b710ac88d17b42cff45dc5e4ad6a6c3d506ce2 /nova/compute
parent47bbf12a6c9705e5abca29a1d44b753c8506505d (diff)
Adds evacuate method to compute.api
Added decorator to check whether the vm is suitable to be evacuated. The decorator validates that vm host is down. The new evacuate method calls rebuild with the recreate flag and specified target host. This implements blueprint rebuild-for-ha DocImpact Change-Id: I877b29928c922fa366fb85deb85ddfc72d97daf8 Co-authored-by: Oshrit Feder <oshritf@il.ibm.com>
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py33
-rw-r--r--nova/compute/cells_api.py7
2 files changed, 40 insertions, 0 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 034b875a6..7ce0a74b8 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2320,6 +2320,39 @@ class API(base.Base):
self.scheduler_rpcapi.live_migration(context, block_migration,
disk_over_commit, instance, host_name)
+ @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.STOPPED],
+ task_state=[None])
+ def evacuate(self, context, instance, host, on_shared_storage,
+ admin_password=None):
+ """Running evacuate to target host.
+
+ Checking vm compute host state, if the host not in expected_state,
+ raising an exception.
+ """
+ LOG.debug(_('vm evacuation scheduled'))
+ host = instance['host']
+ service = self.db.service_get_by_compute_host(context, host)
+ if self.servicegroup_api.service_is_up(service):
+ msg = (_('Instance compute service state on %(host)s '
+ 'expected to be down, but it was up.'
+ ) % locals())
+ LOG.error(msg)
+ raise exception.ComputeServiceUnavailable(msg)
+
+ instance = self.update(context, instance, expected_task_state=None,
+ task_state=task_states.REBUILDING)
+ return self.compute_rpcapi.rebuild_instance(context,
+ instance=instance,
+ new_pass=admin_password,
+ injected_files=None,
+ image_ref=None,
+ orig_image_ref=None,
+ orig_sys_metadata=None,
+ bdms=None,
+ recreate=True,
+ on_shared_storage=on_shared_storage,
+ host=host)
+
class HostAPI(base.Base):
"""Sub-set of the Compute Manager API for managing host operations."""
diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py
index d5427a04b..f3a6fb1af 100644
--- a/nova/compute/cells_api.py
+++ b/nova/compute/cells_api.py
@@ -278,6 +278,13 @@ class ComputeCellsAPI(compute_api.API):
**kwargs)
self._cast_to_cells(context, instance, 'rebuild', *args, **kwargs)
+ @validate_cell
+ def evacuate(self, context, instance, *args, **kwargs):
+ """Evacuate the given instance with the provided attributes."""
+ super(ComputeCellsAPI, self).evacuate(context, instance, *args,
+ **kwargs)
+ self._cast_to_cells(context, instance, 'evacuate', *args, **kwargs)
+
@check_instance_state(vm_state=[vm_states.RESIZED])
@validate_cell
def revert_resize(self, context, instance):