diff options
| author | Armando Migliaccio <armando.migliaccio@citrix.com> | 2010-11-25 10:46:58 +0000 |
|---|---|---|
| committer | Armando Migliaccio <armando.migliaccio@citrix.com> | 2010-11-25 10:46:58 +0000 |
| commit | 71c358e69c80cbeb349db94be20a4c8cf2222276 (patch) | |
| tree | d1b01edb17014af89ccbe9e7031824eb114fc417 /nova/virt | |
| parent | 9f722a0bcdb987c228f4ebf1e42c904a26d0ef73 (diff) | |
| parent | 07ee9639a105a58b8b212fff607f4e0639d411da (diff) | |
small conflict resolution
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/nova/virt/xenapi.py b/nova/virt/xenapi.py index ec5e7456a..5bf98468e 100644 --- a/nova/virt/xenapi.py +++ b/nova/virt/xenapi.py @@ -289,11 +289,21 @@ class XenAPIConnection(object): # Don't complain, just return. This lets us clean up instances # that have already disappeared from the underlying platform. defer.returnValue(None) + # Get the VDIs related to the VM + vdis = yield self._lookup_vm_vdis(vm) try: task = yield self._call_xenapi('Async.VM.hard_shutdown', vm) yield self._wait_for_task(task) except Exception, exc: logging.warn(exc) + # Disk clean-up + if vdis: + for vdi in vdis: + try: + task = yield self._call_xenapi('Async.VDI.destroy', vdi) + yield self._wait_for_task(task) + except Exception, exc: + logging.warn(exc) try: task = yield self._call_xenapi('Async.VM.destroy', vm) yield self._wait_for_task(task) @@ -402,6 +412,30 @@ class XenAPIConnection(object): True, {}) return sr + @utils.deferredToThread + def _lookup_vm_vdis(self, vm): + return self._lookup_vm_vdis_blocking(vm) + + def _lookup_vm_vdis_blocking(self, vm): + # Firstly we get the VBDs, then the VDIs. + # TODO: do we leave the read-only devices? + vbds = self._conn.xenapi.VM.get_VBDs(vm) + vdis = [] + if vbds: + for vbd in vbds: + try: + vdi = self._conn.xenapi.VBD.get_VDI(vbd) + # Test valid VDI + record = self._conn.xenapi.VDI.get_record(vdi) + except Exception, exc: + logging.warn(exc) + else: + vdis.append(vdi) + if len(vdis) > 0: + return vdis + else: + return None + def _wait_for_task(self, task): """Return a Deferred that will give the result of the given task. The task is polled until it completes.""" |
