Skip to content

Commit

Permalink
Merge pull request #620 from MisterBlueBear/global_setting_nic_type
Browse files Browse the repository at this point in the history
Global setting for NIC type
  • Loading branch information
catborise authored Nov 2, 2023
2 parents bcf91ad + 7e8c05f commit 6c0cc3c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
18 changes: 18 additions & 0 deletions appsettings/migrations/0009_alter_appsettings_id.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
28 changes: 28 additions & 0 deletions appsettings/migrations/0010_auto_20231030_1305.py
Original file line number Diff line number Diff line change
@@ -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)
]
6 changes: 3 additions & 3 deletions instances/templates/create_instance_w2.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ <h5 class="modal-title">{% trans "Create Virtual Machine" %} ({{ flavor.label }}
<div class="col-sm-7">
<select class="form-select" name="net_model">
{% for model in net_models_host %}
<option value="{{ model }}" {% if model == 'default' %} selected {% endif %}>{{ model }}</option>
<option value="{{ model }}" {% if model == default_nic_type %} selected {% endif %}>{{ model }}</option>
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -476,7 +476,7 @@ <h5 class="modal-title">{% trans "Create Virtual Machine" %} ({{ flavor.label }}
<div class="col-sm-7">
<select class="form-select" name="net_model">
{% for model in net_models_host %}
<option value="{{ model }}" {% if model == 'default' %} selected {% endif %}>{{ model }}</option>
<option value="{{ model }}" {% if model == default_nic_type %} selected {% endif %}>{{ model }}</option>
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -728,7 +728,7 @@ <h5 class="modal-title">{% trans "Create Virtual Machine" %} ({{ flavor.label }}
<div class="col-sm-7">
<select class="form-select" name="net_model">
{% for model in net_models_host %}
<option value="{{ model }}" {% if model == 'default' %} selected {% endif %}>{{ model }}</option>
<option value="{{ model }}" {% if model == default_nic_type %} selected {% endif %}>{{ model }}</option>
{% endfor %}
</select>
</div>
Expand Down
1 change: 1 addition & 0 deletions instances/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ def create_instance(request, compute_id, arch, machine):
networks = sorted(conn.get_networks())
nwfilters = conn.get_nwfilters()
net_models_host = conn.get_network_models()
default_nic_type = app_settings.INSTANCE_NIC_DEFAULT_TYPE
storages = sorted(conn.get_storages(only_actives=True))
default_graphics = app_settings.QEMU_CONSOLE_DEFAULT_TYPE
default_cdrom = app_settings.INSTANCE_CDROM_ADD
Expand Down

0 comments on commit 6c0cc3c

Please sign in to comment.