1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/storages/api/serializers.py
catborise 726f330dd0 fix(api): host API checks what the web forms check
- An API volume takes the name and size the web form takes. Its name went
  into the volume XML unchecked, so a name could add elements such as a
  backing store pointing at another VM's disk; the name is also escaped
  there now. A size of 0 and metadata preallocation on a non-qcow2 volume
  are refused or dropped, as on the web form.
- An API compute update with an empty or null password keeps the stored
  one, as the web form does; it emptied it and cut the host off.
- The architectures endpoint answers 404 for an unknown compute instead of
  500; an unrouted copy of it is removed.
2026-10-26 17:47:18 +03:00

28 lines
970 B
Python

from rest_framework import serializers
from storages.models import Storages, Storage, Volume
class StoragesSerializer(serializers.ModelSerializer):
class Meta:
model = Storages
fields = ['name', 'status', 'type', 'size', 'volumes']
class StorageSerializer(serializers.ModelSerializer):
volumes = serializers.ReadOnlyField()
class Meta:
model = Storage
fields = ['state', 'size', 'free', 'status', 'path', 'type', 'autostart', 'volumes']
class VolumeSerializer(serializers.ModelSerializer):
# what the web form (storages.forms.CreateVolumeForm) takes
name = serializers.RegexField(r"^[a-zA-Z0-9._-]+$", max_length=120)
size = serializers.IntegerField(min_value=1) # GiB
allocation = serializers.ReadOnlyField()
meta_prealloc = serializers.BooleanField(write_only=True, default=False)
class Meta:
model = Volume
fields = ['name', 'type', 'allocation', 'size', 'meta_prealloc']