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

Index: cobbler-2.6.6/koan/qcreate.py
===================================================================
--- cobbler-2.6.6.orig/koan/qcreate.py
+++ cobbler-2.6.6/koan/qcreate.py
@@ -25,8 +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)
     utils.subprocess_call(cmd)
openSUSE Build Service is sponsored by