[elbe-devel] [PATCH 3/3] elbepack: init: libvirt: autodetect KVM availability
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu May 16 12:14:30 CEST 2024
Not all environments have KVM available, but want to run ELBE
nevertheless. While it may be slow, it's better than nothing.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/init/libvirt.xml.mako | 2 +-
elbepack/initvmaction.py | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/elbepack/init/libvirt.xml.mako b/elbepack/init/libvirt.xml.mako
index abeb81017fb3..21c346cafd18 100644
--- a/elbepack/init/libvirt.xml.mako
+++ b/elbepack/init/libvirt.xml.mako
@@ -36,7 +36,7 @@ forward += ',hostfwd=%s::%s-:%s' % ("tcp", cfg['soapport'], "7588")
if cfg['sshport'] != '-1':
forward += ',hostfwd=%s::%s-:%s' % ("tcp", cfg['sshport'], "22")
-%><domain type='kvm'
+%><domain type='qemu'
xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>${name}</name>
<uuid>${uid}</uuid>
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 0fee9ac0e2c3..315dfe084089 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -760,6 +760,8 @@ class CreateAction(InitVMAction):
with open(os.path.join(initvmdir, 'libvirt.xml')) as f:
xml = f.read()
+ xml = self._libvirt_enable_kvm(xml)
+
# Register initvm in libvirt.
try:
self.conn.defineXML(xml)
@@ -811,6 +813,18 @@ class CreateAction(InitVMAction):
submit_with_repodir_and_dl_result(xmlfile, cdrom, opt)
+ def _libvirt_enable_kvm(self, xml):
+ caps_tree = etree(io.StringIO(self.conn.getCapabilities()))
+ domain_tree = etree(io.StringIO(xml))
+
+ arch = domain_tree.et.find('.//os/type').attrib['arch']
+
+ if caps_tree.et.find('.//guest/arch[@name=' + arch + ']/domain[@type="kvm"]') is None:
+ return xml
+
+ domain_tree.root.et.attrib['type'] = 'kvm'
+ return domain_tree.tostring()
+
@InitVMAction.register('submit')
class SubmitAction(InitVMAction):
--
2.45.0
More information about the elbe-devel
mailing list