1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +00:00

fix(computes): a compute is not edited while a job on it is admitted

A job resolves its compute's connection when it runs. Changing the
compute's hostname meanwhile sent the job to another host, where a VM
with the same UUID (a copy) could be deleted or changed instead. An edit
now holds the compute as a delete does, and is refused while a job or VM
operation on it is admitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-09 21:23:16 +03:00
parent a2f4d3fe06
commit 12e33f7964
3 changed files with 15 additions and 2 deletions

View file

@ -1,5 +1,6 @@
from admin.permissions import IsSuperUser
from computes.models import Compute
from computes.utils import libvirt_compute_lock
from django.shortcuts import get_object_or_404
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema
@ -30,7 +31,7 @@ class ComputeViewSet(viewsets.ModelViewSet):
compute = serializer.instance
subject = f"Compute {compute.name} ({compute.hostname})"
before = snapshot(compute)
with audit(self.request, compute, subject, "change") as entry:
with audit(self.request, compute, subject, "change") as entry, libvirt_compute_lock(compute):
serializer.save()
fields = changed_fields(before, snapshot(compute))
entry.action = "change " + ", ".join(fields)