1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Enrich Instance Create operation: -add capability to create arm, ppc, i686, aarch64 instances, -add option to choose firmware, -add options to choose chipset. -add capability to choose volume driver options. -add new default settings

This commit is contained in:
catborise 2019-12-13 16:47:51 +03:00
parent 28b001e7cb
commit dd16a5b2d5
14 changed files with 828 additions and 211 deletions

View file

@ -1,9 +1,11 @@
import string
from vrtManager import util
from vrtManager.connection import wvmConnect
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as default_owner
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
def get_rbd_storage_data(stg):
@ -11,7 +13,7 @@ def get_rbd_storage_data(stg):
ceph_user = util.get_xml_path(xml, "/pool/source/auth/@username")
def get_ceph_hosts(doc):
hosts = []
hosts = list()
for host in doc.xpath("/pool/source/host"):
name = host.prop("name")
if name:
@ -29,7 +31,7 @@ class wvmCreate(wvmConnect):
"""
Function return all images on all storages
"""
images = []
images = list()
storages = self.get_storages(only_actives=True)
for storage in storages:
stg = self.get_storage(storage)
@ -45,14 +47,14 @@ class wvmCreate(wvmConnect):
return images
def get_os_type(self):
"""Get guest capabilities"""
"""Get guest os type"""
return util.get_xml_path(self.get_cap_xml(), "/capabilities/guest/os_type")
def get_host_arch(self):
"""Get guest capabilities"""
return util.get_xml_path(self.get_cap_xml(), "/capabilities/host/cpu/arch")
def create_volume(self, storage, name, size, image_format=image_format, metadata=False, owner=default_owner):
def create_volume(self, storage, name, size, image_format=image_format, metadata=False, owner=DEFAULT_OWNER):
size = int(size) * 1073741824
stg = self.get_storage(storage)
storage_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
@ -120,7 +122,7 @@ class wvmCreate(wvmConnect):
vol = self.get_volume_by_path(vol_path)
return vol.storagePoolLookupByVolume()
def clone_from_template(self, clone, template, storage=None, metadata=False, owner=default_owner):
def clone_from_template(self, clone, template, storage=None, metadata=False, owner=DEFAULT_OWNER):
vol = self.get_volume_by_path(template)
if not storage:
stg = vol.storagePoolLookupByVolume()
@ -163,16 +165,15 @@ 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, listen_addr, nwfilter=None, video="cirrus", console_pass="random", mac=None, qemu_ga=False):
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):
"""
Create VM function
"""
memory = int(memory) * 1024
caps = self.get_capabilities(arch)
dom_caps = self.get_dom_capabilities(arch, machine)
if self.is_kvm_supported():
hypervisor_type = 'kvm'
else:
hypervisor_type = 'qemu'
memory = int(memory) * 1024
#hypervisor_type = 'kvm' if self.is_kvm_supported() else 'qemu'
xml = """
<domain type='%s'>
@ -180,23 +181,46 @@ class wvmCreate(wvmConnect):
<description>None</description>
<uuid>%s</uuid>
<memory unit='KiB'>%s</memory>
<vcpu>%s</vcpu>""" % (hypervisor_type, name, uuid, memory, vcpu)
if host_model:
<vcpu>%s</vcpu>""" % (dom_caps["domain"], name, uuid, memory, vcpu)
if dom_caps["os_support"] == 'yes':
xml += """<os>
<type arch='%s' machine='%s'>%s</type>""" % (arch, machine, caps["os_type"])
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()
xml += """</os>"""
if caps["features"]:
xml += """<features>"""
if 'acpi' in caps["features"]:
xml += """<acpi/>"""
if 'apic' in caps["features"]:
xml += """<apic/>"""
if 'pae' in caps["features"]:
xml += """<pae/>"""
xml += """</features>"""
if vcpu_mode == "host-model":
xml += """<cpu mode='host-model'/>"""
xml += """<os>
<type arch='%s'>%s</type>
<boot dev='hd'/>
<boot dev='cdrom'/>
<bootmenu enable='yes'/>
</os>""" % (self.get_host_arch(), self.get_os_type())
xml += """<features>
<acpi/><apic/><pae/>
</features>
elif vcpu_mode == "host-passthrough":
xml += """<cpu mode='host-passthrough'/>"""
elif vcpu_mode == "":
pass
else:
xml += """<cpu mode='custom' match='exact' check='none'>
<model fallback='allow'>{}</model>
</cpu>""".format(vcpu_mode)
xml += """
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>"""
"""
xml += """<devices>"""
vd_disk_letters = list(string.lowercase)
fd_disk_letters = list(string.lowercase)
@ -212,11 +236,11 @@ 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'/>
<auth username='%s'>
<driver name='qemu' type='%s' cache='%s' %s />""" % (volume['type'], cache_mode, OPTS.get("network", ''))
xml += """ <auth username='%s'>
<secret type='ceph' uuid='%s'/>
</auth>
<source protocol='rbd' name='%s'>""" % (volume['type'], cache_mode, ceph_user, secret_uuid, volume['path'])
<source protocol='rbd' name='%s'>""" % (ceph_user, secret_uuid, volume['path'])
if isinstance(ceph_hosts, list):
for host in ceph_hosts:
if host.get('port'):
@ -225,12 +249,11 @@ class wvmCreate(wvmConnect):
else:
xml += """
<host name='%s'/>""" % host.get('name')
xml += """
</source>"""
xml += """</source>"""
else:
xml += """<disk type='file' device='%s'>
<driver name='qemu' type='%s' cache='%s'/>
<source file='%s'/>""" % (volume['device'], volume['type'], cache_mode, volume['path'])
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 += """ <source file='%s'/>""" % volume['path']
if volume['bus'] == 'virtio':
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), volume['bus'])
@ -242,12 +265,23 @@ class wvmCreate(wvmConnect):
xml += """<target dev='sd%s' bus='%s'/>""" % (sd_disk_letters.pop(0), volume['bus'])
xml += """</disk>"""
if add_cd:
xml += """ <disk type='file' device='cdrom'>
xml += """<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file=''/>
<target dev='hd%s' bus='ide'/>
<readonly/>
</disk>""" % (hd_disk_letters.pop(0),)
<source file = '' />
<readonly/>"""
if 'ide' in dom_caps['disk_bus']:
xml += """<target dev='hd%s' bus='%s'/>""" % (hd_disk_letters.pop(0), 'ide')
elif 'sata' in dom_caps['disk_bus']:
xml += """<target dev='sd%s' bus='%s'/>""" % (sd_disk_letters.pop(0), 'sata')
elif 'scsi' in dom_caps['disk_bus']:
xml += """<target dev='sd%s' bus='%s'/>""" % (sd_disk_letters.pop(0), 'scsi')
else:
xml += """<target dev='vd%s' bus='%s'/>""" % (vd_disk_letters.pop(0), 'virtio')
xml += """</disk>"""
if volume['bus'] == 'scsi':
xml += """<controller type='scsi' model='%s'/>""" % INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER
for net in networks.split(','):
xml += """<interface type='network'>"""
if mac:
@ -265,10 +299,11 @@ class wvmCreate(wvmConnect):
if not console_pass == "":
console_pass = "passwd='" + console_pass + "'"
xml += """ <input type='mouse' bus='ps2'/>
<input type='tablet' bus='usb'/>
<graphics type='%s' port='-1' autoport='yes' %s listen='%s'/>
<console type='pty'/> """ % (QEMU_CONSOLE_DEFAULT_TYPE, console_pass, listen_addr)
xml += """<input type='mouse' bus='virtio'/>"""
xml += """<input type='tablet' bus='virtio'/>"""
xml += """
<graphics type='%s' port='-1' autoport='yes' %s listen='%s'/>
<console type='pty'/> """ % (graphics, console_pass, listen_addr)
if qemu_ga:
xml += """ <channel type='unix'>
@ -278,7 +313,6 @@ class wvmCreate(wvmConnect):
xml += """ <video>
<model type='%s'/>
</video>
<memballoon model='virtio'/>
</devices>
</domain>""" % video
self._defineXML(xml)