From: Nikos Skalkotos Date: Tue, 30 Jul 2013 12:12:25 +0000 (+0300) Subject: Add a function for finding out the kvm binary X-Git-Tag: 0.5~1^2~13^2 X-Git-Url: https://code.grnet.gr/git/snf-image-creator/commitdiff_plain/4246a133c89cf5b457ed0ee51eb4d7d02c5ef4b0 Add a function for finding out the kvm binary On some systems it is kvm, on some others it is qemu-system-x86_64. On 32bit PC it is qemu-system-i386 --- diff --git a/image_creator/os_type/windows.py b/image_creator/os_type/windows.py index 20029a3..6998d49 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 b2b5f55..fcf5dd5 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)