[virt-tools-list] [virt-manager PATCH 07/12] unattended: Prefer cdrom instead of floppy for Windows
Fabiano Fidêncio
fidencio at redhat.com
Thu Jun 6 14:11:38 UTC 2019
Instead of using "floppy" as the way to perform unattended installations
for Windows, let's prefer using "cdrom" instead.
The main reasons behind this change are:
- VMs using q35 may have floppy device disabled in some systems;
- We can drop mtools dependency;
Generating the ISO depends on genisofs, which is not a big deal as it's
already a virt-manager dependency.
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
virt-manager.spec.in | 5 -----
virtinst/cdrominject.py | 26 ++++++++++++++++++++++++++
virtinst/floppyinject.py | 35 -----------------------------------
virtinst/installer.py | 31 ++++++++++++++++---------------
virtinst/unattended.py | 2 +-
5 files changed, 43 insertions(+), 56 deletions(-)
create mode 100644 virtinst/cdrominject.py
delete mode 100644 virtinst/floppyinject.py
diff --git a/virt-manager.spec.in b/virt-manager.spec.in
index b5f6979b..43e0c10b 100644
--- a/virt-manager.spec.in
+++ b/virt-manager.spec.in
@@ -48,11 +48,6 @@ Requires: dconf
# no ambiguity.
Requires: vte291
-# Those two dependencies are needed in order to support unattended
-# installation for Windows guests.
-Requires: dosfstools
-Requires: mtools
-
# Weak dependencies for the common virt-manager usecase
Recommends: (libvirt-daemon-kvm or libvirt-daemon-qemu)
Recommends: libvirt-daemon-config-network
diff --git a/virtinst/cdrominject.py b/virtinst/cdrominject.py
new file mode 100644
index 00000000..48ee4253
--- /dev/null
+++ b/virtinst/cdrominject.py
@@ -0,0 +1,26 @@
+#
+# Copyright 2019 Red Hat, Inc.
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+import logging
+import os
+import shutil
+import subprocess
+
+from . import util
+
+
+def perform_cdrom_injections():
+ """
+ Insert files into the root directory of an ISO.
+ """
+ scratch = util.get_unattended_cache_dir()
+ iso = os.path.join(scratch, "unattended.iso")
+
+ cmd = ["mkisofs", "-o", iso, "-J", "-input-charset", "utf8", "-r", scratch]
+ output = subprocess.check_output(cmd)
+ logging.debug("cmd output: %s", output)
+
+ return iso
diff --git a/virtinst/floppyinject.py b/virtinst/floppyinject.py
deleted file mode 100644
index baa38b8f..00000000
--- a/virtinst/floppyinject.py
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# Copyright 2019 Red Hat, Inc.
-#
-# This work is licensed under the GNU GPLv2 or later.
-# See the COPYING file in the top-level directory.
-
-import logging
-import os
-import subprocess
-
-from . import util
-
-
-def perform_floppy_injections(injections):
- """
- Insert files into the root directory of a floppy
- """
- if not injections:
- return
-
- scratch = util.make_unattended_cache_dir()
- img = os.path.join(scratch, "unattended.img")
-
- cmd = ["mkfs.msdos", "-C", img, "1440"]
- logging.debug("Running mkisofs: %s", cmd)
- output = subprocess.check_output(cmd)
- logging.debug("cmd output: %s", output)
-
- for filename in injections:
- logging.debug("Copying %s to the floppy.", filename)
- cmd = ["mcopy", "-i", img, filename, "::"]
- output = subprocess.check_output(cmd)
- logging.debug("cmd output: %s", output)
-
- return img
diff --git a/virtinst/installer.py b/virtinst/installer.py
index 48052450..642d14b3 100644
--- a/virtinst/installer.py
+++ b/virtinst/installer.py
@@ -15,7 +15,7 @@ from .devices import DeviceDisk
from .domain import DomainOs
from .osdict import OSDB, OsMedia
from .installertreemedia import InstallerTreeMedia
-from .floppyinject import perform_floppy_injections
+from .cdrominject import perform_cdrom_injections
from . import unattended
from . import util
@@ -51,7 +51,7 @@ class Installer(object):
self._install_kernel = None
self._install_initrd = None
self._install_cdrom_device_added = False
- self._install_floppy_device = False
+ self._unattended_install_cdrom_device = None
self._unattended_files = []
self._defaults_are_set = False
self._unattended_data = None
@@ -119,25 +119,26 @@ class Installer(object):
disk.sync_path_props()
break
- def _add_install_floppy_device(self, guest, location):
- if self._install_floppy_device:
+ def _add_unattended_cdrom_device(self, guest, location):
+ if self._unattended_install_cdrom_device:
return
dev = DeviceDisk(self.conn)
- dev.device = dev.DEVICE_FLOPPY
+ dev.device = dev.DEVICE_CDROM
dev.path = location
dev.sync_path_props()
dev.validate()
dev.set_defaults(guest)
- self._install_floppy_device = dev
- guest.add_device(self._install_floppy_device)
+ self._unattended_install_cdrom_device = dev
+ guest.add_device(self._unattended_install_cdrom_device)
- def _remove_install_floppy_device(self, guest):
+ def _remove_unattended_cdrom_device(self, guest):
dummy = guest
- if not self._install_floppy_device:
+ if not self._unattended_install_cdrom_device:
return
- self._install_floppy_device.path = None
- self._install_floppy_device.sync_path_props()
+ guest.remove_device(self._unattended_install_cdrom_device)
+ self._unattended_install_cdrom_device.path = None
+ self._unattended_install_cdrom_device.sync_path_props()
def _cleanup_unattended_files(self):
if not self._unattended_files:
@@ -236,10 +237,10 @@ class Installer(object):
logging.debug("Generated script contents:\n%s",
open(path).read())
- floppy = perform_floppy_injections([path])
- self._add_install_floppy_device(guest, floppy)
+ cdrom = perform_cdrom_injections()
+ self._add_unattended_cdrom_device(guest, cdrom)
- self._unattended_files.extend([path, floppy])
+ self._unattended_files.extend([path, cdrom])
def _cleanup(self, guest):
if self._treemedia:
@@ -388,7 +389,7 @@ class Installer(object):
return ret
finally:
self._remove_install_cdrom_media(guest)
- self._remove_install_floppy_device(guest)
+ self._remove_unattended_cdrom_device(guest)
self._finish_get_install_xml(guest, data)
def _build_xml(self, guest, meter):
diff --git a/virtinst/unattended.py b/virtinst/unattended.py
index e79c1a47..7a62dc9c 100644
--- a/virtinst/unattended.py
+++ b/virtinst/unattended.py
@@ -251,7 +251,7 @@ def prepare_install_script(guest, unattended_data, url=None, os_media=None):
# For all tree based installations we're going to perform initrd injection
# and install the systems via network.
- injection_method = "floppy" if guest.osinfo.is_windows() else "initrd"
+ injection_method = "cdrom" if guest.osinfo.is_windows() else "initrd"
script.set_preferred_injection_method(injection_method)
installationsource = _get_installation_source(os_media)
--
2.21.0
More information about the virt-tools-list
mailing list