installer: Drop isinstall parameter

Separate the install from postinstall config case more clearly,
so the installer is only ever altering bits for the install-time
case, and Guest handles actually writing postinstall bits
This commit is contained in:
Cole Robinson 2018-09-03 11:47:59 -04:00
parent 068c8aedd2
commit 1abbdfc551
4 changed files with 62 additions and 69 deletions

View File

@ -120,19 +120,19 @@ class DistroInstaller(Installer):
# Private installer impls #
###########################
def _get_bootdev(self, isinstall, guest):
def _is_persistent_cd(self):
mediatype = self._get_media_type()
local = mediatype in [MEDIA_CDROM_PATH, MEDIA_CDROM_IMPLIED,
MEDIA_LOCATION_DIR, MEDIA_LOCATION_CDROM]
persistent_cd = (local and
self.cdrom and
self.livecd)
persistent_cd = bool(local and self.cdrom and self.livecd)
return persistent_cd
if isinstall or persistent_cd:
bootdev = "cdrom"
else:
bootdev = "hd"
return bootdev
def _get_install_bootdev(self, _guest):
return "cdrom"
def _get_postinstall_bootdev(self, _guest):
if self._is_persistent_cd():
return "cdrom"
return "hd"
def _validate_location(self, val):
"""

View File

@ -119,5 +119,3 @@ class DomainOs(XMLBuilder):
self.init = "/sbin/init"
else:
self.init = "/bin/sh"
if self.kernel or self.init:
self.bootorder = []

View File

@ -318,27 +318,8 @@ class Guest(XMLBuilder):
finally:
self._finish_get_install_xml(data)
def _do_get_install_xml(self, install):
"""
Return the full Guest xml configuration.
@install: Whether we want the 'OS install' configuration or
the 'post-install' configuration. The difference is mostly
whether the install media is attached and set as the boot
device. Some installs, like an import or livecd, do not have
an 'install' config.
"""
if install and not self.installer.has_install_phase():
return None
self.installer.alter_bootconfig(self, install)
if not install:
self._remove_cdrom_install_media()
if install:
self.on_reboot = "destroy"
self.os.set_defaults(self)
def _do_get_install_xml(self):
self.installer.alter_bootconfig(self)
return self.get_xml()
@ -347,8 +328,11 @@ class Guest(XMLBuilder):
###########################
def _build_xml(self):
install_xml = self._get_install_xml(install=True)
final_xml = self._get_install_xml(install=False)
install_xml = None
if self.installer.has_install_phase():
install_xml = self._get_install_xml()
self._remove_cdrom_install_media()
final_xml = self.get_xml()
logging.debug("Generated install XML: %s",
(install_xml and ("\n" + install_xml) or "None required"))
@ -752,12 +736,19 @@ class Guest(XMLBuilder):
self.emulator = None
self._add_install_cdrom()
if (not self.os.is_container() and
not self.os.kernel and
not self.os.bootorder and
not any([d.boot.order for d in self.devices.get_all()])):
self.os.bootorder = self.installer.get_postinstall_bootorder(self)
self.clock.set_defaults(self)
self.cpu.set_defaults(self)
self.features.set_defaults(self)
for seclabel in self.seclabels:
seclabel.set_defaults(self)
self.pm.set_defaults(self)
self.os.set_defaults(self)
for dev in self.devices.get_all():
dev.set_defaults(self)

View File

@ -71,8 +71,8 @@ class Installer(object):
# Private helpers #
###################
def _build_boot_order(self, isinstall, guest):
bootorder = [self._get_bootdev(isinstall, guest)]
def _build_boot_order(self, guest, bootdev):
bootorder = [bootdev]
# If guest has an attached disk, always have 'hd' in the boot
# list, so disks are marked as bootable/installable (needed for
@ -85,27 +85,14 @@ class Installer(object):
break
return bootorder
def alter_bootconfig(self, guest, isinstall):
def alter_bootconfig(self, guest):
"""
Generate the portion of the guest xml that determines boot devices
and parameters. (typically the <os></os> block)
:param guest: Guest instance we are installing
:param isinstall: Whether we want xml for the 'install' phase or the
'post-install' phase.
"""
if isinstall and not self.has_install_phase():
return
bootorder = guest.os.bootorder
if isinstall or not bootorder:
# Per device <boot order> is not compatible with os/boot.
if not any(d.boot.order for d in guest.devices.get_all()):
bootorder = self._build_boot_order(isinstall, guest)
guest.os.bootorder = bootorder
if not isinstall:
return
guest.on_reboot = "destroy"
if self._install_kernel:
guest.os.kernel = self._install_kernel
@ -114,13 +101,32 @@ class Installer(object):
if self.extraargs:
guest.os.kernel_args = " ".join(self.extraargs)
bootdev = self._get_install_bootdev(guest)
if (bootdev and
not guest.os.is_container() and
not guest.os.kernel and
not any(d.boot.order for d in guest.devices.get_all())):
guest.os.bootorder = self._build_boot_order(guest, bootdev)
else:
guest.os.bootorder = []
##########################
# Internal API overrides #
##########################
def _get_bootdev(self, isinstall, guest):
ignore = isinstall
def _validate_location(self, val):
return val
def _prepare(self, guest, meter):
ignore = guest
ignore = meter
def _get_install_bootdev(self, guest):
ignore = guest
return None
def _get_postinstall_bootdev(self, guest):
device = guest.devices.disk and guest.devices.disk[0].device or None
if device == DeviceDisk.DEVICE_DISK:
return DomainOs.BOOT_DEVICE_HARDDISK
@ -130,18 +136,18 @@ class Installer(object):
return DomainOs.BOOT_DEVICE_FLOPPY
return DomainOs.BOOT_DEVICE_HARDDISK
def _validate_location(self, val):
return val
def _prepare(self, guest, meter):
ignore = guest
ignore = meter
##############
# Public API #
##############
def get_postinstall_bootorder(self, guest):
"""
Return the preferred guest postinstall bootorder
"""
bootdev = self._get_postinstall_bootdev(guest)
return self._build_boot_order(guest, bootdev)
def scratchdir_required(self):
"""
Returns true if scratchdir is needed for the passed install parameters.
@ -216,16 +222,14 @@ class Installer(object):
class PXEInstaller(Installer):
def _get_bootdev(self, isinstall, guest):
bootdev = DomainOs.BOOT_DEVICE_NETWORK
def _get_install_bootdev(self, guest):
ignore = guest
return DomainOs.BOOT_DEVICE_NETWORK
if (not isinstall and
[d for d in guest.devices.disk if
d.device == d.DEVICE_DISK]):
# If doing post-install boot and guest has an HD attached
bootdev = DomainOs.BOOT_DEVICE_HARDDISK
return bootdev
def _get_postinstall_bootdev(self, guest):
if any([d for d in guest.devices.disk if d.device == d.DEVICE_DISK]):
return DomainOs.BOOT_DEVICE_HARDDISK
return DomainOs.BOOT_DEVICE_NETWORK
def has_install_phase(self):
return True