2018-01-27 23:46:39 +03:00
#!/usr/bin/env python3
2013-03-18 01:06:52 +04:00
#
2014-02-12 13:21:38 +04:00
# Copyright 2005-2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
2014-01-19 02:01:43 +04:00
import argparse
import logging
2016-06-17 19:09:45 +03:00
import os
2014-01-19 02:01:43 +04:00
import re
2013-03-18 01:06:52 +04:00
import sys
import time
2013-08-09 23:00:16 +04:00
import libvirt
2013-03-18 01:06:52 +04:00
import virtinst
2014-09-20 04:31:22 +04:00
from virtinst import cli
2013-03-18 01:06:52 +04:00
from virtinst.cli import fail, print_stdout, print_stderr
##############################
# Validation utility helpers #
##############################
install_methods = "--location URL, --cdrom CD/ISO, --pxe, --import, --boot hd|cdrom|..."
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
def install_specified(location, cdpath, pxe, import_install):
return bool(pxe or cdpath or location or import_install)
2013-04-13 22:34:52 +04:00
2014-01-21 03:04:23 +04:00
def cdrom_specified(guest, disk=None):
2018-03-21 00:23:34 +03:00
disks = guest.devices.disk
2013-04-12 17:39:34 +04:00
2017-06-15 15:18:26 +03:00
for d in disks:
2018-03-20 19:18:35 +03:00
if d.device == virtinst.DeviceDisk.DEVICE_CDROM:
2013-03-18 01:06:52 +04:00
return True
# Probably haven't set up disks yet
2014-01-21 03:04:23 +04:00
if not disks and disk:
for opts in disk:
2013-03-18 01:06:52 +04:00
if opts.count("device=cdrom"):
return True
return False
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
def supports_pxe(guest):
"""
Return False if we are pretty sure the config doesn't support PXE
"""
2018-03-21 00:23:34 +03:00
for nic in guest.devices.interface:
2013-03-18 01:06:52 +04:00
if nic.type == nic.TYPE_USER:
continue
if nic.type != nic.TYPE_VIRTUAL:
return True
try:
2013-09-24 18:00:01 +04:00
netobj = nic.conn.networkLookupByName(nic.source)
2013-09-23 01:04:22 +04:00
xmlobj = virtinst.Network(nic.conn, parsexml=netobj.XMLDesc(0))
if xmlobj.can_pxe():
2013-03-18 01:06:52 +04:00
return True
2017-07-24 11:26:48 +03:00
except Exception:
2013-03-18 01:06:52 +04:00
logging.debug("Error checking if PXE supported", exc_info=True)
return True
return False
2013-04-21 20:28:14 +04:00
def check_cdrom_option_error(options):
if options.cdrom_short and options.cdrom:
fail("Cannot specify both -c and --cdrom")
if options.cdrom_short:
if "://" in options.cdrom_short:
fail("-c specified with what looks like a URI. Did you mean "
"to use --connect? If not, use --cdrom instead")
options.cdrom = options.cdrom_short
2013-04-04 20:04:07 +04:00
if not options.cdrom:
return
2013-04-21 20:28:14 +04:00
# Catch a strangely common error of users passing -vcpus=2 instead of
# --vcpus=2. The single dash happens to map to enough shortened options
# that things can fail weirdly if --paravirt is also specified.
2013-04-04 20:04:07 +04:00
for vcpu in [o for o in sys.argv if o.startswith("-vcpu")]:
if options.cdrom == vcpu[3:]:
fail("You specified -vcpus, you want --vcpus")
2015-04-05 00:10:45 +03:00
#################################
# Back compat option conversion #
#################################
def convert_old_printxml(options):
if options.xmlstep:
options.xmlonly = options.xmlstep
del(options.xmlstep)
2013-03-18 01:06:52 +04:00
2013-09-28 04:16:35 +04:00
def convert_old_sound(options):
2014-02-05 21:32:53 +04:00
if not options.sound:
2013-09-28 04:16:35 +04:00
return
2014-02-05 21:32:53 +04:00
for idx in range(len(options.sound)):
if options.sound[idx] is None:
options.sound[idx] = "default"
2013-03-18 01:06:52 +04:00
2014-01-22 00:36:34 +04:00
def convert_old_init(options):
if not options.init:
return
if not options.boot:
options.boot = ""
options.boot += ",init=%s" % options.init
logging.debug("Converted old --init to --boot %s", options.boot)
2014-09-21 03:16:13 +04:00
def _do_convert_old_disks(options):
2013-09-28 04:16:35 +04:00
paths = virtinst.util.listify(options.file_paths)
sizes = virtinst.util.listify(options.disksize)
2013-03-18 01:06:52 +04:00
def padlist(l, padsize):
2013-09-28 04:16:35 +04:00
l = virtinst.util.listify(l)
2013-03-18 01:06:52 +04:00
l.extend((padsize - len(l)) * [None])
return l
2013-09-28 04:16:35 +04:00
disklist = padlist(paths, max(0, len(sizes)))
sizelist = padlist(sizes, len(disklist))
2013-03-18 01:06:52 +04:00
2013-09-28 04:16:35 +04:00
opts = []
2016-04-18 23:42:12 +03:00
for idx, path in enumerate(disklist):
2013-09-28 04:16:35 +04:00
optstr = ""
2016-04-18 23:42:12 +03:00
if path:
optstr += "path=%s" % path
2013-09-28 04:16:35 +04:00
if sizelist[idx]:
if optstr:
optstr += ","
optstr += "size=%s" % sizelist[idx]
if options.sparse is False:
if optstr:
optstr += ","
optstr += "sparse=no"
logging.debug("Converted to new style: --disk %s", optstr)
opts.append(optstr)
2014-01-21 03:04:23 +04:00
options.disk = opts
2014-09-21 03:16:13 +04:00
def convert_old_disks(options):
if options.nodisks and (options.file_paths or
options.disk or
options.disksize):
fail(_("Cannot specify storage and use --nodisks"))
if ((options.file_paths or options.disksize or not options.sparse) and
options.disk):
fail(_("Cannot mix --file, --nonsparse, or --file-size with --disk "
"options. Use --disk PATH[,size=SIZE][,sparse=yes|no]"))
if not options.disk:
if options.nodisks:
options.disk = ["none"]
else:
_do_convert_old_disks(options)
del(options.file_paths)
del(options.disksize)
del(options.sparse)
del(options.nodisks)
logging.debug("Distilled --disk options: %s", options.disk)
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2014-09-07 19:57:04 +04:00
def convert_old_os_options(options):
distro_variant = options.distro_variant
distro_type = options.distro_type
if not distro_type and not distro_variant:
# Default to distro autodetection
options.distro_variant = "auto"
return
distro_variant = distro_variant and str(distro_variant).lower() or None
distro_type = distro_type and str(distro_type).lower() or None
distkey = distro_variant or distro_type
if not distkey or distkey == "none":
options.distro_variant = "none"
else:
options.distro_variant = distkey
2014-09-20 04:31:22 +04:00
def convert_old_memory(options):
if options.memory:
return
if not options.oldmemory:
return
options.memory = str(options.oldmemory)
def convert_old_cpuset(options):
if not options.cpuset:
return
if not options.vcpus:
options.vcpus = ""
options.vcpus += ",cpuset=%s" % options.cpuset
logging.debug("Generated compat cpuset: --vcpus %s", options.vcpus)
2014-09-21 02:56:39 +04:00
def convert_old_networks(options):
if options.nonetworks:
if options.mac:
fail(_("Cannot use --mac with --nonetworks"))
if options.bridge:
fail(_("Cannot use --bridge with --nonetworks"))
if options.network:
fail(_("Cannot use --nonetworks with --network"))
options.network = ["none"]
2015-08-06 15:43:00 +03:00
if options.pxe and options.network and "none" in options.network:
fail(_("Can't use --pxe without any network"))
2014-09-21 02:56:39 +04:00
macs = virtinst.util.listify(options.mac)
2014-09-20 04:31:22 +04:00
networks = virtinst.util.listify(options.network)
2014-09-21 02:56:39 +04:00
bridges = virtinst.util.listify(options.bridge)
2014-09-20 04:31:22 +04:00
if bridges and networks:
fail(_("Cannot mix both --bridge and --network arguments"))
if bridges:
# Convert old --bridges to --networks
networks = ["bridge:" + b for b in bridges]
def padlist(l, padsize):
l = virtinst.util.listify(l)
l.extend((padsize - len(l)) * [None])
return l
# If a plain mac is specified, have it imply a default network
2014-09-21 02:56:39 +04:00
networks = padlist(networks, max(len(macs), 1))
2014-09-20 04:31:22 +04:00
macs = padlist(macs, len(networks))
2016-04-18 23:42:12 +03:00
for idx, ignore in enumerate(networks):
2014-09-20 04:31:22 +04:00
if networks[idx] is None:
networks[idx] = "default"
if macs[idx]:
networks[idx] += ",mac=%s" % macs[idx]
# Handle old format of bridge:foo instead of bridge=foo
for prefix in ["network", "bridge"]:
if networks[idx].startswith(prefix + ":"):
networks[idx] = networks[idx].replace(prefix + ":",
prefix + "=")
2014-09-21 02:56:39 +04:00
del(options.mac)
del(options.bridge)
del(options.nonetworks)
2014-09-20 04:31:22 +04:00
options.network = networks
2014-09-21 02:56:39 +04:00
logging.debug("Distilled --network options: %s", options.network)
2014-09-20 04:31:22 +04:00
2018-06-05 21:43:19 +03:00
def convert_old_graphics(options):
2014-09-20 04:31:22 +04:00
vnc = options.vnc
vncport = options.vncport
vnclisten = options.vnclisten
nographics = options.nographics
sdl = options.sdl
keymap = options.keymap
graphics = options.graphics
if graphics and (vnc or sdl or keymap or vncport or vnclisten):
fail(_("Cannot mix --graphics and old style graphical options"))
optnum = sum([bool(g) for g in [vnc, nographics, sdl, graphics]])
if optnum > 1:
raise ValueError(_("Can't specify more than one of VNC, SDL, "
"--graphics or --nographics"))
if options.graphics:
return
if optnum == 0:
return
# Build a --graphics command line from old style opts
optstr = ((vnc and "vnc") or
(sdl and "sdl") or
(nographics and ("none")))
if vnclisten:
optstr += ",listen=%s" % vnclisten
if vncport:
optstr += ",port=%s" % vncport
if keymap:
optstr += ",keymap=%s" % keymap
logging.debug("--graphics compat generated: %s", optstr)
options.graphics = [optstr]
def convert_old_features(options):
if getattr(options, "features", None):
return
opts = ""
if options.noacpi:
opts += "acpi=off"
if options.noapic:
if opts:
opts += ","
opts += "apic=off"
options.features = opts or None
2013-03-18 01:06:52 +04:00
########################
# Virt type validation #
########################
2013-07-17 15:53:47 +04:00
def get_guest(conn, options):
2013-03-18 01:06:52 +04:00
# Set up all virt/hypervisor parameters
2013-04-12 00:32:00 +04:00
if sum([bool(f) for f in [options.fullvirt,
options.paravirt,
options.container]]) > 1:
2013-03-18 01:06:52 +04:00
fail(_("Can't do more than one of --hvm, --paravirt, or --container"))
req_hv_type = options.hv_type and options.hv_type.lower() or None
if options.fullvirt:
req_virt_type = "hvm"
elif options.paravirt:
req_virt_type = "xen"
elif options.container:
req_virt_type = "exe"
else:
# This should force capabilities to give us the most sensible default
req_virt_type = None
logging.debug("Requesting virt method '%s', hv type '%s'.",
(req_virt_type and req_virt_type or _("default")),
(req_hv_type and req_hv_type or _("default")))
arch = options.arch
if re.match("i.86", arch or ""):
arch = "i686"
try:
2015-04-04 00:24:32 +03:00
guest = conn.caps.lookup_virtinst_guest(
os_type=req_virt_type,
arch=arch,
typ=req_hv_type,
machine=options.machine)
2017-05-05 19:47:21 +03:00
except Exception as e:
2013-03-18 01:06:52 +04:00
fail(e)
if (not req_virt_type and
not req_hv_type and
2013-07-06 04:36:28 +04:00
conn.is_qemu() and
2015-04-04 00:24:32 +03:00
guest.os.arch in ["i686", "x86_64"] and
not guest.type == "kvm"):
2017-05-05 21:21:15 +03:00
logging.warning("KVM acceleration not available, using '%s'",
2015-04-04 00:24:32 +03:00
guest.type)
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
return guest
2013-03-18 01:06:52 +04:00
##################################
# Install media setup/validation #
##################################
2014-09-07 19:57:04 +04:00
def set_install_media(guest, location, cdpath, distro_variant):
try:
cdinstall = bool(not location and (cdpath or cdrom_specified(guest)))
2013-03-18 01:06:52 +04:00
2014-09-07 19:57:04 +04:00
if cdinstall or cdpath:
guest.installer.cdrom = True
if location or cdpath:
guest.installer.location = (location or cdpath)
2013-03-18 01:06:52 +04:00
virtinst: Fix os-variant ordering
Previously os-variant was not being set before performing location
checks. This lead to a sitation where the os-variant data could not be
acted on. This commit re-orders the process to ensure that the correct
ordering happens.
Previous behavior:
```
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (distroinstaller:180) DistroInstaller location is a network source.
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (distroinstaller:181) Sanitized value is https://example.com/repo/rhel/7/rhel-7-server-rpms/
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (urlfetcher:57) Using scratchdir=/home/bharrington/.cache/virt-manager/boot
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (urlfetcher:477) Finding distro store for location=https://example.com/repo/rhel/7/rhel-7-server-rpms/
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (urlfetcher:484) Using os-variant=generic
[Thu, 11 May 2017 12:28:30 virt-install 19296] DEBUG (urlfetcher:486) Supplying urldistro=None
[Thu, 11 May 2017 12:28:34 virt-install 19296] DEBUG (urlfetcher:186) HTTP hasFile request failed: 404 Client Error: Not Found for url: https://example.com/repo/rhel/7/rhel-7-server-rpms/Fedora
[Thu, 11 May 2017 12:28:34 virt-install 19296] DEBUG (urlfetcher:145) hasFile(https://example.com/repo/rhel/7/rhel-7-server-rpms/Fedora) returning False
[Thu, 11 May 2017 12:28:34 virt-install 19296] DEBUG (urlfetcher:1114) No treearch found in uri, defaulting to arch=i386
...
```
Current behavior:
```
[Thu, 11 May 2017 13:20:37 virt-install 22335] DEBUG (distroinstaller:180) DistroInstaller location is a network source.
[Thu, 11 May 2017 13:20:37 virt-install 22335] DEBUG (guest:250) Setting Guest.os_variant to 'rhel7.3'
[Thu, 11 May 2017 13:20:37 virt-install 22335] DEBUG (urlfetcher:57) Using scratchdir=/home/bharrington/.cache/virt-manager/boot
[Thu, 11 May 2017 13:20:37 virt-install 22335] DEBUG (urlfetcher:477) Finding distro store for location=https://example.com/repo/rhel/7/rhel-7-server-rpms/
[Thu, 11 May 2017 13:20:38 virt-install 22335] DEBUG (urlfetcher:499) Prioritizing distro store=<class 'virtinst.urlfetcher.RHELDistro'>
```
2017-05-11 23:23:08 +03:00
if distro_variant not in ["auto", "none"]:
guest.os_variant = distro_variant
2014-09-07 19:57:04 +04:00
guest.installer.check_location(guest)
if distro_variant == "auto":
guest.os_variant = guest.installer.detect_distro(guest)
2017-05-05 19:47:21 +03:00
except ValueError as e:
2015-06-02 15:21:58 +03:00
fail(_("Error validating install location: %s") % str(e))
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2014-09-21 04:32:19 +04:00
def do_test_media_detection(conn, url):
2015-04-04 00:24:32 +03:00
guest = conn.caps.lookup_virtinst_guest()
2014-09-21 04:32:19 +04:00
guest.installer = virtinst.DistroInstaller(conn)
guest.installer.location = url
print_stdout(guest.installer.detect_distro(guest), do_force=True)
2013-03-18 01:06:52 +04:00
#############################
# General option validation #
#############################
def validate_required_options(options, guest):
# Required config. Don't error right away if nothing is specified,
# aggregate the errors to help first time users get it right
msg = ""
if not options.name:
2015-04-12 02:25:46 +03:00
msg += "\n" + _("--name is required")
2013-03-18 01:06:52 +04:00
if not options.memory:
2014-06-16 07:56:02 +04:00
msg += "\n" + _("--memory amount in MiB is required")
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
if (not guest.os.is_container() and
2014-09-21 03:16:13 +04:00
not (options.disk or options.filesystem)):
2014-05-12 02:58:17 +04:00
msg += "\n" + (
2014-09-21 03:16:13 +04:00
_("--disk storage must be specified (override with --disk none)"))
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
if (not guest.os.is_container() and
2015-04-05 00:10:45 +03:00
not options.xmlonly and
2013-03-18 01:06:52 +04:00
(not install_specified(options.location, options.cdrom,
options.pxe, options.import_install)) and
2014-01-21 03:04:23 +04:00
(not cdrom_specified(guest, options.disk))):
2014-05-12 02:58:17 +04:00
msg += "\n" + (
_("An install method must be specified\n(%(methods)s)") %
2017-08-17 14:01:28 +03:00
{"methods": install_methods})
2013-03-18 01:06:52 +04:00
2014-02-05 01:16:39 +04:00
if msg:
2013-03-18 01:06:52 +04:00
fail(msg)
2013-04-13 22:34:52 +04:00
2014-09-07 21:50:22 +04:00
_cdrom_location_man_page = _("See the man page for examples of "
"using --location with CDROM media")
2013-03-18 01:06:52 +04:00
def check_option_collisions(options, guest):
2016-06-01 16:32:56 +03:00
if options.noreboot and options.transient:
fail(_("--noreboot and --transient can not be specified together"))
2013-03-18 01:06:52 +04:00
# Install collisions
2013-04-12 00:32:00 +04:00
if sum([bool(l) for l in [options.pxe, options.location,
options.cdrom, options.import_install]]) > 1:
2013-03-18 01:06:52 +04:00
fail(_("Only one install method can be used (%(methods)s)") %
2017-08-05 09:39:32 +03:00
{"methods": install_methods})
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
if (guest.os.is_container() and
2013-03-18 01:06:52 +04:00
install_specified(options.location, options.cdrom,
options.pxe, options.import_install)):
fail(_("Install methods (%s) cannot be specified for "
"container guests") % install_methods)
2013-07-17 15:53:47 +04:00
if guest.os.is_xenpv():
2013-03-18 01:06:52 +04:00
if options.pxe:
fail(_("Network PXE boot is not supported for paravirtualized "
"guests"))
if options.cdrom or options.livecd:
fail(_("Paravirtualized guests cannot install off cdrom media."))
if (options.location and
2013-07-06 04:36:28 +04:00
guest.conn.is_remote() and not
2013-10-06 18:08:04 +04:00
guest.conn.support_remote_url_install()):
2013-03-18 01:06:52 +04:00
fail(_("Libvirt version does not support remote --location installs"))
2014-02-03 00:17:44 +04:00
cdrom_err = ""
if guest.installer.cdrom:
2014-11-21 00:36:23 +03:00
cdrom_err = " " + _cdrom_location_man_page
2014-01-21 03:04:23 +04:00
if not options.location and options.extra_args:
2014-02-03 00:17:44 +04:00
fail(_("--extra-args only work if specified with --location.") +
cdrom_err)
2014-01-21 03:04:23 +04:00
if not options.location and options.initrd_inject:
2014-02-03 00:17:44 +04:00
fail(_("--initrd-inject only works if specified with --location.") +
cdrom_err)
def _show_nographics_warnings(options, guest):
2018-03-21 00:23:34 +03:00
if guest.devices.graphics:
2014-02-03 00:17:44 +04:00
return
if not options.autoconsole:
return
2014-11-21 21:57:30 +03:00
if guest.installer.cdrom:
2017-05-05 21:21:15 +03:00
logging.warning(_("CDROM media does not print to the text console "
2014-02-03 00:17:44 +04:00
"by default, so you likely will not see text install output. "
2014-11-21 00:36:23 +03:00
"You might want to use --location.") + " " +
_cdrom_location_man_page)
2014-02-03 00:17:44 +04:00
return
if not options.location:
return
# Trying --location --nographics with console connect. Warn if
# they likely won't see any output.
2018-03-21 00:23:34 +03:00
if not guest.devices.console:
2017-05-05 21:21:15 +03:00
logging.warning(_("No --console device added, you likely will not "
2014-02-03 00:17:44 +04:00
"see text install output from the guest."))
return
serial_arg = "console=ttyS0"
2014-08-04 00:22:07 +04:00
serial_arm_arg = "console=ttyAMA0"
2015-09-22 15:42:09 +03:00
hvc_arg = "console=hvc0"
2014-02-03 00:17:44 +04:00
2015-09-22 15:42:09 +03:00
console_type = serial_arg
if guest.os.is_arm():
console_type = serial_arm_arg
2018-03-21 00:23:34 +03:00
if guest.devices.console[0].target_type in ["virtio", "xen"]:
2015-09-22 15:42:09 +03:00
console_type = hvc_arg
2015-11-11 23:23:19 +03:00
if guest.os.is_ppc64() or guest.os.is_arm_machvirt():
# Later arm/ppc kernels figure out console= automatically, so don't
# warn about it.
2015-11-09 17:15:43 +03:00
return
2015-09-22 15:42:09 +03:00
2016-03-18 05:28:17 +03:00
for args in options.extra_args:
2016-03-24 22:59:29 +03:00
if console_type in (args or ""):
2016-03-18 05:28:17 +03:00
return
2014-02-03 00:17:44 +04:00
2017-05-05 21:21:15 +03:00
logging.warning(_("Did not find '%(console_string)s' in --extra-args, "
2015-09-22 15:42:09 +03:00
"which is likely required to see text install output from the "
"guest."), {"console_string": console_type})
2014-02-03 00:17:44 +04:00
def show_warnings(options, guest):
if options.pxe and not supports_pxe(guest):
2017-05-05 21:21:15 +03:00
logging.warning(_("The guest's network configuration does not support "
2014-02-03 00:17:44 +04:00
"PXE"))
2016-04-08 00:36:53 +03:00
if (guest.os_variant == "generic" and
options.distro_variant not in ["none", "generic"]):
2017-05-05 21:21:15 +03:00
logging.warning(_("No operating system detected, VM performance may "
2014-09-07 21:55:45 +04:00
"suffer. Specify an OS with --os-variant for optimal results."))
2014-02-03 00:17:44 +04:00
_show_nographics_warnings(options, guest)
2013-03-18 01:06:52 +04:00
##########################
# Guest building helpers #
##########################
2013-07-17 15:53:47 +04:00
def build_installer(options, conn, virt_type):
2013-03-18 01:06:52 +04:00
# Build the Installer instance
2014-09-07 21:42:56 +04:00
if options.pxe:
2013-03-18 01:06:52 +04:00
instclass = virtinst.PXEInstaller
2014-09-07 21:42:56 +04:00
elif options.cdrom or options.location or options.livecd:
2013-03-18 01:06:52 +04:00
instclass = virtinst.DistroInstaller
2014-02-03 15:03:21 +04:00
elif virt_type == "exe":
instclass = virtinst.ContainerInstaller
2014-01-21 03:04:23 +04:00
elif options.import_install or options.boot:
2013-03-18 01:06:52 +04:00
options.import_install = True
instclass = virtinst.ImportInstaller
2015-04-05 00:10:45 +03:00
elif options.xmlonly:
2014-05-12 03:19:00 +04:00
instclass = virtinst.ImportInstaller
2013-03-18 01:06:52 +04:00
else:
instclass = virtinst.DistroInstaller
2013-07-17 00:47:08 +04:00
installer = instclass(conn)
2014-09-07 21:42:56 +04:00
if options.livecd:
installer.livecd = True
2013-03-18 01:06:52 +04:00
return installer
2013-04-13 22:34:52 +04:00
2016-06-14 14:37:21 +03:00
def build_guest_instance(conn, options):
2013-07-17 15:53:47 +04:00
guest = get_guest(conn, options)
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
logging.debug("Received virt method '%s'", guest.type)
logging.debug("Hypervisor name is '%s'", guest.os.os_type)
2013-03-18 01:06:52 +04:00
2013-07-17 15:53:47 +04:00
guest.installer = build_installer(options, conn, guest.os.os_type)
2013-03-18 01:06:52 +04:00
2014-01-21 03:15:08 +04:00
# non-xml install options
2016-11-02 17:27:14 +03:00
options.extra_args = options.extra_args or []
guest.installer.extraargs = options.extra_args
2014-01-21 03:04:23 +04:00
guest.installer.initrd_injections = options.initrd_inject
2014-01-21 03:15:08 +04:00
guest.autostart = options.autostart
2013-10-06 16:53:05 +04:00
2014-02-05 01:16:39 +04:00
if options.name:
guest.name = options.name
2014-01-21 03:15:08 +04:00
if options.uuid:
guest.uuid = options.uuid
2014-01-25 05:03:30 +04:00
if options.description:
guest.description = options.description
2013-03-18 01:06:52 +04:00
2014-02-05 01:16:39 +04:00
validate_required_options(options, guest)
2016-06-14 14:37:21 +03:00
cli.parse_option_strings(options, guest, None)
2013-03-18 01:06:52 +04:00
2014-02-05 01:16:39 +04:00
# Extra disk validation
2018-03-21 00:23:34 +03:00
for disk in guest.devices.disk:
2014-02-05 01:16:39 +04:00
cli.validate_disk(disk)
2014-09-07 19:57:04 +04:00
set_install_media(guest, options.location, options.cdrom,
options.distro_variant)
2013-03-18 01:06:52 +04:00
2014-09-07 19:57:04 +04:00
guest.add_default_devices()
2013-03-18 01:06:52 +04:00
2015-02-22 01:44:21 +03:00
# Default to UEFI for aarch64
if (guest.os.is_arm64() and
not guest.os.kernel and
not guest.os.loader and
guest.os.loader_ro is None and
guest.os.nvram is None):
try:
guest.set_uefi_default()
2017-05-05 19:47:21 +03:00
except Exception as e:
2015-02-22 01:44:21 +03:00
logging.debug("Error setting UEFI default for aarch64",
exc_info=True)
2017-05-05 21:21:15 +03:00
logging.warning("Couldn't configure UEFI: %s", e)
logging.warning("Your aarch64 VM may not boot successfully.")
2015-02-22 01:44:21 +03:00
2017-01-26 17:08:36 +03:00
# Check usability of SMM feature
if guest.features.smm:
if not guest.os.is_x86():
fail(_("SMM feature is valid only for x86 architecture."))
if guest.os.machine is None:
guest.os.machine = "q35"
elif not guest.os.is_q35():
fail(_("SMM feature is valid only for q35 machine type"))
2013-03-18 01:06:52 +04:00
# Various little validations about option collisions. Need to do
# this after setting guest.installer at least
check_option_collisions(options, guest)
2014-02-03 00:17:44 +04:00
show_warnings(options, guest)
2013-03-18 01:06:52 +04:00
return guest
###########################
# Install process helpers #
###########################
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
def start_install(guest, options):
2017-01-18 15:11:43 +03:00
if options.wait is not None:
2013-03-18 01:06:52 +04:00
wait_on_install = True
wait_time = options.wait * 60
2016-06-17 19:09:45 +03:00
if "VIRTINST_TEST_SUITE" in os.environ and wait_time:
# Convert wait time to 1 second, for the test suite
wait_time = 1
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
else:
wait_on_install = False
wait_time = -1
2013-03-18 01:06:52 +04:00
# If --wait specified, we don't want the default behavior of waiting
# for virt-viewer to exit, since then we can't exit the app when time
# expires
wait_on_console = not wait_on_install
2014-09-21 02:20:41 +04:00
if wait_time == 0:
# --wait 0 implies --noautoconsole
autoconsole = False
else:
autoconsole = options.autoconsole
conscb = None
if autoconsole:
conscb = cli.get_console_cb(guest)
if not conscb:
# If there isn't any console to actually connect up,
# default to --wait -1 to get similarish behavior
autoconsole = False
if options.wait is None:
logging.warning(_("No console to launch for the guest, "
"defaulting to --wait -1"))
wait_on_install = True
wait_time = -1
2013-03-18 01:06:52 +04:00
2015-04-12 02:25:46 +03:00
meter = cli.get_meter()
2013-03-18 01:06:52 +04:00
logging.debug("Guest.has_install_phase: %s",
guest.installer.has_install_phase())
# we've got everything -- try to start the install
print_stdout(_("\nStarting install..."))
try:
start_time = time.time()
# Do first install phase
2016-06-01 16:32:56 +03:00
guest.start_install(meter=meter, doboot=not options.noreboot,
transient=options.transient)
2014-02-06 04:09:26 +04:00
cli.connect_console(guest, conscb, wait_on_console)
2016-06-01 16:32:56 +03:00
check_domain(guest, conscb, options.transient,
2016-06-17 18:43:41 +03:00
wait_on_install, wait_time, start_time)
2013-03-18 01:06:52 +04:00
2015-03-26 23:43:28 +03:00
print_stdout(_("Domain creation completed."))
2016-06-01 16:32:56 +03:00
if not options.transient and not guest.domain.isActive():
2015-03-26 23:43:28 +03:00
if options.noreboot or not guest.installer.has_install_phase():
print_stdout(
_("You can restart your domain by running:\n %s") %
cli.virsh_start_cmd(guest))
else:
print_stdout(_("Restarting guest."))
2016-06-17 18:43:41 +03:00
guest.domain.create()
2015-03-26 23:43:28 +03:00
cli.connect_console(guest, conscb, True)
2013-03-18 01:06:52 +04:00
except KeyboardInterrupt:
logging.debug("", exc_info=True)
print_stderr(_("Domain install interrupted."))
raise
2017-05-05 19:47:21 +03:00
except Exception as e:
2013-03-18 01:06:52 +04:00
fail(e, do_exit=False)
2016-06-17 18:43:41 +03:00
if guest.domain is None:
2015-09-06 20:42:07 +03:00
guest.cleanup_created_disks(meter)
2013-03-18 01:06:52 +04:00
cli.install_fail(guest)
2013-04-13 22:34:52 +04:00
2016-06-01 16:32:56 +03:00
def check_domain(guest, conscb, transient,
wait_for_install, wait_time, start_time):
2013-03-18 01:06:52 +04:00
"""
Make sure domain ends up in expected state, and wait if for install
to complete if requested
"""
2016-06-17 19:12:17 +03:00
def check_domain_inactive():
2016-06-01 16:32:56 +03:00
try:
dominfo = guest.domain.info()
state = dominfo[0]
logging.debug("Domain state after install: %s", state)
2013-03-18 01:06:52 +04:00
2016-06-01 16:32:56 +03:00
if state == libvirt.VIR_DOMAIN_CRASHED:
fail(_("Domain has crashed."))
2013-03-18 01:06:52 +04:00
2016-06-01 16:32:56 +03:00
return not guest.domain.isActive()
2017-05-05 19:47:21 +03:00
except libvirt.libvirtError as e:
2016-06-01 16:32:56 +03:00
if transient and e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
logging.debug("transient VM shutdown and disappeared.")
return True
raise
2013-03-18 01:06:52 +04:00
2016-06-17 19:12:17 +03:00
if check_domain_inactive():
2016-06-17 18:43:41 +03:00
return
2013-03-18 01:06:52 +04:00
2016-06-17 19:12:17 +03:00
if bool(conscb):
# We are trying to detect if the VM shutdown, or the user
# just closed the console and the VM is still running. In the
# the former case, libvirt may not have caught up yet with the
# VM having exited, so wait a bit and check again
time.sleep(2)
if check_domain_inactive():
return
2013-03-18 01:06:52 +04:00
2016-06-17 19:12:17 +03:00
# If we reach here, the VM still appears to be running.
2013-03-18 01:06:52 +04:00
if not wait_for_install or wait_time == 0:
# User either:
# used --noautoconsole
# used --wait 0
# killed console and guest is still running
if not guest.installer.has_install_phase():
2016-06-17 18:43:41 +03:00
return
2013-03-18 01:06:52 +04:00
print_stdout(
_("Domain installation still in progress. You can reconnect"
" to \nthe console to complete the installation process."))
sys.exit(0)
2016-06-17 18:43:41 +03:00
wait_forever = (wait_time < 0)
2013-03-18 01:06:52 +04:00
timestr = (not wait_forever and
2014-09-21 02:20:41 +04:00
_(" %d minutes") % (int(wait_time) / 60) or "")
2013-03-18 01:06:52 +04:00
print_stdout(
2014-09-21 02:20:41 +04:00
_("Domain installation still in progress. Waiting"
2013-09-20 20:10:34 +04:00
"%(time_string)s for installation to complete.") %
{"time_string": timestr})
2013-03-18 01:06:52 +04:00
# Wait loop
while True:
2016-06-17 19:12:17 +03:00
if not guest.domain.isActive():
print_stdout(_("Domain has shutdown. Continuing."))
break
2018-02-23 04:21:42 +03:00
time.sleep(1)
2013-03-18 01:06:52 +04:00
time_elapsed = (time.time() - start_time)
if not wait_forever and time_elapsed >= wait_time:
print_stdout(
_("Installation has exceeded specified time limit. "
2016-06-17 19:12:17 +03:00
"Exiting application."))
2013-03-18 01:06:52 +04:00
sys.exit(1)
########################
# XML printing helpers #
########################
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
def xml_to_print(guest, xmlonly, dry):
2013-03-18 01:06:52 +04:00
start_xml, final_xml = guest.start_install(dry=dry, return_xml=True)
if not start_xml:
start_xml = final_xml
final_xml = None
2015-04-05 00:10:45 +03:00
if dry and not xmlonly:
2013-03-18 01:06:52 +04:00
print_stdout(_("Dry run completed successfully"))
return
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
if xmlonly not in [False, "1", "2", "all"]:
fail(_("Unknown XML step request '%s', must be 1, 2, or all") %
xmlonly)
2015-04-05 00:10:45 +03:00
if xmlonly == "1":
2013-03-18 01:06:52 +04:00
return start_xml
2015-04-05 00:10:45 +03:00
if xmlonly == "2":
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
if not final_xml:
2013-03-18 01:06:52 +04:00
fail(_("Requested installation does not have XML step 2"))
return final_xml
# "all" case
xml = start_xml
if final_xml:
xml += final_xml
return xml
#######################
# CLI option handling #
#######################
def parse_args():
2013-06-30 23:03:53 +04:00
parser = cli.setupParser(
2016-04-07 22:52:07 +03:00
"%(prog)s --name NAME --memory MB STORAGE INSTALL [options]",
2014-01-22 18:06:35 +04:00
_("Create a new virtual machine from specified install media."),
introspection_epilog=True)
2013-03-18 01:06:52 +04:00
cli.add_connect_option(parser)
2014-01-19 02:01:43 +04:00
geng = parser.add_argument_group(_("General Options"))
2014-01-21 03:04:23 +04:00
geng.add_argument("-n", "--name",
2013-03-18 01:06:52 +04:00
help=_("Name of the guest instance"))
2014-01-25 03:56:59 +04:00
cli.add_memory_option(geng, backcompat=True)
2013-03-18 01:06:52 +04:00
cli.vcpu_cli_options(geng)
2014-01-25 05:03:30 +04:00
cli.add_metadata_option(geng)
geng.add_argument("-u", "--uuid", help=argparse.SUPPRESS)
geng.add_argument("--description", help=argparse.SUPPRESS)
2013-03-18 01:06:52 +04:00
2014-01-19 02:01:43 +04:00
insg = parser.add_argument_group(_("Installation Method Options"))
insg.add_argument("-c", dest="cdrom_short", help=argparse.SUPPRESS)
2014-01-21 03:04:23 +04:00
insg.add_argument("--cdrom", help=_("CD-ROM installation media"))
insg.add_argument("-l", "--location",
2013-03-18 01:06:52 +04:00
help=_("Installation source (eg, nfs:host:/path, "
2018-04-30 15:56:53 +03:00
"https://host/path, ftp://host/path)"))
2014-01-21 03:04:23 +04:00
insg.add_argument("--pxe", action="store_true",
2013-03-18 01:06:52 +04:00
help=_("Boot from the network using the PXE protocol"))
2014-01-19 02:01:43 +04:00
insg.add_argument("--import", action="store_true", dest="import_install",
2013-03-18 01:06:52 +04:00
help=_("Build guest around an existing disk image"))
2014-01-21 03:04:23 +04:00
insg.add_argument("--livecd", action="store_true",
2013-03-18 01:06:52 +04:00
help=_("Treat the CD-ROM media as a Live CD"))
2016-03-18 05:28:17 +03:00
insg.add_argument("-x", "--extra-args", action="append",
2013-03-18 01:06:52 +04:00
help=_("Additional arguments to pass to the install kernel "
"booted from --location"))
2014-01-21 03:04:23 +04:00
insg.add_argument("--initrd-inject", action="append",
2013-03-18 01:06:52 +04:00
help=_("Add given file to root of initrd from --location"))
2014-09-07 19:57:04 +04:00
2014-09-21 04:32:19 +04:00
# Takes a URL and just prints to stdout the detected distro name
insg.add_argument("--test-media-detection", help=argparse.SUPPRESS)
2014-09-07 19:57:04 +04:00
insg.add_argument("--os-type", dest="distro_type", help=argparse.SUPPRESS)
insg.add_argument("--os-variant", dest="distro_variant",
help=_("The OS variant being installed guests, "
"e.g. 'fedora18', 'rhel6', 'winxp', etc."))
2014-02-11 03:13:42 +04:00
cli.add_boot_options(insg)
2014-01-22 00:36:34 +04:00
insg.add_argument("--init", help=argparse.SUPPRESS)
2013-03-18 01:06:52 +04:00
2014-09-21 03:30:16 +04:00
devg = parser.add_argument_group(_("Device Options"))
cli.add_disk_option(devg)
cli.add_net_option(devg)
cli.add_gfx_option(devg)
cli.add_device_options(devg, sound_back_compat=True)
# Deprecated device options
devg.add_argument("-f", "--file", dest="file_paths", action="append",
2014-01-19 02:01:43 +04:00
help=argparse.SUPPRESS)
2014-09-21 03:30:16 +04:00
devg.add_argument("-s", "--file-size", type=float,
2013-03-18 01:06:52 +04:00
action="append", dest="disksize",
2014-01-19 02:01:43 +04:00
help=argparse.SUPPRESS)
2014-09-21 03:30:16 +04:00
devg.add_argument("--nonsparse", action="store_false",
2013-03-18 01:06:52 +04:00
default=True, dest="sparse",
2014-01-19 02:01:43 +04:00
help=argparse.SUPPRESS)
2014-09-21 03:30:16 +04:00
devg.add_argument("--nodisks", action="store_true", help=argparse.SUPPRESS)
devg.add_argument("--nonetworks", action="store_true",
2014-09-21 02:56:39 +04:00
help=argparse.SUPPRESS)
2014-09-21 03:30:16 +04:00
devg.add_argument("-b", "--bridge", action="append",
2014-09-20 04:31:22 +04:00
help=argparse.SUPPRESS)
2014-09-21 03:30:16 +04:00
devg.add_argument("-m", "--mac", action="append", help=argparse.SUPPRESS)
devg.add_argument("--vnc", action="store_true", help=argparse.SUPPRESS)
devg.add_argument("--vncport", type=int, help=argparse.SUPPRESS)
devg.add_argument("--vnclisten", help=argparse.SUPPRESS)
devg.add_argument("-k", "--keymap", help=argparse.SUPPRESS)
devg.add_argument("--sdl", action="store_true", help=argparse.SUPPRESS)
devg.add_argument("--nographics", action="store_true",
2014-09-20 04:31:22 +04:00
help=argparse.SUPPRESS)
2013-03-18 01:06:52 +04:00
2014-09-21 03:30:16 +04:00
gxmlg = parser.add_argument_group(_("Guest Configuration Options"))
cli.add_guest_xml_options(gxmlg)
2013-03-18 01:06:52 +04:00
2014-01-19 02:01:43 +04:00
virg = parser.add_argument_group(_("Virtualization Platform Options"))
virg.add_argument("-v", "--hvm", action="store_true", dest="fullvirt",
2013-03-18 01:06:52 +04:00
help=_("This guest should be a fully virtualized guest"))
2014-01-21 03:04:23 +04:00
virg.add_argument("-p", "--paravirt", action="store_true",
2013-03-18 01:06:52 +04:00
help=_("This guest should be a paravirtualized guest"))
2014-01-19 02:01:43 +04:00
virg.add_argument("--container", action="store_true", default=False,
2013-03-18 01:06:52 +04:00
help=_("This guest should be a container guest"))
2014-01-19 02:01:43 +04:00
virg.add_argument("--virt-type", dest="hv_type",
2013-03-18 01:06:52 +04:00
default="",
help=_("Hypervisor name to use (kvm, qemu, xen, ...)"))
2014-01-19 02:01:43 +04:00
virg.add_argument("--accelerate", action="store_true", default=False,
2014-01-21 03:04:23 +04:00
help=argparse.SUPPRESS)
virg.add_argument("--arch",
2013-03-18 01:06:52 +04:00
help=_("The CPU architecture to simulate"))
2014-01-21 03:04:23 +04:00
virg.add_argument("--machine",
2013-03-18 01:06:52 +04:00
help=_("The machine type to emulate"))
2014-09-20 04:31:22 +04:00
virg.add_argument("--noapic", action="store_true",
default=False, help=argparse.SUPPRESS)
virg.add_argument("--noacpi", action="store_true",
default=False, help=argparse.SUPPRESS)
2013-03-18 01:06:52 +04:00
2014-01-19 02:01:43 +04:00
misc = parser.add_argument_group(_("Miscellaneous Options"))
misc.add_argument("--autostart", action="store_true", dest="autostart",
2013-03-18 01:06:52 +04:00
default=False,
help=_("Have domain autostart on host boot up."))
2016-06-01 16:32:56 +03:00
misc.add_argument("--transient", action="store_true", dest="transient",
default=False,
help=_("Create a transient domain."))
2014-01-19 02:01:43 +04:00
misc.add_argument("--wait", type=int, dest="wait",
2013-09-28 19:27:26 +04:00
help=_("Minutes to wait for install to complete."))
cli.add_misc_options(misc, prompt=True, printxml=True, printstep=True,
2014-02-06 04:09:26 +04:00
noreboot=True, dryrun=True, noautoconsole=True)
2013-03-18 01:06:52 +04:00
2014-01-19 02:01:43 +04:00
return parser.parse_args()
2013-03-18 01:06:52 +04:00
###################
# main() handling #
###################
def main(conn=None):
cli.earlyLogging()
2014-01-19 02:01:43 +04:00
options = parse_args()
2013-03-18 01:06:52 +04:00
# Default setup options
2018-06-05 21:54:34 +03:00
convert_old_printxml(options)
2015-04-05 00:10:45 +03:00
options.quiet = (options.xmlonly or
2014-09-21 04:32:19 +04:00
options.test_media_detection or options.quiet)
2013-03-18 01:06:52 +04:00
cli.setupLogging("virt-install", options.debug, options.quiet)
2018-06-05 21:54:34 +03:00
if cli.check_option_introspection(options):
return 0
2013-03-18 01:06:52 +04:00
2018-06-05 21:54:34 +03:00
check_cdrom_option_error(options)
2015-04-12 02:25:46 +03:00
cli.convert_old_force(options)
cli.parse_check(options.check)
2013-03-18 01:06:52 +04:00
cli.set_prompt(options.prompt)
2018-06-05 21:54:34 +03:00
convert_old_memory(options)
convert_old_sound(options)
convert_old_networks(options)
convert_old_graphics(options)
convert_old_disks(options)
convert_old_features(options)
convert_old_cpuset(options)
convert_old_init(options)
convert_old_os_options(options)
2014-01-22 18:06:35 +04:00
2013-03-18 01:06:52 +04:00
if conn is None:
conn = cli.getConnection(options.connect)
2014-09-21 04:32:19 +04:00
if options.test_media_detection:
do_test_media_detection(conn, options.test_media_detection)
return 0
2016-06-14 14:37:21 +03:00
guest = build_guest_instance(conn, options)
2015-04-05 00:10:45 +03:00
if options.xmlonly or options.dry:
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
xml = xml_to_print(guest, options.xmlonly, options.dry)
2013-03-18 01:06:52 +04:00
if xml:
print_stdout(xml, do_force=True)
else:
virtinst: guest: drop 'continue_install' concept
continue_install is intended to facilitate windows XP style 3 stage
installs:
stage 1: initial dos style disk setup, reboot
stage 2: actual full installer, reboot
stage 3: OS is functional, virt-install is done
The code assumed that we needed to keep the cdrom as the primary
boot device for the second stage, so virt-install/virt-manager needed
to hang around through the second stage run, wait until the VM shutdown,
then encode the final XML to boot of the disk.
Windows is and always has been smart enough to handle that case though...
after the initial boot, if we set the hd as the primary boot device
for stage 2, the disk bits that windows already installed will make
use of the cdrom as necessary. So the entire premise of continue_install
is irrelevant. Maybe back when it was added, when xen didn't even have
working ACPI support, this served a purpose, but I'm pretty sure we
can safely drop it nowadays.
2016-06-16 23:13:54 +03:00
start_install(guest, options)
2013-03-18 01:06:52 +04:00
return 0
if __name__ == "__main__":
try:
sys.exit(main())
2017-05-05 19:47:21 +03:00
except SystemExit as sys_e:
2013-03-18 01:06:52 +04:00
sys.exit(sys_e.code)
except KeyboardInterrupt:
logging.debug("", exc_info=True)
print_stderr(_("Installation aborted at user request"))
2017-05-05 19:47:21 +03:00
except Exception as main_e:
2013-03-18 01:06:52 +04:00
fail(main_e)