From 7e8c05fff93646651f3345128623bea7ef9506b3 Mon Sep 17 00:00:00 2001 From: MisterBlueBear <51129551+MisterBlueBear@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:08:38 -0400 Subject: [PATCH] Global setting for NIC type --- .../migrations/0009_alter_appsettings_id.py | 18 ++++++++++++ .../migrations/0010_auto_20231030_1305.py | 28 +++++++++++++++++++ instances/templates/create_instance_w2.html | 6 ++-- instances/views.py | 1 + 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 appsettings/migrations/0009_alter_appsettings_id.py create mode 100644 appsettings/migrations/0010_auto_20231030_1305.py diff --git a/appsettings/migrations/0009_alter_appsettings_id.py b/appsettings/migrations/0009_alter_appsettings_id.py new file mode 100644 index 0000000..5e588dc --- /dev/null +++ b/appsettings/migrations/0009_alter_appsettings_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2023-10-30 17:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('appsettings', '0008_auto_20220905_1459'), + ] + + operations = [ + migrations.AlterField( + model_name='appsettings', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/appsettings/migrations/0010_auto_20231030_1305.py b/appsettings/migrations/0010_auto_20231030_1305.py new file mode 100644 index 0000000..606909d --- /dev/null +++ b/appsettings/migrations/0010_auto_20231030_1305.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.5 on 2023-10-30 17:05 + +from django.db import migrations +from django.utils.translation import gettext_lazy as _ + +def add_default_settings(apps, schema_editor): + setting = apps.get_model("appsettings", "AppSettings") + db_alias = schema_editor.connection.alias + setting.objects.using(db_alias).bulk_create([ + setting(35, _("VM NIC Type"), "INSTANCE_NIC_DEFAULT_TYPE", "default", "default,e1000,e1000e,rt18139,virtio", _("Change instance default NIC type")) + ]) + + +def del_default_settings(apps, schema_editor): + setting = apps.get_model("appsettings", "AppSettings") + db_alias = schema_editor.connection.alias + setting.objects.using(db_alias).filter(key="INSTANCE_NIC_DEFAULT_TYPE").delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('appsettings', '0009_alter_appsettings_id') + ] + + operations = [ + migrations.RunPython(add_default_settings,del_default_settings) + ] diff --git a/instances/templates/create_instance_w2.html b/instances/templates/create_instance_w2.html index 91ae2ec..1cf7d62 100644 --- a/instances/templates/create_instance_w2.html +++ b/instances/templates/create_instance_w2.html @@ -200,7 +200,7 @@