summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2011-01-22 22:13:49 +0000
committerTarmac <>2011-01-22 22:13:49 +0000
commitb6d2d24e778eb6d4b6570246bfe09cba1897d254 (patch)
tree605014146ca297bcfc77afa8c288353192d90280
parent7da2bb5bd74ff94f65bc11af88694aa79b35f5d5 (diff)
parentf5b051bbd0858294157f911ecbb04542fadbb38d (diff)
downloadnova-b6d2d24e778eb6d4b6570246bfe09cba1897d254.tar.gz
nova-b6d2d24e778eb6d4b6570246bfe09cba1897d254.tar.xz
nova-b6d2d24e778eb6d4b6570246bfe09cba1897d254.zip
This patch skips VM shutdown if already in the halted state.
-rw-r--r--nova/virt/xenapi/vmops.py74
1 files changed, 52 insertions, 22 deletions
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 6c2fd6a68..2ccd1ec24 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -252,41 +252,71 @@ class VMOps(object):
raise RuntimeError(resp_dict['message'])
return resp_dict['message']
- def destroy(self, instance):
- """Destroy VM instance"""
- vm = VMHelper.lookup(self._session, instance.name)
- return self._destroy(instance, vm, shutdown=True)
-
- def _destroy(self, instance, vm, shutdown=True):
- """ Destroy VM instance """
- if vm is None:
- # Don't complain, just return. This lets us clean up instances
- # that have already disappeared from the underlying platform.
+ def _shutdown(self, instance, vm):
+ """Shutdown an instance """
+ state = self.get_info(instance['name'])['state']
+ if state == power_state.SHUTDOWN:
+ LOG.warn(_("VM %(vm)s already halted, skipping shutdown...") %
+ locals())
return
- # Get the VDIs related to the VM
+
+ try:
+ task = self._session.call_xenapi('Async.VM.hard_shutdown', vm)
+ self._session.wait_for_task(instance.id, task)
+ except self.XenAPI.Failure, exc:
+ LOG.exception(exc)
+
+ def _destroy_vdis(self, instance, vm):
+ """Destroys all VDIs associated with a VM """
vdis = VMHelper.lookup_vm_vdis(self._session, vm)
- if shutdown:
+
+ if not vdis:
+ return
+
+ for vdi in vdis:
try:
- task = self._session.call_xenapi('Async.VM.hard_shutdown', vm)
+ task = self._session.call_xenapi('Async.VDI.destroy', vdi)
self._session.wait_for_task(instance.id, task)
except self.XenAPI.Failure, exc:
LOG.exception(exc)
- # Disk clean-up
- if vdis:
- for vdi in vdis:
- try:
- task = self._session.call_xenapi('Async.VDI.destroy', vdi)
- self._session.wait_for_task(instance.id, task)
- except self.XenAPI.Failure, exc:
- LOG.exception(exc)
- # VM Destroy
+ def _destroy_vm(self, instance, vm):
+ """Destroys a VM record """
try:
task = self._session.call_xenapi('Async.VM.destroy', vm)
self._session.wait_for_task(instance.id, task)
except self.XenAPI.Failure, exc:
LOG.exception(exc)
+ def destroy(self, instance):
+ """
+ Destroy VM instance
+
+ This is the method exposed by xenapi_conn.destroy(). The rest of the
+ destroy_* methods are internal.
+ """
+ vm = VMHelper.lookup(self._session, instance.name)
+ return self._destroy(instance, vm, shutdown=True)
+
+ def _destroy(self, instance, vm, shutdown=True):
+ """
+ Destroys VM instance by performing:
+
+ 1. A shutdown if requested
+ 2. Destroying associated VDIs
+ 3. Destroying that actual VM record
+ """
+ if vm is None:
+ # Don't complain, just return. This lets us clean up instances
+ # that have already disappeared from the underlying platform.
+ return
+
+ if shutdown:
+ self._shutdown(instance, vm)
+
+ self._destroy_vdis(instance, vm)
+ self._destroy_vm(instance, vm)
+
def _wait_with_callback(self, instance_id, task, callback):
ret = None
try: