1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

Add virtio support check, add more control while creating instance

This commit is contained in:
catborise 2019-12-19 13:49:41 +03:00
parent 6634207ef5
commit d401d2f3ff
4 changed files with 73 additions and 31 deletions

View file

@ -250,12 +250,14 @@
<input type="checkbox" name="qemu_ga" value="true" checked>
</div>
</div>
{% if virtio_support %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="virtio" value="true" checked>
<input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div>
</div>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
@ -468,12 +470,14 @@
<input type="checkbox" name="qemu_ga" value="true" checked>
</div>
</div>
{% if virtio_support %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-7">
<input type="checkbox" name="virtio" value="true" checked>
<div class="col-sm-6">
<input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div>
</div>
{% endif %}
<div class="form-group">
<div class="col-sm-7 col-sm-offset-3">
{% if storages %}
@ -668,12 +672,14 @@
<input type="checkbox" name="qemu_ga" value="true" checked>
</div>
</div>
{% if virtio_support %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-7">
<input type="checkbox" name="virtio" value="true" checked>
<div class="col-sm-6">
<input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div>
</div>
{% endif %}
<div class="form-group">
<div class="col-sm-7 col-sm-offset-3">
{% if storages %}

View file

@ -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"],

View file

@ -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)

View file

@ -189,8 +189,16 @@ class wvmCreate(wvmConnect):
xml += """ <boot dev='hd'/>
<boot dev='cdrom'/>
<bootmenu enable='yes'/>"""
if 'UEFI' in firmware:
xml += """<loader readonly='yes' type='pflash'>%s</loader>""" % firmware.split(":")[1].strip()
if firmware:
if firmware["secure"] == 'yes':
xml += """<loader readonly='%s' type='%s' secure='%s'>%s</loader>""" % (firmware["readonly"],
firmware["type"],
firmware["secure"],
firmware["loader"])
if firmware["secure"] == 'no':
xml += """<loader readonly='%s' type='%s'>%s</loader>""" % (firmware["readonly"],
firmware["type"],
firmware["loader"])
xml += """</os>"""
if caps["features"]:
@ -201,6 +209,8 @@ class wvmCreate(wvmConnect):
xml += """<apic/>"""
if 'pae' in caps["features"]:
xml += """<pae/>"""
if 'yes' == firmware["secure"]:
xml += """<smm state="on"/>"""
xml += """</features>"""
if vcpu_mode == "host-model":
@ -211,8 +221,8 @@ class wvmCreate(wvmConnect):
pass
else:
xml += """<cpu mode='custom' match='exact' check='none'>
<model fallback='allow'>{}</model>
</cpu>""".format(vcpu_mode)
<model fallback='allow'>%s</model>""" % vcpu_mode
xml += """</cpu>"""
xml += """
<clock offset="utc"/>
@ -255,14 +265,16 @@ class wvmCreate(wvmConnect):
xml += """ <driver name='qemu' type='%s' cache='%s' %s/>""" % (volume['type'], cache_mode, OPTS.get("file", ''))
xml += """ <source file='%s'/>""" % volume['path']
if volume['bus'] == 'virtio':
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), volume['bus'])
elif volume['bus'] == 'ide':
xml += """<target dev='hd%s' bus='%s'/>""" % (hd_disk_letters.pop(0), volume['bus'])
elif volume['bus'] == 'fdc':
xml += """<target dev='fd%s' bus='%s'/>""" % (fd_disk_letters.pop(0), volume['bus'])
if volume.get('bus') == 'virtio':
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), volume.get('bus'))
elif volume.get('bus') == 'ide':
xml += """<target dev='hd%s' bus='%s'/>""" % (hd_disk_letters.pop(0), volume.get('bus'))
elif volume.get('bus') == 'fdc':
xml += """<target dev='fd%s' bus='%s'/>""" % (fd_disk_letters.pop(0), volume.get('bus'))
elif volume.get('bus') == 'sata' or volume.get('bus') == 'scsi':
xml += """<target dev='sd%s' bus='%s'/>""" % (sd_disk_letters.pop(0), volume.get('bus'))
else:
xml += """<target dev='sd%s' bus='%s'/>""" % (sd_disk_letters.pop(0), volume['bus'])
xml += """<target dev='sd%s'/>""" % sd_disk_letters.pop(0)
xml += """</disk>"""
if add_cd:
xml += """<disk type='file' device='cdrom'>
@ -279,7 +291,7 @@ class wvmCreate(wvmConnect):
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), 'virtio')
xml += """</disk>"""
if volume['bus'] == 'scsi':
if volume.get('bus') == 'scsi':
xml += """<controller type='scsi' model='%s'/>""" % 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 += """<input type='mouse' bus='virtio'/>"""
xml += """<input type='tablet' bus='virtio'/>"""
if 'usb' in dom_caps['disk_bus']:
xml += """<input type='mouse' bus='{}'/>""".format('virtio' if virtio else 'usb')
xml += """<input type='tablet' bus='{}'/>""".format('virtio' if virtio else 'usb')
xml += """
<graphics type='%s' port='-1' autoport='yes' %s listen='%s'/>
<console type='pty'/> """ % (graphics, console_pass, listen_addr)
if qemu_ga:
if qemu_ga and virtio:
xml += """ <channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>"""