Add a function for finding out the kvm binary
authorNikos Skalkotos <skalkoto@grnet.gr>
Tue, 30 Jul 2013 12:12:25 +0000 (15:12 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Tue, 30 Jul 2013 13:44:00 +0000 (16:44 +0300)
On some systems it is kvm, on some others it is qemu-system-x86_64. On
32bit PC it is qemu-system-i386

image_creator/os_type/windows.py
image_creator/util.py

index 20029a3..6998d49 100644 (file)
@@ -37,7 +37,8 @@
 Windows OSs."""
 
 from image_creator.os_type import OSBase, sysprep, add_sysprep_param
-from image_creator.util import FatalError, check_guestfs_version
+from image_creator.util import FatalError, check_guestfs_version, \
+    get_kvm_binary
 from image_creator.winexe import WinEXE, WinexeTimeout
 
 import hivex
@@ -762,8 +763,13 @@ class _VM(object):
         # Use ganeti's VNC port range for a random vnc port
         self.display = random.randint(11000, 14999) - 5900
 
+        kvm = get_kvm_binary()
+
+        if kvm is None:
+            FatalError("Can't find the kvm binary")
+
         args = [
-            'kvm', '-smp', '1', '-m', '1024', '-drive',
+            kvm, '-smp', '1', '-m', '1024', '-drive',
             'file=%s,format=raw,cache=unsafe,if=virtio' % self.disk,
             '-netdev', 'type=user,hostfwd=tcp::445-:445,id=netdev0',
             '-device', 'virtio-net-pci,mac=%s,netdev=netdev0' % random_mac(),
index b2b5f55..fcf5dd5 100644 (file)
@@ -41,6 +41,7 @@ import sh
 import hashlib
 import time
 import os
+import re
 
 
 class FatalError(Exception):
@@ -63,6 +64,24 @@ def get_command(command):
         return find_sbin_command(command, e)
 
 
+def get_kvm_binary():
+    """Returns the path to the kvm binary"""
+
+    uname = get_command('uname')
+    which = get_command('which')
+
+    machine = str(uname('-m'))
+    if re.match('i[3-6]86', machine):
+        machine = 'i386'
+
+    binary = which('qemu-system-%s' % machine)
+
+    if binary is None:
+        return which('kvm')
+
+    return binary
+
+
 def try_fail_repeat(command, *args):
     """Execute a command multiple times until it succeeds"""
     times = (0.1, 0.5, 1, 2)