diff --git a/image_creator/os_type/windows.py b/image_creator/os_type/windows.py index 20029a33c3461d798a8620643fbdfa02c2dd409b..6998d491ac623c56ed89889277d9d676620b58b4 100644 --- a/image_creator/os_type/windows.py +++ b/image_creator/os_type/windows.py @@ -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(), diff --git a/image_creator/util.py b/image_creator/util.py index b2b5f55ef209f6015e0500ad0c771dba9efa5047..fcf5dd526fa9683c420b02f92439d319f6e215c3 100644 --- a/image_creator/util.py +++ b/image_creator/util.py @@ -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)