'Retrieve libvirt domain object for an instance.
All libvirt error handling should be handled in this method and
relevant nova exceptions should be raised in response.
:param instance: a nova.objects.Instance object
:returns: a libvirt.Domain object
:raises exception.InstanceNotFound: The domain was not found
:raises exception.InternalError: A libvirt error occurred'

def get_domain(self, instance):

    try:
        conn = self.get_connection()
        return conn.lookupByName(instance.name)
    except libvirt.libvirtError as ex:
        error_code = ex.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_DOMAIN):
            raise exception.InstanceNotFound(instance_id=instance.uuid)
        msg = (_('Error    from    libvirt    while    looking    up    %(instance_name)s:    [Error    Code    %(error_code)s]    %(ex)s') % {'instance_name': instance.name, 'error_code': error_code, 'ex': ex})
        raise exception.InternalError(msg)
