summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin SB <justin@fathomdb.com>2011-04-09 12:33:24 -0700
committerJustin SB <justin@fathomdb.com>2011-04-09 12:33:24 -0700
commitbe386ee614777212da2a14ebd8211f4b3d90ce66 (patch)
tree3f21d93d2c7e0007c6c4ce78ebe1a702ef0b109d
parenta572b49e376cd6da4265c2807eaed8f0a2daf954 (diff)
Split logic on shutdown and undefine, so that even if the machine is already shutdown we will be able to proceed
-rw-r--r--nova/virt/libvirt_conn.py53
1 files changed, 40 insertions, 13 deletions
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 1ad6f8b32..47eb17abb 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -309,20 +309,47 @@ class LibvirtConnection(driver.ComputeDriver):
return infos
def destroy(self, instance, cleanup=True):
- name = instance['name']
+ instance_name = instance['name']
+
+ # TODO(justinsb): Refactor all lookupByName calls for error-handling
try:
- virt_dom = self._conn.lookupByName(name)
- virt_dom.destroy()
- # NOTE(justinsb): We remove the domain definition. We probably
- # would do better to keep it if cleanup=False (e.g. volumes?)
- # (e.g. #2 - not losing machines on failure)
- virt_dom.undefine()
- except Exception as e:
- # TODO(justinsb): We really should check the error is 'not found'
- LOG.warn(_("Ignoring error destroying domain %(name)s: %(e)s") %
- locals())
- pass
- # If the instance is already terminated, we're still happy
+ virt_dom = self._conn.lookupByName(instance_name)
+ except libvirt.libvirtError as e:
+ errcode = e.get_error_code()
+ if errcode == libvirt.VIR_ERR_NO_DOMAIN:
+ virt_dom = None
+ else:
+ LOG.warning(_("Error from libvirt during lookup of "
+ "%(instance_name)s. Code=%(errcode)s "
+ "Error=%(e)s") %
+ locals())
+ raise
+
+ # If the instance is already terminated, we're still happy
+ # Otherwise, destroy it
+ if virt_dom is not None:
+ try:
+ virt_dom.destroy()
+ except libvirt.libvirtError as e:
+ errcode = e.get_error_code()
+ LOG.warning(_("Error from libvirt during destroy of "
+ "%(instance_name)s. Code=%(errcode)s "
+ "Error=%(e)s") %
+ locals())
+ raise
+
+ try:
+ # NOTE(justinsb): We remove the domain definition. We probably
+ # would do better to keep it if cleanup=False (e.g. volumes?)
+ # (e.g. #2 - not losing machines on failure)
+ virt_dom.undefine()
+ except libvirt.libvirtError as e:
+ errcode = e.get_error_code()
+ LOG.warning(_("Error from libvirt during undefine of "
+ "%(instance_name)s. Code=%(errcode)s "
+ "Error=%(e)s") %
+ locals())
+ raise
# We'll save this for when we do shutdown,
# instead of destroy - but destroy returns immediately