1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(logs): failures name their job, VM and user; the new VM form shows a list it could not load

- A failed cancel hook logged "worker task cancel failed": it now names
  the job, its kind, resource and user, with the traceback for a fault
  of the panel.
- novncd logged "Console connection failed" without the VM or the user.
- django-axes wrote four INFO lines a login ("Reset 0 access
  attempts"...); logins are on the Logs page, so it logs warnings only.
- The new VM form's machine types and disk buses answered 200 with an
  empty object when libvirt failed, and nothing was logged: the list
  stayed empty, the form could not go on and said nothing. They answer
  400 with the error, as the pool's volume list does, the warning is
  logged with the compute, and the form's lists show an error they get
  with the page's messages.
This commit is contained in:
catborise 2026-11-06 23:14:08 +03:00
parent 432b1505b3
commit 6abea495f1
14 changed files with 155 additions and 40 deletions

View file

@ -1,9 +1,10 @@
import json
import logging
from admin.decorators import superuser_only
from django.conf import settings
from django.core import signing
from django.http import HttpResponse
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
@ -28,6 +29,8 @@ from computes.models import Compute
from . import utils
logger = logging.getLogger(__name__)
# The host CPU graph sends back the CPU sample of its previous answer; usage
# is taken since then when it is this recent, otherwise over one second.
CPU_SAMPLE_MAX_AGE = 15
@ -227,7 +230,10 @@ def get_compute_disk_buses(request, compute_id, arch, machine, disk):
:return:
"""
comp_mgr = ComputeManager(compute_id)
return HttpResponse(comp_mgr.get_disk_buses(arch, machine, disk), content_type="application/json")
try:
return HttpResponse(comp_mgr.get_disk_buses(arch, machine, disk), content_type="application/json")
except libvirtError as err:
return read_failed(comp_mgr.compute, "disk buses", err)
def get_compute_machine_types(request, compute_id, arch):
@ -238,7 +244,17 @@ def get_compute_machine_types(request, compute_id, arch):
:return:
"""
comp_mgr = ComputeManager(compute_id)
return HttpResponse(comp_mgr.get_machine_types(arch), content_type="application/json")
try:
return HttpResponse(comp_mgr.get_machine_types(arch), content_type="application/json")
except libvirtError as err:
return read_failed(comp_mgr.compute, "machine types", err)
def read_failed(compute, what, err):
"""A list the new VM form loads that the host did not give: not 200 with
an empty list, which the form cannot tell from none."""
logger.warning("Reading the %s of compute %s failed: %s", what, compute.name, err)
return JsonResponse({"error": str(err)}, status=400)
class ComputeManager:
@ -246,30 +262,21 @@ class ComputeManager:
self.compute = get_object_or_404(Compute, pk=compute_id)
def get_machine_types(self, arch):
data = dict()
try:
data["machines"] = self.compute.proxy.get_machine_types(arch)
except libvirtError:
pass
return json.dumps(data)
return json.dumps({"machines": self.compute.proxy.get_machine_types(arch)})
def get_disk_buses(self, arch, machine, disk):
data = dict()
try:
disk_device_types = self.compute.proxy.get_disk_device_types(arch, machine)
disk_device_types = self.compute.proxy.get_disk_device_types(arch, machine)
if disk in disk_device_types:
if disk == "disk":
data["bus"] = sorted(self.compute.proxy.get_disk_bus_types(arch, machine))
elif disk == "cdrom":
data["bus"] = ["ide", "sata", "scsi"]
elif disk == "floppy":
data["bus"] = ["fdc"]
elif disk == "lun":
data["bus"] = ["scsi"]
except libvirtError:
pass
if disk in disk_device_types:
if disk == "disk":
data["bus"] = sorted(self.compute.proxy.get_disk_bus_types(arch, machine))
elif disk == "cdrom":
data["bus"] = ["ide", "sata", "scsi"]
elif disk == "floppy":
data["bus"] = ["fdc"]
elif disk == "lun":
data["bus"] = ["scsi"]
return json.dumps(data)