File koan-use-kvm-acceleration-if-available.dif of Package koan

Index: koan-2.9.0/koan/qcreate.py
===================================================================
--- koan-2.9.0.orig/koan/qcreate.py
+++ koan-2.9.0/koan/qcreate.py
@@ -25,9 +25,26 @@ requires python-virtinst-0.200 (or virt-
 
 import utils
 import virtinstall
-
+from xml.dom.minidom import parseString
 
 def start_install(*args, **kwargs):
+    if 'arch' in kwargs.keys():
+        kwargs['arch'] = None # use host arch for kvm acceleration
+
+    # Use kvm acceleration if available
+    try:
+        import libvirt
+    except:
+        raise koan.InfoException("package libvirt is required for installing virtual guests")
+    conn = libvirt.openReadOnly(None)
+    # See http://libvirt.org/formatcaps.html
+    capabilities = parseString(conn.getCapabilities())
+    for domain in capabilities.getElementsByTagName("domain"):
+        attributes = dict(domain.attributes.items())
+        if 'type' in attributes.keys() and attributes['type'] == 'kvm':
+            kwargs['virt_type'] = 'kvm'
+            break
+
     virtinstall.create_image_file(*args, **kwargs)
     cmd = virtinstall.build_commandline("qemu:///system", *args, **kwargs)
     rc, result, result_stderr = utils.subprocess_get_response(cmd, ignore_rc=True, get_stderr=True)
openSUSE Build Service is sponsored by