1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +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> <input type="checkbox" name="qemu_ga" value="true" checked>
</div> </div>
</div> </div>
{% if virtio_support %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label> <label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-6"> <div class="col-sm-6">
<input type="checkbox" name="virtio" value="true" checked> <input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button> <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> <input type="checkbox" name="qemu_ga" value="true" checked>
</div> </div>
</div> </div>
{% if virtio_support %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label> <label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-7"> <div class="col-sm-6">
<input type="checkbox" name="virtio" value="true" checked> <input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div> </div>
</div> </div>
{% endif %}
<div class="form-group"> <div class="form-group">
<div class="col-sm-7 col-sm-offset-3"> <div class="col-sm-7 col-sm-offset-3">
{% if storages %} {% if storages %}
@ -668,12 +672,14 @@
<input type="checkbox" name="qemu_ga" value="true" checked> <input type="checkbox" name="qemu_ga" value="true" checked>
</div> </div>
</div> </div>
{% if virtio_support %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label> <label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-7"> <div class="col-sm-6">
<input type="checkbox" name="virtio" value="true" checked> <input type="checkbox" name="virtio" value="{{ virtio_support }}" checked>
</div> </div>
</div> </div>
{% endif %}
<div class="form-group"> <div class="form-group">
<div class="col-sm-7 col-sm-offset-3"> <div class="col-sm-7 col-sm-offset-3">
{% if storages %} {% if storages %}

View file

@ -111,6 +111,7 @@ def create_instance(request, compute_id, arch, machine):
dom_caps = conn.get_dom_capabilities(arch, machine) dom_caps = conn.get_dom_capabilities(arch, machine)
caps = conn.get_capabilities(arch) caps = conn.get_capabilities(arch)
virtio_support = conn.is_supports_virtio(arch, machine)
hv_supports_uefi = conn.supports_uefi_xml(dom_caps["loader_enums"]) hv_supports_uefi = conn.supports_uefi_xml(dom_caps["loader_enums"])
# Add BIOS # Add BIOS
label = conn.label_for_firmware_path(arch, None) label = conn.label_for_firmware_path(arch, None)
@ -149,6 +150,7 @@ def create_instance(request, compute_id, arch, machine):
delete_flavor.delete() delete_flavor.delete()
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'create' in request.POST: if 'create' in request.POST:
firmware = dict()
volume_list = list() volume_list = list()
is_disk_created = False is_disk_created = False
clone_path = "" clone_path = ""
@ -176,6 +178,7 @@ def create_instance(request, compute_id, arch, machine):
volume['path'] = path volume['path'] = path
volume['type'] = conn.get_volume_type(path) volume['type'] = conn.get_volume_type(path)
volume['device'] = 'disk' volume['device'] = 'disk'
if data['virtio']:
volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS
volume_list.append(volume) volume_list.append(volume)
is_disk_created = True is_disk_created = True
@ -193,6 +196,7 @@ def create_instance(request, compute_id, arch, machine):
volume['path'] = clone_path volume['path'] = clone_path
volume['type'] = conn.get_volume_type(clone_path) volume['type'] = conn.get_volume_type(clone_path)
volume['device'] = 'disk' volume['device'] = 'disk'
if data['virtio']:
volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS
volume_list.append(volume) volume_list.append(volume)
is_disk_created = True is_disk_created = True
@ -215,12 +219,23 @@ def create_instance(request, compute_id, arch, machine):
if data['cache_mode'] not in conn.get_cache_modes(): if data['cache_mode'] not in conn.get_cache_modes():
error_msg = _("Invalid cache mode") error_msg = _("Invalid cache mode")
error_messages.append(error_msg) 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: if not error_messages:
uuid = util.randomUUID() uuid = util.randomUUID()
try: try:
conn.create_instance(name=data['name'], memory=data['memory'], vcpu=data['vcpu'], conn.create_instance(name=data['name'], memory=data['memory'], vcpu=data['vcpu'],
vcpu_mode=data['vcpu_mode'], uuid=uuid, arch=arch, machine=machine, vcpu_mode=data['vcpu_mode'], uuid=uuid, arch=arch, machine=machine,
firmware=data["firmware"], firmware=firmware,
images=volume_list, cache_mode=data['cache_mode'], images=volume_list, cache_mode=data['cache_mode'],
networks=data['networks'], virtio=data['virtio'], networks=data['networks'], virtio=data['virtio'],
listen_addr=data["listener_addr"], nwfilter=data["nwfilter"], listen_addr=data["listener_addr"], nwfilter=data["nwfilter"],

View file

@ -236,14 +236,19 @@ def instance(request, compute_id, vname):
return return
if new_compute == instance.compute: if new_compute == instance.compute:
return return
try:
conn_migrate = wvmInstances(new_compute.hostname, conn_migrate = wvmInstances(new_compute.hostname,
new_compute.login, new_compute.login,
new_compute.password, new_compute.password,
new_compute.type) 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.compute = new_compute
instance.save() instance.save()
conn_migrate.close()
conn_new = wvmInstance(new_compute.hostname, conn_new = wvmInstance(new_compute.hostname,
new_compute.login, new_compute.login,
new_compute.password, new_compute.password,
@ -267,6 +272,8 @@ def instance(request, compute_id, vname):
boot_order = conn.get_bootorder() boot_order = conn.get_bootorder()
arch = conn.get_arch() arch = conn.get_arch()
machine = conn.get_machine_type() machine = conn.get_machine_type()
firmware = conn.get_loader()
nvram = conn.get_nvram()
vcpu = conn.get_vcpu() vcpu = conn.get_vcpu()
cur_vcpu = conn.get_cur_vcpu() cur_vcpu = conn.get_cur_vcpu()
vcpus = conn.get_vcpus() vcpus = conn.get_vcpus()
@ -290,7 +297,6 @@ def instance(request, compute_id, vname):
insort(memory_range, memory) insort(memory_range, memory)
if cur_memory not in memory_range: if cur_memory not in memory_range:
insort(memory_range, cur_memory) insort(memory_range, cur_memory)
nvram = conn.get_nvram()
telnet_port = conn.get_telnet_port() telnet_port = conn.get_telnet_port()
console_type = conn.get_console_type() console_type = conn.get_console_type()
console_port = conn.get_console_port() console_port = conn.get_console_port()
@ -949,16 +955,17 @@ def instance(request, compute_id, vname):
error_messages.append(msg) error_messages.append(msg)
else: else:
new_instance = Instance(compute_id=compute_id, name=clone_data['name']) new_instance = Instance(compute_id=compute_id, name=clone_data['name'])
new_instance.save() #new_instance.save()
try: try:
new_uuid = conn.clone_instance(clone_data) new_uuid = conn.clone_instance(clone_data)
new_instance.uuid = new_uuid new_instance.uuid = new_uuid
new_instance.save() new_instance.save()
except Exception as e: except Exception as e:
new_instance.delete() #new_instance.delete()
raise e 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) msg = _("Clone of '%s'" % instance.name)
addlogmsg(request.user.username, new_instance.name, msg) addlogmsg(request.user.username, new_instance.name, msg)

View file

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