1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00
webvirtcloud/appsettings/migrations/0015_remove_clone_instance_auto_migrate.py
catborise 1016f745c2 fix(instances): a clone stays on the host of the VM it was made from
With "VM Clone Auto Migrate" on, a new clone was migrated to a random
compute, whatever storage, CPU or network that host had, and a failed
migration showed as a failed clone although the clone existed.

The setting and its code are removed; migration appsettings.0015
deletes the setting. A clone can be migrated afterwards like any VM.
The README's update notes list the migration changes: the migration
address, storage pools for the disk check, and this setting.
2026-10-06 15:58:35 +03:00

31 lines
1.1 KiB
Python

from django.db import migrations
def remove_auto_migrate(apps, schema_editor):
"""A clone stays on the host of the VM it was made from: the setting sent
it to a random host, whatever storage, CPU or network that host had."""
AppSettings = apps.get_model("appsettings", "AppSettings")
AppSettings.objects.using(schema_editor.connection.alias).filter(key="CLONE_INSTANCE_AUTO_MIGRATE").delete()
def restore_auto_migrate(apps, schema_editor):
AppSettings = apps.get_model("appsettings", "AppSettings")
AppSettings.objects.using(schema_editor.connection.alias).get_or_create(
key="CLONE_INSTANCE_AUTO_MIGRATE",
defaults={
"name": "VM Clone Auto Migrate",
"value": "False",
"choices": "True,False",
"description": "Auto migrate instance after clone",
},
)
class Migration(migrations.Migration):
dependencies = [
("appsettings", "0014_login_lockout_settings"),
]
operations = [
migrations.RunPython(remove_auto_migrate, restore_auto_migrate),
]