mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
Cloud images read their first-boot settings with cloud-init. The panel served them only over HTTP, which a VM reaches only with the network and a reverse DNS name for its address. A new VM can now carry them itself: Cloud-init seed (Advanced) on the create form, or cloud_init in the API. The job writes a NoCloud seed, an ISO labelled cidata, into the disk's directory pool as cidata-<uuid>.iso and puts it in the VM's CD-ROM drive. Its meta-data holds the VM's UUID as instance-id and its name as hostname, written as JSON so a VM named 123 or yes keeps a string hostname; its user-data is what the HTTP datasource serves, with the creating user's SSH keys. The ISO is built with pycdlib and written through a libvirt stream, as the NVRAM copy is, now one helper for both. A seed needs a CD-ROM bus and a directory pool, else the create is refused. A failed create deletes the seed with the new disk, recovery names one left behind, and deleting the VM with its disks deletes its seed, found in the pools by name even when ejected. A clone's drive is left empty: the seed is the source VM's identity.
113 lines
3.1 KiB
Python
113 lines
3.1 KiB
Python
from instances.models import CreateInstance, Flavor, Instance, MigrateInstance
|
|
from instances.utils import nic_macs
|
|
from rest_framework import serializers
|
|
|
|
|
|
class InstanceSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Instance
|
|
fields = ["id", "compute", "name", "uuid", "is_template", "created", "drbd"]
|
|
|
|
|
|
class InstanceDetailsSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Instance
|
|
fields = [
|
|
"id",
|
|
"compute",
|
|
"status",
|
|
"uuid",
|
|
"name",
|
|
"title",
|
|
"description",
|
|
"is_template",
|
|
"created",
|
|
"drbd",
|
|
"arch",
|
|
"machine",
|
|
"vcpu",
|
|
"memory",
|
|
"firmware",
|
|
"nvram",
|
|
"bootmenu",
|
|
"boot_order",
|
|
"disks",
|
|
"media",
|
|
"media_iso",
|
|
"snapshots",
|
|
"networks",
|
|
"console_type",
|
|
"console_port",
|
|
"console_keymap",
|
|
"console_listener_address",
|
|
"video_model",
|
|
"guest_agent_ready",
|
|
"autostart",
|
|
]
|
|
|
|
|
|
class FlavorSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Flavor
|
|
fields = ["label", "memory", "vcpu", "disk"]
|
|
|
|
|
|
class CreateInstanceSerializer(serializers.ModelSerializer):
|
|
video = serializers.CharField(initial="vga")
|
|
storage = serializers.CharField(initial="default")
|
|
cache_mode = serializers.CharField(initial="none")
|
|
virtio = serializers.BooleanField(initial=True)
|
|
qemu_ga = serializers.BooleanField(initial=True)
|
|
submission_key = serializers.CharField(write_only=True)
|
|
|
|
def validate(self, attrs):
|
|
try:
|
|
nic_macs(attrs.get("mac"), attrs.get("networks", ""))
|
|
except ValueError as err:
|
|
raise serializers.ValidationError({"mac": str(err)})
|
|
return attrs
|
|
|
|
class Meta:
|
|
model = CreateInstance
|
|
fields = [
|
|
"name",
|
|
"vcpu",
|
|
"vcpu_mode",
|
|
"memory",
|
|
"networks",
|
|
"mac",
|
|
"nwfilter",
|
|
"storage",
|
|
"hdd_size",
|
|
"cache_mode",
|
|
"meta_prealloc",
|
|
"virtio",
|
|
"qemu_ga",
|
|
"cloud_init",
|
|
"video",
|
|
"listener_addr",
|
|
"submission_key",
|
|
]
|
|
|
|
|
|
class MigrateSerializer(serializers.ModelSerializer):
|
|
instance = Instance.objects.all().prefetch_related("userinstance_set")
|
|
live = serializers.BooleanField(initial=True)
|
|
# left out, also from a form-encoded request: auto converge on
|
|
autoconverge = serializers.BooleanField(default=True)
|
|
compress = serializers.BooleanField(default=False)
|
|
unsafe = serializers.BooleanField(default=False)
|
|
submission_key = serializers.CharField(write_only=True)
|
|
|
|
class Meta:
|
|
model = MigrateInstance
|
|
fields = [
|
|
"instance",
|
|
"target_compute",
|
|
"live",
|
|
"offline",
|
|
"autoconverge",
|
|
"compress",
|
|
"unsafe",
|
|
"submission_key",
|
|
]
|