diff --git a/create/forms.py b/create/forms.py index fccf944..0f208ce 100644 --- a/create/forms.py +++ b/create/forms.py @@ -2,6 +2,7 @@ import re from django import forms from django.utils.translation import ugettext_lazy as _ from create.models import Flavor +from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES class FlavorAddForm(forms.Form): @@ -45,6 +46,9 @@ class NewVMForm(forms.Form): meta_prealloc = forms.BooleanField(required=False) virtio = forms.BooleanField(required=False) mac = forms.CharField(required=False) + console_pass = forms.CharField(required=False,empty_value="", widget=forms.PasswordInput()) + video = forms.CharField(error_messages={'required': _('Please select a graphic display')}) + listener_addr = forms.ChoiceField(required=True, widget=forms.RadioSelect, choices=QEMU_CONSOLE_LISTEN_ADDRESSES) def clean_name(self): name = self.cleaned_data['name'] @@ -54,3 +58,4 @@ class NewVMForm(forms.Form): elif len(name) > 20: raise forms.ValidationError(_('The name of the virtual machine must not exceed 20 characters')) return name + diff --git a/create/templates/create_instance.html b/create/templates/create_instance.html index 42f18aa..210ee48 100644 --- a/create/templates/create_instance.html +++ b/create/templates/create_instance.html @@ -14,8 +14,8 @@ - {% include 'errors_block.html' %} + {% include 'pleasewaitdialog.html' %}
@@ -115,7 +115,7 @@
{% if storages %} - {% else %} @@ -202,8 +202,35 @@ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ {% if storages %} - {% else %} diff --git a/create/views.py b/create/views.py index cd8e133..51280c4 100644 --- a/create/views.py +++ b/create/views.py @@ -10,7 +10,8 @@ from instances.models import Instance from vrtManager.create import wvmCreate from vrtManager import util from libvirt import libvirtError - +from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES +from django.contrib import messages @login_required def create_instance(request, compute_id): @@ -27,7 +28,7 @@ def create_instance(request, compute_id): storages = [] networks = [] meta_prealloc = False - computes = Compute.objects.all() + #computes = Compute.objects.all() compute = get_object_or_404(Compute, pk=compute_id) flavors = Flavor.objects.filter().order_by('id') @@ -40,7 +41,9 @@ def create_instance(request, compute_id): storages = sorted(conn.get_storages(only_actives=True)) networks = sorted(conn.get_networks()) instances = conn.get_instances() + videos = conn.get_video() cache_modes = sorted(conn.get_cache_modes().items()) + listener_addr = QEMU_CONSOLE_LISTEN_ADDRESSES mac_auto = util.randomMAC() get_images = sorted(conn.get_storages_images()) except libvirtError as lib_err: @@ -110,8 +113,13 @@ def create_instance(request, compute_id): error_messages.append(lib_err.message) elif data['template']: templ_path = conn.get_volume_path(data['template']) - clone_path = conn.clone_from_template(data['name'], templ_path, metadata=meta_prealloc) - volumes[clone_path] = conn.get_volume_type(clone_path) + dest_vol = conn.get_volume_path(data["name"] + ".img") + if dest_vol: + error_msg = _("Image has already exist. Please check volumes or change instance name") + error_messages.append(error_msg) + else: + clone_path = conn.clone_from_template(data['name'], templ_path, metadata=meta_prealloc) + volumes[clone_path] = conn.get_volume_type(clone_path) else: if not data['images']: error_msg = _("First you need to create or select an image") @@ -131,12 +139,14 @@ def create_instance(request, compute_id): try: conn.create_instance(data['name'], data['memory'], data['vcpu'], data['host_model'], uuid, volumes, data['cache_mode'], data['networks'], data['virtio'], + data["console_pass"], data["listener_addr"], None, data["video"], data['mac']) create_instance = Instance(compute_id=compute_id, name=data['name'], uuid=uuid) create_instance.save() + messages.success(request,"Instance is created.") return HttpResponseRedirect(reverse('instance', args=[compute_id, data['name']])) except libvirtError as lib_err: - if data['hdd_size']: + if data['hdd_size'] or volumes[clone_path]: conn.delete_volume(volumes.keys()[0]) error_messages.append(lib_err) conn.close() diff --git a/vrtManager/create.py b/vrtManager/create.py index 2c2b936..58c2c82 100644 --- a/vrtManager/create.py +++ b/vrtManager/create.py @@ -2,6 +2,7 @@ import string from vrtManager import util from vrtManager.connection import wvmConnect from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE +from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT @@ -148,7 +149,7 @@ class wvmCreate(wvmConnect): vol = self.get_volume_by_path(path) vol.delete() - def create_instance(self, name, memory, vcpu, host_model, uuid, images, cache_mode, networks, virtio, mac=None): + def create_instance(self, name, memory, vcpu, host_model, uuid, images, cache_mode, networks, virtio, console_pass, listen_addr, nwfilter=None, video="cirrus", mac=None ): """ Create VM function """ @@ -228,20 +229,24 @@ class wvmCreate(wvmConnect): xml += """""" if mac: xml += """""" % mac - xml += """ - """ % net + xml += """""" % net + if nwfilter: + xml += """""" % nwfilter if virtio: xml += """""" xml += """""" + if console_pass is None: console_pass = "passwd='" + util.randomPasswd() + "'" + else: console_pass = "passwd='" + console_pass + "'" + xml += """ - + - """ % (QEMU_CONSOLE_DEFAULT_TYPE, util.randomPasswd()) + """ % (QEMU_CONSOLE_DEFAULT_TYPE, console_pass, listen_addr, video) self._defineXML(xml)