mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 03:36:48 +00:00
feat(operations): the job worker
This commit is contained in:
parent
34582d23f3
commit
a35284bbc9
10 changed files with 791 additions and 50 deletions
|
|
@ -2,47 +2,23 @@ from django.contrib import messages
|
|||
from django.http import JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
import libvirt
|
||||
from libvirt import libvirtError
|
||||
from operations import claims
|
||||
from operations.utils import busy_message, summary
|
||||
from vrtManager.util import ConnectionFailed
|
||||
from operations.utils import busy_message, public_error_text, summary
|
||||
|
||||
API_PREFIX = "/api/"
|
||||
# errors of the connection to the host, not of the operation: both the
|
||||
# domain and the code must match (a daemon that lacks a procedure answers
|
||||
# VIR_FROM_RPC / VIR_ERR_NO_SUPPORT, which the user should see)
|
||||
TRANSPORT_ERROR_DOMAINS = {libvirt.VIR_FROM_RPC, libvirt.VIR_FROM_REMOTE, libvirt.VIR_FROM_SSH, libvirt.VIR_FROM_LIBSSH}
|
||||
TRANSPORT_ERROR_CODES = {
|
||||
libvirt.VIR_ERR_INTERNAL_ERROR, # "connection closed due to keepalive timeout"
|
||||
libvirt.VIR_ERR_SYSTEM_ERROR, # "Cannot recv data: ..."
|
||||
libvirt.VIR_ERR_RPC,
|
||||
libvirt.VIR_ERR_NO_CONNECT,
|
||||
libvirt.VIR_ERR_AUTH_FAILED,
|
||||
libvirt.VIR_ERR_AUTH_UNAVAILABLE,
|
||||
libvirt.VIR_ERR_AUTH_CANCELLED,
|
||||
libvirt.VIR_ERR_SSH,
|
||||
libvirt.VIR_ERR_LIBSSH,
|
||||
}
|
||||
UNREACHABLE = _("The host of this virtual machine cannot be reached right now.")
|
||||
|
||||
|
||||
def error_text(request, exception):
|
||||
"""
|
||||
The libvirt error to show. A connection error names the host and how it
|
||||
is reached, which only administrators (superusers and the global
|
||||
view_instances permission, who see the hosts) get; other users learn
|
||||
that the host cannot be reached.
|
||||
The libvirt error to show. Administrators (superusers and the global
|
||||
view_instances permission, who see the hosts) get the full error; other
|
||||
users the public text.
|
||||
"""
|
||||
connection_error = isinstance(exception, ConnectionFailed) or (
|
||||
isinstance(exception, libvirtError)
|
||||
and exception.get_error_domain() in TRANSPORT_ERROR_DOMAINS
|
||||
and exception.get_error_code() in TRANSPORT_ERROR_CODES
|
||||
)
|
||||
user = getattr(request, "user", None)
|
||||
if connection_error and not (user and (user.is_superuser or user.has_perm("instances.view_instances"))):
|
||||
return str(UNREACHABLE)
|
||||
return str(exception)
|
||||
if user and (user.is_superuser or user.has_perm("instances.view_instances")):
|
||||
return str(exception)
|
||||
return public_error_text(exception)
|
||||
|
||||
|
||||
class ExceptionMiddleware:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue