virt-install: Rework install option detection a bit

Add an explicit no_install to Installer to encode that the user is
not expecting an install phase. Use that to determine later if any
install options were specified. This saves later code from having
to deal with installer=None, and is the basis for further clarifications
This commit is contained in:
Cole Robinson 2019-06-13 16:15:21 -04:00
parent 3b396e8321
commit f36e8b36bc
2 changed files with 32 additions and 27 deletions

View File

@ -307,7 +307,7 @@ def validate_required_options(options, guest, installer):
msg += "\n" + (
_("--disk storage must be specified (override with --disk none)"))
if not installer:
if not guest.os.is_container() and not installer.options_specified():
msg += "\n" + (
_("An install method must be specified\n(%(methods)s)") %
{"methods": INSTALL_METHODS})
@ -377,8 +377,6 @@ def build_installer(options, guest):
install_initrd = None
install_kernel_args = None
has_installer = True
if options.install:
installdata = cli.parse_install(options.install)
@ -415,26 +413,23 @@ def build_installer(options, guest):
else:
extra_args = [installdata.kernel_args]
no_install = None
if options.location:
(location,
location_kernel,
location_initrd) = cli.parse_location(options.location)
elif options.cdrom:
cdrom = options.cdrom
if options.livecd:
no_install = True
elif options.pxe:
install_bootdev = "network"
elif (guest.os.is_container() or
options.import_install or
options.xmlonly or
options.boot or
installdata):
elif installdata:
pass
else:
has_installer = False
if not has_installer:
# This triggers an error in validate_required_options
return None
elif (options.import_install or
options.xmlonly or
options.boot):
no_install = True
installer = virtinst.Installer(guest.conn,
cdrom=cdrom,
@ -444,10 +439,9 @@ def build_installer(options, guest):
install_bootdev=install_bootdev,
install_kernel=install_kernel,
install_initrd=install_initrd,
install_kernel_args=install_kernel_args)
install_kernel_args=install_kernel_args,
no_install=no_install)
if cdrom and options.livecd:
installer.livecd = True
if options.unattended:
unattended_data = cli.parse_unattended(options.unattended)
installer.set_unattended_data(unattended_data)
@ -543,10 +537,9 @@ def build_guest_instance(conn, options):
installer = build_installer(options, guest)
set_cli_defaults(options, guest)
if installer:
installer.set_install_defaults(guest)
for path in installer.get_search_paths(guest):
cli.check_path_search(guest.conn, path)
installer.set_install_defaults(guest)
for path in installer.get_search_paths(guest):
cli.check_path_search(guest.conn, path)
# cli specific disk validation
for disk in guest.devices.disk:

View File

@ -38,24 +38,27 @@ class Installer(object):
:param install_kernel_args: Kernel args <cmdline> to use. This overwrites
whatever the installer might request, unlike extra_args which will
append arguments.
:param no_install: If True, this installer specifically does not have
an install phase. We are just using it to create the initial XML.
"""
def __init__(self, conn, cdrom=None, location=None, install_bootdev=None,
location_kernel=None, location_initrd=None,
install_kernel=None, install_initrd=None, install_kernel_args=None):
install_kernel=None, install_initrd=None, install_kernel_args=None,
no_install=None):
self.conn = conn
self.livecd = False
# Entry point for virt-manager 'Customize' wizard to change autostart
self.autostart = False
self._install_bootdev = install_bootdev
self._install_cdrom_device_added = False
self._unattended_install_cdrom_device = None
self._tmpfiles = []
self._defaults_are_set = False
self._unattended_data = None
self._install_bootdev = install_bootdev
self._no_install = no_install
self._treemedia = None
self._treemedia_bootconfig = None
self._cdrom = None
@ -267,7 +270,7 @@ class Installer(object):
os.unlink(f)
def _get_postinstall_bootdev(self, guest):
if self.cdrom and self.livecd:
if self.cdrom and self._no_install:
return DomainOs.BOOT_DEVICE_CDROM
if self._install_bootdev:
@ -350,12 +353,21 @@ class Installer(object):
into the guest. Things like LiveCDs, Import, or a manually specified
bootorder do not have an install phase.
"""
if self.cdrom and self.livecd:
if self._no_install:
return False
return bool(self._cdrom or
self._install_bootdev or
self._treemedia)
def options_specified(self):
"""
Return True if some explicit install option was actually passed in
Validate that some install option was actually passed in.
"""
if self._no_install:
return True
return self.has_install_phase()
def detect_distro(self, guest):
"""
Attempt to detect the distro for the Installer's 'location'. If