def _undefine_domain(self, instance):
    try:
        virt_dom = self._lookup_by_name(instance['name'])
    except exception.InstanceNotFound:
        virt_dom = None
    if virt_dom:
        try:
            try:
                virt_dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
            except libvirt.libvirtError:
                LOG.debug('Error from libvirt during undefineFlags. Retrying with undefine', instance=instance)
                virt_dom.undefine()
            except AttributeError:
                try:
                    if virt_dom.hasManagedSaveImage(0):
                        virt_dom.managedSaveRemove(0)
                except AttributeError:
                    pass
                virt_dom.undefine()
        except libvirt.libvirtError as e:
            with excutils.save_and_reraise_exception():
                errcode = e.get_error_code()
                LOG.error(_LE('Error from libvirt during undefine. Code=%(errcode)s Error=%(e)s'), {'errcode': errcode, 'e': e}, instance=instance)
def _undefine_domain(self, instance):
    try:
        virt_dom = self._lookup_by_name(instance['name'])
    except exception.InstanceNotFound:
        virt_dom = None
    if virt_dom:
        try:
            try:
                virt_dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
            except libvirt.libvirtError:
                LOG.debug('Error from libvirt during undefineFlags. Retrying with undefine', instance=instance)
                virt_dom.undefine()
            except AttributeError:
                try:
                    if virt_dom.hasManagedSaveImage(0):
                        virt_dom.managedSaveRemove(0)
                except AttributeError:
                    pass
                virt_dom.undefine()
        except libvirt.libvirtError as e:
            with excutils.save_and_reraise_exception():
                errcode = e.get_error_code()
                LOG.error(_LE('Error from libvirt during undefine. Code=%(errcode)s Error=%(e)s'), {'errcode': errcode, 'e': e}, instance=instance)