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

add disk options for instance. add keyboard input type.

This commit is contained in:
catborise 2020-01-08 11:23:10 +03:00
parent 0ef876c7a7
commit 2b96089542
3 changed files with 44 additions and 13 deletions

View file

@ -16,6 +16,9 @@ from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_BUS
from webvirtcloud.settings import INSTANCE_CPU_DEFAULT_MODE
from webvirtcloud.settings import INSTANCE_MACHINE_DEFAULT_TYPE
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_IO
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_DISCARD
from django.contrib import messages
from logs.views import addlogmsg
@ -97,7 +100,10 @@ def create_instance(request, compute_id, arch, machine):
instances = conn.get_instances()
videos = conn.get_video_models(arch, machine)
cache_modes = sorted(conn.get_cache_modes().items())
default_cache = INSTANCE_VOLUME_DEFAULT_CACHE
default_cache = INSTANCE_VOLUME_DEFAULT_CACHE.lower()
default_io = INSTANCE_VOLUME_DEFAULT_IO.lower()
default_zeroes = INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES.lower()
default_discard = INSTANCE_VOLUME_DEFAULT_DISCARD.lower()
listener_addr = QEMU_CONSOLE_LISTEN_ADDRESSES
mac_auto = util.randomMAC()
disk_devices = conn.get_disk_device_types(arch, machine)
@ -238,6 +244,7 @@ def create_instance(request, compute_id, arch, machine):
vcpu_mode=data['vcpu_mode'], uuid=uuid, arch=arch, machine=machine,
firmware=firmware,
images=volume_list, cache_mode=data['cache_mode'],
io_mode=default_io, discard_mode=default_discard, detect_zeroes_mode=default_zeroes,
networks=data['networks'], virtio=data['virtio'],
listen_addr=data["listener_addr"], nwfilter=data["nwfilter"],
graphics=data["graphics"], video=data["video"],

View file

@ -4,7 +4,8 @@ from vrtManager.connection import wvmConnect
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as DEFAULT_OWNER
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_DRIVER_OPTS as OPTS
@ -165,7 +166,11 @@ class wvmCreate(wvmConnect):
vol = self.get_volume_by_path(path)
vol.delete()
def create_instance(self, name, memory, vcpu, vcpu_mode, uuid, arch, machine, firmware, images, cache_mode, networks, nwfilter, graphics, virtio, listen_addr, video="vga", console_pass="random", mac=None, qemu_ga=False):
def create_instance(self, name, memory, vcpu, vcpu_mode, uuid, arch, machine, firmware, images,
networks, nwfilter, graphics, virtio, listen_addr,
video="vga", console_pass="random", mac=None,
cache_mode=None, io_mode=None, discard_mode=None, detect_zeroes_mode=None,
qemu_ga=True):
"""
Create VM function
"""
@ -173,7 +178,6 @@ class wvmCreate(wvmConnect):
dom_caps = self.get_dom_capabilities(arch, machine)
memory = int(memory) * 1024
#hypervisor_type = 'kvm' if self.is_kvm_supported() else 'qemu'
xml = """
<domain type='%s'>
@ -237,6 +241,17 @@ class wvmCreate(wvmConnect):
hd_disk_letters = list(string.lowercase)
sd_disk_letters = list(string.lowercase)
add_cd = True
disk_opts = ''
if cache_mode is not None and cache_mode != 'default':
disk_opts += "cache='%s' " % cache_mode
if io_mode is not None and io_mode != 'default':
disk_opts += "io='%s' " % io_mode
if discard_mode is not None and discard_mode != 'default':
disk_opts += "discard='%s' " % discard_mode
if detect_zeroes_mode is not None and detect_zeroes_mode != 'default':
disk_opts += "detect_zeroes='%s' " % detect_zeroes_mode
for volume in images:
stg = self.get_storage_by_vol_path(volume['path'])
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
@ -246,7 +261,7 @@ class wvmCreate(wvmConnect):
if stg_type == 'rbd':
ceph_user, secret_uuid, ceph_hosts = get_rbd_storage_data(stg)
xml += """<disk type='network' device='disk'>
<driver name='qemu' type='%s' cache='%s' %s />""" % (volume['type'], cache_mode, OPTS.get("network", ''))
<driver name='qemu' type='%s' %s />""" % (volume['type'], disk_opts)
xml += """ <auth username='%s'>
<secret type='ceph' uuid='%s'/>
</auth>
@ -262,7 +277,7 @@ class wvmCreate(wvmConnect):
xml += """</source>"""
else:
xml += """<disk type='file' device='%s'>""" % volume['device']
xml += """ <driver name='qemu' type='%s' cache='%s' %s/>""" % (volume['type'], cache_mode, OPTS.get("file", ''))
xml += """ <driver name='qemu' type='%s' %s/>""" % (volume['type'], disk_opts)
xml += """ <source file='%s'/>""" % volume['path']
if volume.get('bus') == 'virtio':
@ -313,7 +328,12 @@ class wvmCreate(wvmConnect):
if 'usb' in dom_caps['disk_bus']:
xml += """<input type='mouse' bus='{}'/>""".format('virtio' if virtio else 'usb')
xml += """<input type='keyboard' bus='{}'/>""".format('virtio' if virtio else 'usb')
xml += """<input type='tablet' bus='{}'/>""".format('virtio' if virtio else 'usb')
else:
xml += """<input type='mouse'/>"""
xml += """<input type='keyboard'/>"""
xml += """<input type='tablet'/>"""
xml += """
<graphics type='%s' port='-1' autoport='yes' %s listen='%s'/>

View file

@ -158,17 +158,21 @@ INSTANCE_VOLUME_DEFAULT_FORMAT = 'qcow2'
# available bus types: virtio, scsi, ide, usb, sata
INSTANCE_VOLUME_DEFAULT_BUS = 'virtio'
#SCSI types: 'virtio-scsi', 'lsilogic'
#SCSI types: virtio-scsi, lsilogic
INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER = 'virtio-scsi'
# Volume optionals: two variable: disk driver type is file and network(rbd, iscsi),
# optionals : discard='unmap|ignore', detect_zeroes='on|off|unmap', copy_on_read='on|off'
# Example: {"file": "discard='unmap' copy_on_read='on'", "network": "detect_zeroes='unmap'"}
INSTANCE_VOLUME_DEFAULT_DRIVER_OPTS = {"file": "", "network": ""}
# available cache types: none, unsafe, writeback, writethrough
# Volume cache: default, directsync, none, unsafe, writeback, writethrough
INSTANCE_VOLUME_DEFAULT_CACHE = 'directsync'
# Volume io mode: default, native, threads
INSTANCE_VOLUME_DEFAULT_IO = 'default'
# Volume detect zeroes mode: default, on, off, unmap
INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES = 'default'
# Volume discard mode: default, unmap, ignore
INSTANCE_VOLUME_DEFAULT_DISCARD = 'default'
# up to os, 0=root, 107=qemu or libvirt-bin(for ubuntu)
INSTANCE_VOLUME_DEFAULT_OWNER = {'uid': 0, 'guid': 0}