mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-08-10 04:58:08 -05:00
virt-install: Split build_installer out a bit
This commit is contained in:
+52
-40
@@ -147,7 +147,7 @@ def convert_old_os_options(options):
|
||||
elif options.old_os_type:
|
||||
distkey = options.old_os_type
|
||||
|
||||
options.os_variant = cli.parse_os_variant(distkey)
|
||||
options.os_variant = distkey
|
||||
del(options.old_os_type)
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ def _show_nographics_warnings(options, guest, installer):
|
||||
return
|
||||
|
||||
|
||||
def show_warnings(options, guest, installer):
|
||||
def show_warnings(options, guest, installer, osdata):
|
||||
if options.pxe and not supports_pxe(guest):
|
||||
logging.warning(_("The guest's network configuration does not support "
|
||||
"PXE"))
|
||||
@@ -353,8 +353,8 @@ def show_warnings(options, guest, installer):
|
||||
# Limit it to hvm x86 guests which presently our defaults
|
||||
# only really matter for
|
||||
if (guest.osinfo.name == "generic" and
|
||||
not options.os_variant.is_none and
|
||||
not options.os_variant.name == "generic" and
|
||||
not osdata.is_none and
|
||||
not osdata.name == "generic" and
|
||||
guest.os.is_x86() and guest.os.is_hvm()):
|
||||
logging.warning(_("No operating system detected, VM performance may "
|
||||
"suffer. Specify an OS with --os-variant for optimal results."))
|
||||
@@ -366,7 +366,7 @@ def show_warnings(options, guest, installer):
|
||||
# Guest building helpers #
|
||||
##########################
|
||||
|
||||
def build_installer(options, guest):
|
||||
def build_installer(options, guest, osdata):
|
||||
cdrom = None
|
||||
location = None
|
||||
location_kernel = None
|
||||
@@ -381,20 +381,20 @@ def build_installer(options, guest):
|
||||
installdata = cli.parse_install(options.install)
|
||||
|
||||
if options.unattended:
|
||||
if options.os_variant.is_none or options.os_variant.is_auto:
|
||||
if osdata.is_none or osdata.is_auto:
|
||||
fail(_("--unattended requires an explicit --os-variant"))
|
||||
if not guest.osinfo.is_windows():
|
||||
if options.cdrom:
|
||||
options.location = options.cdrom
|
||||
options.cdrom = None
|
||||
options.os_variant.install = "location"
|
||||
osdata.install = "location"
|
||||
|
||||
INSTALL_VALUES = ["location"]
|
||||
if options.os_variant.install not in INSTALL_VALUES + [None]:
|
||||
if osdata.install not in INSTALL_VALUES + [None]:
|
||||
fail(_("Unknown --os-variant install value '%s'. Must be one of: %s") %
|
||||
(options.os_variant.install, ", ".join(INSTALL_VALUES)))
|
||||
(osdata.install, ", ".join(INSTALL_VALUES)))
|
||||
|
||||
if options.os_variant.install == "location":
|
||||
if osdata.install == "location":
|
||||
if not options.location:
|
||||
location = guest.osinfo.get_location(guest.os.arch)
|
||||
logging.debug(
|
||||
@@ -452,17 +452,6 @@ def build_installer(options, guest):
|
||||
if options.autostart:
|
||||
installer.autostart = True
|
||||
|
||||
distro = None
|
||||
try:
|
||||
# This also validates the install location
|
||||
autodistro = installer.detect_distro(guest)
|
||||
if options.os_variant.is_auto:
|
||||
distro = autodistro
|
||||
except ValueError as e:
|
||||
fail(_("Error validating install location: %s") % str(e))
|
||||
|
||||
if distro:
|
||||
guest.set_os_name(distro)
|
||||
return installer
|
||||
|
||||
|
||||
@@ -505,25 +494,46 @@ def set_cli_defaults(options, guest):
|
||||
cli.ParserDisk(diskstr, guest=guest).parse(None)
|
||||
|
||||
|
||||
def set_explicit_guest_options(options, guest):
|
||||
if options.name:
|
||||
guest.name = options.name
|
||||
options.name = None
|
||||
if options.uuid:
|
||||
guest.uuid = options.uuid
|
||||
options.uuid = None
|
||||
if options.description:
|
||||
guest.description = options.description
|
||||
options.description = None
|
||||
if options.os_type:
|
||||
guest.os.os_type = options.os_type
|
||||
options.os_type = None
|
||||
if options.virt_type:
|
||||
guest.type = options.virt_type
|
||||
options.virt_type = None
|
||||
if options.arch:
|
||||
guest.os.arch = options.arch
|
||||
options.arch = None
|
||||
if options.machine:
|
||||
guest.os.machine = options.machine
|
||||
options.machine = None
|
||||
|
||||
|
||||
def installer_detect_distro(guest, installer, osdata):
|
||||
try:
|
||||
# This also validates the install location
|
||||
autodistro = installer.detect_distro(guest)
|
||||
if osdata.is_auto and autodistro:
|
||||
guest.set_os_name(autodistro)
|
||||
except ValueError as e:
|
||||
fail(_("Error validating install location: %s") % str(e))
|
||||
|
||||
|
||||
def build_guest_instance(conn, options):
|
||||
guest = virtinst.Guest(conn)
|
||||
guest.skip_default_osinfo = True
|
||||
|
||||
if options.name:
|
||||
guest.name = options.name
|
||||
if options.uuid:
|
||||
guest.uuid = options.uuid
|
||||
if options.description:
|
||||
guest.description = options.description
|
||||
if options.os_type:
|
||||
guest.os.os_type = options.os_type
|
||||
if options.virt_type:
|
||||
guest.type = options.virt_type
|
||||
if options.arch:
|
||||
guest.os.arch = options.arch
|
||||
if options.machine:
|
||||
guest.os.machine = options.machine
|
||||
|
||||
# Fill in guest from the command line content
|
||||
set_explicit_guest_options(options, guest)
|
||||
cli.parse_option_strings(options, guest, None)
|
||||
|
||||
# Call set_capabilities_defaults explicitly here rather than depend
|
||||
@@ -534,12 +544,14 @@ def build_guest_instance(conn, options):
|
||||
|
||||
# If explicit os-variant requested, set it early since it will
|
||||
# provide more defaults in the future
|
||||
osdata = cli.parse_os_variant(options.os_variant)
|
||||
guest.set_default_os_name()
|
||||
options.os_variant.set_os_name(guest)
|
||||
osdata.set_os_name(guest)
|
||||
|
||||
installer = build_installer(options, guest, osdata)
|
||||
installer_detect_distro(guest, installer, osdata)
|
||||
|
||||
installer = build_installer(options, guest)
|
||||
set_cli_defaults(options, guest)
|
||||
|
||||
installer.set_install_defaults(guest)
|
||||
for path in installer.get_search_paths(guest):
|
||||
cli.check_path_search(guest.conn, path)
|
||||
@@ -549,7 +561,7 @@ def build_guest_instance(conn, options):
|
||||
cli.validate_disk(disk)
|
||||
|
||||
validate_required_options(options, guest, installer)
|
||||
show_warnings(options, guest, installer)
|
||||
show_warnings(options, guest, installer, osdata)
|
||||
|
||||
return guest, installer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user