summaryrefslogtreecommitdiff
path: root/virt-install
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2019-06-13 18:40:26 -0400
committerCole Robinson <crobinso@redhat.com>2019-06-13 18:46:58 -0400
commit839eea35873dc9095df1548205867a1ecebd2408 (patch)
tree3e6a410c35f00bcc3090e3c92cb4a49deb2710a9 /virt-install
parentee119c3bb239c287f6c98d7f1f2bf5b94060f828 (diff)
downloadvirt-manager-839eea35873dc9095df1548205867a1ecebd2408.tar.gz
virt-install: Split build_installer out a bit
Diffstat (limited to 'virt-install')
-rwxr-xr-xvirt-install70
1 files changed, 41 insertions, 29 deletions
diff --git a/virt-install b/virt-install
index 57875b0e..55e04d5d 100755
--- a/virt-install
+++ b/virt-install
@@ -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 build_guest_instance(conn, options):
- guest = virtinst.Guest(conn)
- guest.skip_default_osinfo = True
-
+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
+
+ # 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)
- set_cli_defaults(options, guest)
+ installer = build_installer(options, guest, osdata)
+ installer_detect_distro(guest, installer, osdata)
+ 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