diff --git a/appsettings/migrations/0008_auto_20220905_1459.py b/appsettings/migrations/0008_auto_20220905_1459.py
new file mode 100644
index 0000000..2390d5d
--- /dev/null
+++ b/appsettings/migrations/0008_auto_20220905_1459.py
@@ -0,0 +1,32 @@
+# Generated by Django 3.2.13 on 2022-06-30 07:17
+
+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(32, _("VM CD-ROM Device"), "INSTANCE_CDROM_ADD", "sata", "None,ide,sata,scsi,virtio", _("Add or not cdrom device while instance creating")),
+ setting(33, _("VM Video Type"), "INSTANCE_VIDEO_DEFAULT_TYPE", "vga", "None,virtio,vga,cirrus,vmvga,bochs,ramfb", _("Change instance default video type")),
+ setting(34, _("VM Input Device"), "INSTANCE_INPUT_DEFAULT_DEVICE", "default", "None,default,virtio,usb", _("Add or not input device with specify its 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_CDROM_ADD").delete()
+ setting.objects.using(db_alias).filter(key="INSTANCE_VIDEO_DEFAULT_TYPE").delete()
+ setting.objects.using(db_alias).filter(key="INSTANCE_INPUT_DEFAULT_DEVICE").delete()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('appsettings', '0007_auto_20220905_0918'),
+ ]
+
+ operations = [
+ migrations.RunPython(add_default_settings, del_default_settings),
+ ]
diff --git a/instances/models.py b/instances/models.py
index b376491..ec80685 100644
--- a/instances/models.py
+++ b/instances/models.py
@@ -244,6 +244,7 @@ class CreateInstance(models.Model):
qemu_ga = models.BooleanField(default=False)
mac = models.CharField(max_length=17, blank=True)
console_pass = models.CharField(max_length=64, blank=True)
+ add_cdrom = models.CharField(max_length=16)
graphics = models.CharField(max_length=16, error_messages={'required': _('Please select a graphics type')})
video = models.CharField(max_length=16, error_messages={'required': _('Please select a video driver')})
listener_addr = models.CharField(max_length=20, choices=QEMU_CONSOLE_LISTENER_ADDRESSES)
diff --git a/instances/templates/create_instance_w2.html b/instances/templates/create_instance_w2.html
index f71328a..4e98676 100644
--- a/instances/templates/create_instance_w2.html
+++ b/instances/templates/create_instance_w2.html
@@ -227,7 +227,7 @@
{% endif %}
{% for video in videos %}
-
+
{% endfor %}
@@ -248,6 +248,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/instances/views.py b/instances/views.py
index ca998e3..ce2db54 100644
--- a/instances/views.py
+++ b/instances/views.py
@@ -1376,6 +1376,7 @@ def create_instance(request, compute_id, arch, machine):
default_cpu_mode = app_settings.INSTANCE_CPU_DEFAULT_MODE
instances = conn.get_instances()
videos = conn.get_video_models(arch, machine)
+ default_video = app_settings.INSTANCE_VIDEO_DEFAULT_TYPE
cache_modes = sorted(conn.get_cache_modes().items())
default_cache = app_settings.INSTANCE_VOLUME_DEFAULT_CACHE
default_io = app_settings.INSTANCE_VOLUME_DEFAULT_IO
@@ -1394,6 +1395,7 @@ def create_instance(request, compute_id, arch, machine):
nwfilters = conn.get_nwfilters()
storages = sorted(conn.get_storages(only_actives=True))
default_graphics = app_settings.QEMU_CONSOLE_DEFAULT_TYPE
+ default_cdrom = app_settings.INSTANCE_CDROM_ADD
dom_caps = conn.get_dom_capabilities(arch, machine)
caps = conn.get_capabilities(arch)
@@ -1552,6 +1554,7 @@ def create_instance(request, compute_id, arch, machine):
console_pass=data["console_pass"],
mac=data["mac"],
qemu_ga=data["qemu_ga"],
+ add_cdrom=data["add_cdrom"]
)
create_instance = Instance(compute_id=compute_id, name=data["name"], uuid=uuid)
create_instance.save()
diff --git a/vrtManager/create.py b/vrtManager/create.py
index 3084afc..6aaa1a9 100644
--- a/vrtManager/create.py
+++ b/vrtManager/create.py
@@ -165,6 +165,7 @@ class wvmCreate(wvmConnect):
console_pass="random",
mac=None,
qemu_ga=True,
+ add_cdrom="sata",
):
"""
Create VM function
@@ -233,7 +234,18 @@ class wvmCreate(wvmConnect):
fd_disk_letters = list(string.ascii_lowercase)
hd_disk_letters = list(string.ascii_lowercase)
sd_disk_letters = list(string.ascii_lowercase)
- add_cd = True
+ def get_letter(bus_type):
+ if bus_type == "ide":
+ return hd_disk_letters.pop(0)
+ elif bus_type in ["sata", "scsi"]:
+ return sd_disk_letters.pop(0)
+ elif bus_type == "fdc":
+ return fd_disk_letters.pop(0)
+ elif bus_type == "virtio":
+ return vd_disk_letters.pop(0)
+ else:
+ return sd_disk_letters.pop(0)
+
for volume in volumes:
@@ -251,7 +263,7 @@ class wvmCreate(wvmConnect):
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
if volume["device"] == "cdrom":
- add_cd = False
+ add_cdrom = None
if stg_type == "rbd":
ceph_user, secret_uuid, ceph_hosts = get_rbd_storage_data(stg)
@@ -274,34 +286,24 @@ class wvmCreate(wvmConnect):
xml += f""" """
xml += f""" """
- if volume.get("bus") == "virtio":
- xml += """""" % (vd_disk_letters.pop(0), volume.get("bus"))
- elif volume.get("bus") == "ide":
- xml += """""" % (hd_disk_letters.pop(0), volume.get("bus"))
- elif volume.get("bus") == "fdc":
- xml += """""" % (fd_disk_letters.pop(0), volume.get("bus"))
- elif volume.get("bus") in ["sata", "scsi"]:
- xml += """""" % (sd_disk_letters.pop(0), volume.get("bus"))
+ if volume.get("bus") in dom_caps["disk_bus"]:
+ dev_prefix = util.vol_dev_type(volume.get("bus"))
+ xml += """""" % (dev_prefix, get_letter(volume.get("bus")), volume.get("bus"))
else:
- xml += """""" % sd_disk_letters.pop(0)
+ xml += """""" % get_letter("sata")
xml += """"""
if volume.get("bus") == "scsi":
xml += f""""""
- if add_cd:
+ if add_cdrom != "None":
xml += """
"""
- if "ide" in dom_caps["disk_bus"]:
- xml += """""" % (hd_disk_letters.pop(0), "ide")
- elif "scsi" in dom_caps["disk_bus"]:
- xml += """""" % (sd_disk_letters.pop(0), "scsi")
- elif "sata" in dom_caps["disk_bus"]:
- xml += """""" % (sd_disk_letters.pop(0), "sata")
- else:
- xml += """""" % (vd_disk_letters.pop(0), "virtio")
+ if add_cdrom in dom_caps["disk_bus"]:
+ dev_prefix = util.vol_dev_type(add_cdrom)
+ xml += """""" % (dev_prefix, get_letter(add_cdrom), add_cdrom)
xml += """"""
if mac:
diff --git a/vrtManager/util.py b/vrtManager/util.py
index d618896..ab47f32 100644
--- a/vrtManager/util.py
+++ b/vrtManager/util.py
@@ -182,3 +182,15 @@ UEFI_ARCH_PATTERNS = {
r".*arm/QEMU_EFI.*", # fedora, gerd's firmware repo
],
}
+
+
+def vol_dev_type(vol_bus):
+ if vol_bus == "ide":
+ return "hd"
+ elif vol_bus == "fdc":
+ return "fd"
+ elif vol_bus == "virtio":
+ return "vd"
+ elif vol_bus in ["scsi", "sata"]:
+ return "sd"
+