mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
feat(logs): every VM operation writes an audit row the VM's Logs tab finds by UUID
Operations on a VM now write their rows the way the admin audit does: one
row per operation, done or failed with a safe reason, with the user, IP and
host. Each row names the VM ("VM web-1: delete snapshot snap1") and carries
its UUID in the new Logs.instance_uuid column.
- audit_vm and failed_vm wrap audit() and failed() for a VM. A failure the
view turns into a message is caught outside the block, so its failed row
is written; busy claims, permission and quota refusals and invalid input
write nothing. No password, key or XML goes into a row.
- All VM page operations move from addlogmsg to audit_vm, and addlogmsg
goes. QoS changes and defining a VM from XML are logged now; a gstfsd
error reply (root password, SSH key) is a failed row, not a done one.
- Partial results are rows of their own: the VM delete, then each disk
delete; the disk detach, then the volume delete; the migration, then a
failed autostart restore, NVRAM removal or record on the target.
- Migration rows use the compute name as the host column, as every other
row does.
- VM job rows (create, clone, snapshots) and their resolutions carry the
VM's UUID; snapshot job intents now record it. The owner rows of the VM
page and the accounts pages, and the ownership system rows, carry it too.
- The Logs tab loads vm_logs/<pk>/ and shows the rows with the VM's UUID,
so a rename keeps the history, two VMs with one name are told apart and
a VM on two computes is one VM. It gains a Result column. Rows from
before this change have no UUID and stay on the Logs page only.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
49cf16ecbe
commit
c1d36053d6
24 changed files with 639 additions and 524 deletions
|
|
@ -1,44 +1,25 @@
|
|||
import logging
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from admin.decorators import superuser_only
|
||||
from instances.models import Instance
|
||||
from logs.audit import write
|
||||
from logs.models import Logs
|
||||
|
||||
|
||||
def addlogmsg(user, host, instance, message):
|
||||
"""
|
||||
:param user:
|
||||
:param host:
|
||||
:param instance:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
write(user, host, instance, str(message))
|
||||
logger = logging.getLogger("")
|
||||
logger.info(f"{user} {host} {instance} {message}")
|
||||
|
||||
|
||||
@superuser_only
|
||||
def vm_logs(request, vname):
|
||||
"""
|
||||
:param request:
|
||||
:param vname:
|
||||
:return:
|
||||
"""
|
||||
|
||||
vm = Instance.objects.get(name=vname)
|
||||
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by("-date")
|
||||
def vm_logs(request, pk):
|
||||
"""The rows of a VM, found by its UUID: a rename keeps them, and a VM on two computes is one VM."""
|
||||
vm = get_object_or_404(Instance, pk=pk)
|
||||
results = {None: _("Unknown"), True: _("Done"), False: _("Failed")}
|
||||
logs = []
|
||||
for l in logs_:
|
||||
log = dict()
|
||||
log["user"] = l.user
|
||||
log["host"] = l.host
|
||||
log["instance"] = l.instance
|
||||
log["message"] = l.message
|
||||
log["date"] = l.date.strftime("%x %X")
|
||||
logs.append(log)
|
||||
|
||||
for log in Logs.objects.filter(instance_uuid=vm.uuid).order_by("-date", "-id"):
|
||||
logs.append({
|
||||
"user": log.user,
|
||||
"host": log.host,
|
||||
"instance": log.instance,
|
||||
"message": log.message,
|
||||
"result": results[log.success],
|
||||
"date": log.date.strftime("%x %X"),
|
||||
})
|
||||
return JsonResponse(logs, safe=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue