Created
February 2, 2018 11:42
-
-
Save flokli/869308cf0e64c6d657fbcd3abf7bbc96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 15a7a469957bc37915e8428f77cbcc6f2c54b364 Mon Sep 17 00:00:00 2001 | |
From: Florian Klink <flokli@flokli.de> | |
Date: Fri, 2 Feb 2018 00:37:37 +0100 | |
Subject: [PATCH 1/2] libvirtd: remove unused imports | |
--- | |
nixops/backends/libvirtd.py | 11 ++++------- | |
1 file changed, 4 insertions(+), 7 deletions(-) | |
diff --git a/nixops/backends/libvirtd.py b/nixops/backends/libvirtd.py | |
index 0e6e270..cef32b0 100644 | |
--- a/nixops/backends/libvirtd.py | |
+++ b/nixops/backends/libvirtd.py | |
@@ -1,21 +1,19 @@ | |
# -*- coding: utf-8 -*- | |
-from distutils import spawn | |
-import os | |
import copy | |
import json | |
+import os | |
import random | |
import shutil | |
-import string | |
-import subprocess | |
import time | |
from xml.etree import ElementTree | |
import libvirt | |
-from nixops.backends import MachineDefinition, MachineState | |
import nixops.known_hosts | |
import nixops.util | |
+from nixops.backends import MachineDefinition, MachineState | |
+ | |
# to prevent libvirt errors from appearing on screen, see | |
# https://www.redhat.com/archives/libvirt-users/2017-August/msg00011.html | |
@@ -254,10 +252,9 @@ class LibvirtdState(MachineState): | |
' <type arch="x86_64">hvm</type>', | |
" <kernel>%s</kernel>" % defn.kernel, | |
" <initrd>%s</initrd>" % defn.initrd if len(defn.kernel) > 0 else "", | |
- " <cmdline>%s</cmdline>"% defn.cmdline if len(defn.kernel) > 0 else "", | |
+ " <cmdline>%s</cmdline>" % defn.cmdline if len(defn.kernel) > 0 else "", | |
'</os>'] | |
- | |
domain_fmt = "\n".join([ | |
'<domain type="{5}">', | |
' <name>{0}</name>', | |
-- | |
2.16.1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 101de7ea198649b88fc620c0c3b5d76cc2e5f616 Mon Sep 17 00:00:00 2001 | |
From: Florian Klink <flokli@flokli.de> | |
Date: Fri, 2 Feb 2018 12:36:38 +0100 | |
Subject: [PATCH 2/2] backends.libvirtd: use machine name for temp_image_path | |
Otherwise, deployments with multiple VMs try to write to the same image. | |
Also, do the temp_image_path calculation only once. | |
--- | |
nixops/backends/libvirtd.py | 10 ++++++---- | |
1 file changed, 6 insertions(+), 4 deletions(-) | |
diff --git a/nixops/backends/libvirtd.py b/nixops/backends/libvirtd.py | |
index cef32b0..18f20bb 100644 | |
--- a/nixops/backends/libvirtd.py | |
+++ b/nixops/backends/libvirtd.py | |
@@ -169,15 +169,17 @@ class LibvirtdState(MachineState): | |
self.log("preparing disk image...") | |
newEnv = copy.deepcopy(os.environ) | |
newEnv["NIXOPS_LIBVIRTD_PUBKEY"] = self.client_public_key | |
+ | |
+ temp_image_path = os.path.join(self.depl.tempdir, 'libvirtd-image-{}'.format(self.name)) | |
base_image = self._logged_exec( | |
["nix-build"] + self.depl._eval_flags(self.depl.nix_exprs) + | |
["--arg", "checkConfigurationOptions", "false", | |
"-A", "nodes.{0}.config.deployment.libvirtd.baseImage".format(self.name), | |
- "-o", "{0}/libvirtd-image-{1}".format(self.depl.tempdir, self.name)], | |
+ "-o", temp_image_path], | |
capture_stdout=True, env=newEnv).rstrip() | |
- temp_disk_path = os.path.join(self.depl.tempdir, 'disk.qcow2') | |
- shutil.copyfile(base_image + "/disk.qcow2", temp_disk_path) | |
+ temp_disk_path = os.path.join(self.depl.tempdir, 'disk-{}.qcow2'.format(self.name)) | |
+ shutil.copyfile(os.path.join(temp_image_path, 'disk.qcow2'), temp_disk_path) | |
# Rebase onto empty backing file to prevent breaking the disk image | |
# when the backing file gets garbage collected. | |
self._logged_exec(["qemu-img", "rebase", "-f", "qcow2", "-b", | |
@@ -293,7 +295,7 @@ class LibvirtdState(MachineState): | |
""" | |
# alternative is VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE if qemu agent is available | |
ifaces = self.dom.interfaceAddresses(libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, 0) | |
- if (ifaces == None): | |
+ if ifaces is None: | |
self.log("Failed to get domain interfaces") | |
return | |
-- | |
2.16.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment