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

refactor: the API's serializers and the new VM form no longer need models

Networks, Interfaces, Storages, Storage, Volume, MigrateInstance and
CreateInstance were unmanaged models with no table, there only so that
ModelSerializers and the new VM ModelForm could take their fields. They
made content types and migrations, and their DO_NOTHING foreign keys
added reverse accessors that meant nothing (Compute.host,
Compute.target_host, Instance.source_host).

The serializers are plain Serializers and NewVMForm a Form, field for
field as the models gave them (types, lengths, required, defaults, the
minimum of 1 for vCPUs, memory and disk size; the form's labels are
still derived from the field names). Compared field by field before and
after, the API schema changes only where the models were wrong:
- no int64 bounds on the listing fields;
- the interface fields lose the titles that named the wrong column
  (type was "Status", state "Device", mac "Forward");
- a pool's volumes is a list of objects (it was described as an
  integer) and a volume's allocation an integer (it was untyped).
One migration per app deletes the models; none touches a table.
This commit is contained in:
catborise 2026-11-06 11:06:40 +03:00
parent f3bdeddb0b
commit f1f52aac42
17 changed files with 434 additions and 736 deletions

View file

@ -1,11 +1,10 @@
from rest_framework import serializers
from interfaces.models import Interfaces
class InterfacesSerializer(serializers.ModelSerializer):
class Meta:
model = Interfaces
fields = ['name', 'type', 'state', 'mac']
class InterfacesSerializer(serializers.Serializer):
"""A host interface as the API lists it."""
name = serializers.CharField(max_length=20)
type = serializers.CharField(max_length=12)
state = serializers.CharField(max_length=100)
mac = serializers.CharField(max_length=24)