diff --git a/Dockerfile b/Dockerfile index 4f57585..d6b95ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,7 @@ RUN python3 -m venv venv && \ chown -R www-data:www-data /srv/webvirtcloud RUN . venv/bin/activate && \ + python3 manage.py makemigrations && \ python3 manage.py migrate && \ python3 manage.py collectstatic --noinput && \ chown -R www-data:www-data /srv/webvirtcloud diff --git a/admin/__init__.py b/admin/__init__.py index b7f8a6a..052dc42 100644 --- a/admin/__init__.py +++ b/admin/__init__.py @@ -1 +1 @@ -defautl_app_config = 'admin.apps.AdminConfig' +default_app_config = 'admin.apps.AdminConfig' diff --git a/appsettings/migrations/0006_auto_20220630_0717.py b/appsettings/migrations/0006_auto_20220630_0717.py index b9d9871..9ffc860 100644 --- a/appsettings/migrations/0006_auto_20220630_0717.py +++ b/appsettings/migrations/0006_auto_20220630_0717.py @@ -24,5 +24,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(add_default_settings, del_default_settings), + migrations.RunPython(add_default_settings, del_default_settings), ] diff --git a/appsettings/migrations/0007_auto_20220905_0918.py b/appsettings/migrations/0007_auto_20220905_0918.py new file mode 100644 index 0000000..229e1cb --- /dev/null +++ b/appsettings/migrations/0007_auto_20220905_0918.py @@ -0,0 +1,21 @@ +# 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 update_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_MACHINE_DEFAULT_TYPE").update(choices="q35,x86_64,virt"), + setting.objects.using(db_alias).filter(key="INSTANCE_ARCH_DEFAULT_TYPE").update(choices="x86_64,i686,aarch64"), + + +class Migration(migrations.Migration): + + dependencies = [ + ('appsettings', '0006_auto_20220630_0717'), + ] + + operations = [ + migrations.RunPython(update_default_settings, None) + ] 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/api/viewsets.py b/instances/api/viewsets.py index 4960f07..1fb06bb 100644 --- a/instances/api/viewsets.py +++ b/instances/api/viewsets.py @@ -199,24 +199,24 @@ class CreateInstanceViewSet(viewsets.ViewSet): firmware["secure"] = "yes" ret = conn.create_instance( - serializer.validated_data['name'], - serializer.validated_data['memory'], - serializer.validated_data['vcpu'], - serializer.validated_data['vcpu_mode'], - util.randomUUID(), - arch, - machine, - firmware, - volume_list, - serializer.validated_data['networks'], - serializer.validated_data['nwfilter'], - serializer.validated_data['graphics'], - serializer.validated_data['virtio'], - serializer.validated_data['listener_addr'], - serializer.validated_data['video'], - serializer.validated_data['console_pass'], - serializer.validated_data['mac'], - serializer.validated_data['qemu_ga'], + name=serializer.validated_data['name'], + memory=serializer.validated_data['memory'], + vcpu=serializer.validated_data['vcpu'], + vcpu_mode=serializer.validated_data['vcpu_mode'], + uuid=util.randomUUID(), + arch=arch, + machine=machine, + firmware=firmware, + volumes=volume_list, + networks=serializer.validated_data['networks'], + nwfilter=serializer.validated_data['nwfilter'], + graphics=serializer.validated_data['graphics'], + virtio=serializer.validated_data['virtio'], + listener_addr=serializer.validated_data['listener_addr'], + video=serializer.validated_data['video'], + console_pass=serializer.validated_data['console_pass'], + mac=serializer.validated_data['mac'], + qemu_ga=serializer.validated_data['qemu_ga'], ) msg = f"Instance {serializer.validated_data['name']} is created" return Response({'status': msg }) diff --git a/instances/models.py b/instances/models.py index fa18483..222f886 100644 --- a/instances/models.py +++ b/instances/models.py @@ -3,7 +3,6 @@ from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ from libvirt import VIR_DOMAIN_XML_SECURE -from vrtManager.create import wvmCreate from webvirtcloud.settings import QEMU_CONSOLE_LISTENER_ADDRESSES from computes.models import Compute @@ -228,7 +227,7 @@ class MigrateInstance(models.Model): class CreateInstance(models.Model): compute = models.ForeignKey(Compute, related_name='host', on_delete=models.DO_NOTHING) name = models.CharField(max_length=64, error_messages={'required': _('No Virtual Machine name has been entered')}) - firmware = models.CharField(max_length=50) + firmware = models.CharField(max_length=64) vcpu = models.IntegerField(error_messages={'required': _('No VCPU has been entered')}) vcpu_mode = models.CharField(max_length=20, blank=True) disk = models.IntegerField(blank=True) @@ -238,15 +237,17 @@ class CreateInstance(models.Model): storage = models.CharField(max_length=256, blank=True) template = models.CharField(max_length=256, blank=True) images = models.CharField(max_length=256, blank=True) - cache_mode = models.CharField(max_length=12, error_messages={'required': _('Please select HDD cache mode')}) + cache_mode = models.CharField(max_length=16, error_messages={'required': _('Please select HDD cache mode')}) hdd_size = models.IntegerField(blank=True) meta_prealloc = models.BooleanField(default=False, blank=True) virtio = models.BooleanField(default=True) qemu_ga = models.BooleanField(default=False) mac = models.CharField(max_length=17, blank=True) console_pass = models.CharField(max_length=64, blank=True) - graphics = models.CharField(max_length=12, error_messages={'required': _('Please select a graphics type')}) - video = models.CharField(max_length=12, error_messages={'required': _('Please select a video driver')}) + add_cdrom = models.CharField(max_length=16) + add_input = 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) class Meta: diff --git a/instances/templates/create_instance_w2.html b/instances/templates/create_instance_w2.html index f71328a..d26b2a6 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,32 @@ +