diff --git a/create/templates/create_instance_w2.html b/create/templates/create_instance_w2.html index 1e73feb..09a9484 100644 --- a/create/templates/create_instance_w2.html +++ b/create/templates/create_instance_w2.html @@ -250,12 +250,14 @@ + {% if virtio_support %}
- +
+ {% endif %} + {% if virtio_support %}
-
- +
+
+ {% endif %}
{% if storages %} @@ -668,12 +672,14 @@
+ {% if virtio_support %}
-
- +
+
+ {% endif %}
{% if storages %} diff --git a/create/views.py b/create/views.py index f0c8633..4aa5c39 100644 --- a/create/views.py +++ b/create/views.py @@ -111,6 +111,7 @@ def create_instance(request, compute_id, arch, machine): dom_caps = conn.get_dom_capabilities(arch, machine) caps = conn.get_capabilities(arch) + virtio_support = conn.is_supports_virtio(arch, machine) hv_supports_uefi = conn.supports_uefi_xml(dom_caps["loader_enums"]) # Add BIOS label = conn.label_for_firmware_path(arch, None) @@ -149,6 +150,7 @@ def create_instance(request, compute_id, arch, machine): delete_flavor.delete() return HttpResponseRedirect(request.get_full_path()) if 'create' in request.POST: + firmware = dict() volume_list = list() is_disk_created = False clone_path = "" @@ -176,7 +178,8 @@ def create_instance(request, compute_id, arch, machine): volume['path'] = path volume['type'] = conn.get_volume_type(path) volume['device'] = 'disk' - volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS + if data['virtio']: + volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS volume_list.append(volume) is_disk_created = True except libvirtError as lib_err: @@ -193,7 +196,8 @@ def create_instance(request, compute_id, arch, machine): volume['path'] = clone_path volume['type'] = conn.get_volume_type(clone_path) volume['device'] = 'disk' - volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS + if data['virtio']: + volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS volume_list.append(volume) is_disk_created = True else: @@ -215,12 +219,23 @@ def create_instance(request, compute_id, arch, machine): if data['cache_mode'] not in conn.get_cache_modes(): error_msg = _("Invalid cache mode") error_messages.append(error_msg) + if 'UEFI' in data["firmware"]: + firmware["loader"] = data["firmware"].split(":")[1].strip() + firmware["secure"] = 'no' + firmware["readonly"] = 'yes' + firmware["type"] = 'pflash' + if 'secboot' in firmware["loader"] and machine != 'q35': + messages.warning(request, "Changing machine type from '%s' to 'q35' " + "which is required for UEFI secure boot." % machine) + machine = 'q35' + firmware["secure"] = 'yes' + if not error_messages: uuid = util.randomUUID() try: conn.create_instance(name=data['name'], memory=data['memory'], vcpu=data['vcpu'], vcpu_mode=data['vcpu_mode'], uuid=uuid, arch=arch, machine=machine, - firmware=data["firmware"], + firmware=firmware, images=volume_list, cache_mode=data['cache_mode'], networks=data['networks'], virtio=data['virtio'], listen_addr=data["listener_addr"], nwfilter=data["nwfilter"], diff --git a/instances/views.py b/instances/views.py index 368f3e4..100a17a 100644 --- a/instances/views.py +++ b/instances/views.py @@ -236,14 +236,19 @@ def instance(request, compute_id, vname): return if new_compute == instance.compute: return - conn_migrate = wvmInstances(new_compute.hostname, + try: + conn_migrate = wvmInstances(new_compute.hostname, new_compute.login, new_compute.password, new_compute.type) - conn_migrate.moveto(conn, instance.name, live, unsafe, xml_del, offline) + + conn_migrate.moveto(conn, instance.name, live, unsafe, xml_del, offline) + finally: + conn_migrate.close() + instance.compute = new_compute instance.save() - conn_migrate.close() + conn_new = wvmInstance(new_compute.hostname, new_compute.login, new_compute.password, @@ -267,6 +272,8 @@ def instance(request, compute_id, vname): boot_order = conn.get_bootorder() arch = conn.get_arch() machine = conn.get_machine_type() + firmware = conn.get_loader() + nvram = conn.get_nvram() vcpu = conn.get_vcpu() cur_vcpu = conn.get_cur_vcpu() vcpus = conn.get_vcpus() @@ -290,7 +297,6 @@ def instance(request, compute_id, vname): insort(memory_range, memory) if cur_memory not in memory_range: insort(memory_range, cur_memory) - nvram = conn.get_nvram() telnet_port = conn.get_telnet_port() console_type = conn.get_console_type() console_port = conn.get_console_port() @@ -949,16 +955,17 @@ def instance(request, compute_id, vname): error_messages.append(msg) else: new_instance = Instance(compute_id=compute_id, name=clone_data['name']) - new_instance.save() + #new_instance.save() try: new_uuid = conn.clone_instance(clone_data) new_instance.uuid = new_uuid new_instance.save() except Exception as e: - new_instance.delete() + #new_instance.delete() raise e - userinstance = UserInstance(instance_id=new_instance.id, user_id=request.user.id, is_delete=True) - userinstance.save() + + user_instance = UserInstance(instance_id=new_instance.id, user_id=request.user.id, is_delete=True) + user_instance.save() msg = _("Clone of '%s'" % instance.name) addlogmsg(request.user.username, new_instance.name, msg) diff --git a/vrtManager/create.py b/vrtManager/create.py index d11e2eb..a889d69 100644 --- a/vrtManager/create.py +++ b/vrtManager/create.py @@ -189,8 +189,16 @@ class wvmCreate(wvmConnect): xml += """ """ - if 'UEFI' in firmware: - xml += """%s""" % firmware.split(":")[1].strip() + if firmware: + if firmware["secure"] == 'yes': + xml += """%s""" % (firmware["readonly"], + firmware["type"], + firmware["secure"], + firmware["loader"]) + if firmware["secure"] == 'no': + xml += """%s""" % (firmware["readonly"], + firmware["type"], + firmware["loader"]) xml += """""" if caps["features"]: @@ -201,6 +209,8 @@ class wvmCreate(wvmConnect): xml += """""" if 'pae' in caps["features"]: xml += """""" + if 'yes' == firmware["secure"]: + xml += """""" xml += """""" if vcpu_mode == "host-model": @@ -211,8 +221,8 @@ class wvmCreate(wvmConnect): pass else: xml += """ - {} - """.format(vcpu_mode) + %s""" % vcpu_mode + xml += """""" xml += """ @@ -255,14 +265,16 @@ class wvmCreate(wvmConnect): xml += """ """ % (volume['type'], cache_mode, OPTS.get("file", '')) xml += """ """ % volume['path'] - if volume['bus'] == 'virtio': - xml += """""" % (vd_disk_letters.pop(0), volume['bus']) - elif volume['bus'] == 'ide': - xml += """""" % (hd_disk_letters.pop(0), volume['bus']) - elif volume['bus'] == 'fdc': - xml += """""" % (fd_disk_letters.pop(0), volume['bus']) + 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') == 'sata' or volume.get('bus') == 'scsi': + xml += """""" % (sd_disk_letters.pop(0), volume.get('bus')) else: - xml += """""" % (sd_disk_letters.pop(0), volume['bus']) + xml += """""" % sd_disk_letters.pop(0) xml += """""" if add_cd: xml += """ @@ -279,7 +291,7 @@ class wvmCreate(wvmConnect): xml += """""" % (vd_disk_letters.pop(0), 'virtio') xml += """""" - if volume['bus'] == 'scsi': + if volume.get('bus') == 'scsi': xml += """""" % INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER for net in networks.split(','): @@ -299,13 +311,15 @@ class wvmCreate(wvmConnect): if not console_pass == "": console_pass = "passwd='" + console_pass + "'" - xml += """""" - xml += """""" + if 'usb' in dom_caps['disk_bus']: + xml += """""".format('virtio' if virtio else 'usb') + xml += """""".format('virtio' if virtio else 'usb') + xml += """ """ % (graphics, console_pass, listen_addr) - if qemu_ga: + if qemu_ga and virtio: xml += """ """