mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
The Settings page saved whatever was posted, and some lists offered values the panel cannot use: - Quota Debug could not be turned off: "False" is a non-empty text and counted as on. - VM Clone Name Prefix showed as a True/False list, so no prefix could be typed, and touching it set the prefix to True. - Disk SCSI Controller listed " lsilogic" with a space, never shown as chosen, and virtio-blk, which is no SCSI controller. - VM Machine Type listed x86_64, an architecture; VM CD-ROM Device listed virtio, a bus a CD-ROM cannot use. - Logs per Page and Disk Owner UID/GID are read with int(): a letter broke the logs page and VM create. A migration fixes the lists and moves a value they no longer offer to the default (the clone prefix keeps its text). A listed setting now takes one of its choices, and every number setting a whole number in its range, checked before it is saved.
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from django.db import migrations
|
|
|
|
# key: (its choices, the value a removed choice becomes)
|
|
FIXES = {
|
|
"CLONE_INSTANCE_DEFAULT_PREFIX": ("", None), # a text, not True or False
|
|
"INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER": ("virtio-scsi,lsilogic", "virtio-scsi"), # virtio-blk is no SCSI controller
|
|
"INSTANCE_MACHINE_DEFAULT_TYPE": ("q35,pc,virt", "q35"), # x86_64 is an architecture
|
|
"INSTANCE_CDROM_ADD": ("None,ide,sata,scsi", "sata"), # a CD-ROM has no virtio bus
|
|
}
|
|
|
|
|
|
def fix_choices(apps, schema_editor):
|
|
"""Choices the panel cannot use, a space that kept lsilogic from being
|
|
shown as chosen, and a text setting listed as True or False. Not undone
|
|
on the way back, as nothing needs the old choices."""
|
|
AppSettings = apps.get_model("appsettings", "AppSettings")
|
|
for setting in AppSettings.objects.using(schema_editor.connection.alias).filter(key__in=FIXES):
|
|
choices, fallback = FIXES[setting.key]
|
|
setting.choices = choices
|
|
if choices and setting.value not in choices.split(","):
|
|
setting.value = fallback
|
|
setting.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("appsettings", "0019_prebuilt_themes"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(fix_choices, migrations.RunPython.noop),
|
|
]
|