1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(computes): a libvirt host is one compute, and a compute's VMs stay on their host

One host could be added twice, under another name, as TCP and SSH, or by
another address: its VMs were listed once per record, each with its own
owners, and counted twice in the capacity totals. A compute with VMs could
also be pointed at another host: the owners of a VM then reached the
VM with the same UUID there, a restored or copied one.

A compute now keeps its libvirt host UUID. Adding a compute or changing
its connection, on the web or the API, connects and reads it: a host that
is already a compute is refused, and a compute with VMs moves only to an
address of the same host, which must answer. Computes added before are
read when another one is checked.
This commit is contained in:
catborise 2026-11-12 08:42:04 +03:00
parent 2db25314ea
commit 29ec20682b
17 changed files with 567 additions and 259 deletions

View file

@ -1,3 +1,5 @@
from copy import copy
from computes.models import Compute
from computes.validators import validate_gstfsd_key
from rest_framework import serializers
@ -35,6 +37,14 @@ class ComputeSerializer(serializers.ModelSerializer):
def validate_gstfsd_key(self, value):
return value or (self.instance.gstfsd_key if self.instance else value)
def validate(self, attrs):
# as the web form: the connection is tried and its host checked (Compute.clean)
compute = copy(self.instance) if self.instance else Compute()
for field, value in attrs.items():
setattr(compute, field, value)
compute.clean()
return {**attrs, "host_uuid": compute.host_uuid}
class Meta:
model = Compute
fields = ["id", "name", "hostname", "login", "password", "type", "details", "migration_address", "gstfsd_key"]