Skip to content

Commit

Permalink
Determine QEMU executable via libvirt API
Browse files Browse the repository at this point in the history
  • Loading branch information
erosennin committed Jan 18, 2018
1 parent 158f22d commit 4b4b833
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions nixops/backends/libvirtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import string
import subprocess
import time
from xml.etree import ElementTree

import libvirt

from nixops.backends import MachineDefinition, MachineState
Expand Down Expand Up @@ -141,6 +143,11 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.primary_net = defn.networks[0]
self.uri = defn.uri

# required for virConnectGetDomainCapabilities()
# https://libvirt.org/formatdomaincaps.html
if self.conn.getLibVersion() < 1002007:
raise Exception('libvirt 1.2.7 or newer is required at the target host')

if not self.primary_mac:
self._generate_primary_mac()
if not self.client_public_key:
Expand Down Expand Up @@ -217,10 +224,15 @@ def read_file(stream, nbytes, f):
stream.sendAll(read_file, f)
stream.finish()

def _qemu_executable(self):
domaincaps_xml = self.conn.getDomainCapabilities(
emulatorbin=None, arch='x86_64', machine=None, virttype='kvm',
)
domaincaps = ElementTree.fromstring(domaincaps_xml)
return domaincaps.find('./path').text.strip()

def _make_domain_xml(self, defn):
qemu_executable = "qemu-system-x86_64"
qemu = spawn.find_executable(qemu_executable)
assert qemu is not None, "{} executable not found. Please install QEMU first.".format(qemu_executable)
qemu = self._qemu_executable()

def maybe_mac(n):
if n == self.primary_net:
Expand Down

0 comments on commit 4b4b833

Please sign in to comment.