2018-01-28 04:46:39 +08:00
|
|
|
#!/usr/bin/env python3
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2014-02-12 17:21:38 +08:00
|
|
|
# Copyright 2005-2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
import argparse
|
2018-10-12 02:11:37 +08:00
|
|
|
import atexit
|
2013-03-18 05:06:52 +08:00
|
|
|
import sys
|
|
|
|
import time
|
2019-08-14 17:16:00 +08:00
|
|
|
import select
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-08-10 03:00:16 +08:00
|
|
|
import libvirt
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
import virtinst
|
2014-09-20 08:31:22 +08:00
|
|
|
from virtinst import cli
|
2019-06-17 09:12:39 +08:00
|
|
|
from virtinst import log
|
2013-03-18 05:06:52 +08:00
|
|
|
from virtinst.cli import fail, print_stdout, print_stderr
|
|
|
|
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Validation utility helpers #
|
|
|
|
##############################
|
|
|
|
|
2019-06-14 02:13:29 +08:00
|
|
|
INSTALL_METHODS = "--location URL, --cdrom CD/ISO, --pxe, --import, --boot hd|cdrom|..."
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def supports_pxe(guest):
|
|
|
|
"""
|
|
|
|
Return False if we are pretty sure the config doesn't support PXE
|
|
|
|
"""
|
2018-03-21 05:23:34 +08:00
|
|
|
for nic in guest.devices.interface:
|
2013-03-18 05:06:52 +08:00
|
|
|
if nic.type == nic.TYPE_USER:
|
|
|
|
continue
|
|
|
|
if nic.type != nic.TYPE_VIRTUAL:
|
|
|
|
return True
|
|
|
|
|
|
|
|
try:
|
2013-09-24 22:00:01 +08:00
|
|
|
netobj = nic.conn.networkLookupByName(nic.source)
|
2013-09-23 05:04:22 +08:00
|
|
|
xmlobj = virtinst.Network(nic.conn, parsexml=netobj.XMLDesc(0))
|
2019-06-14 02:47:08 +08:00
|
|
|
return xmlobj.can_pxe()
|
|
|
|
except Exception: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error checking if PXE supported", exc_info=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2013-04-22 00:28:14 +08: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:
|
2019-06-14 02:47:08 +08:00
|
|
|
fail("-c specified with what looks like a libvirt URI. "
|
|
|
|
"Did you mean to use --connect? If not, use --cdrom instead")
|
2013-04-22 00:28:14 +08:00
|
|
|
options.cdrom = options.cdrom_short
|
|
|
|
|
2013-04-05 00:04:07 +08:00
|
|
|
|
2015-04-05 05:10:45 +08:00
|
|
|
#################################
|
|
|
|
# Back compat option conversion #
|
|
|
|
#################################
|
|
|
|
|
|
|
|
def convert_old_printxml(options):
|
|
|
|
if options.xmlstep:
|
|
|
|
options.xmlonly = options.xmlstep
|
|
|
|
del(options.xmlstep)
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-28 08:16:35 +08:00
|
|
|
def convert_old_sound(options):
|
2014-02-06 01:32:53 +08:00
|
|
|
if not options.sound:
|
2013-09-28 08:16:35 +08:00
|
|
|
return
|
2014-02-06 01:32:53 +08:00
|
|
|
for idx in range(len(options.sound)):
|
|
|
|
if options.sound[idx] is None:
|
|
|
|
options.sound[idx] = "default"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2014-01-22 04:36:34 +08:00
|
|
|
def convert_old_init(options):
|
|
|
|
if not options.init:
|
|
|
|
return
|
|
|
|
if not options.boot:
|
2018-10-02 01:14:43 +08:00
|
|
|
options.boot = [""]
|
|
|
|
options.boot[-1] += ",init=%s" % options.init
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Converted old --init to --boot %s", options.boot[-1])
|
2014-01-22 04:36:34 +08:00
|
|
|
|
|
|
|
|
2014-09-21 07:16:13 +08:00
|
|
|
def _do_convert_old_disks(options):
|
2019-06-08 06:21:24 +08:00
|
|
|
paths = virtinst.xmlutil.listify(options.file_paths)
|
|
|
|
sizes = virtinst.xmlutil.listify(options.disksize)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def padlist(l, padsize):
|
2019-06-08 06:21:24 +08:00
|
|
|
l = virtinst.xmlutil.listify(l)
|
2013-03-18 05:06:52 +08:00
|
|
|
l.extend((padsize - len(l)) * [None])
|
|
|
|
return l
|
|
|
|
|
2013-09-28 08:16:35 +08:00
|
|
|
disklist = padlist(paths, max(0, len(sizes)))
|
|
|
|
sizelist = padlist(sizes, len(disklist))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-28 08:16:35 +08:00
|
|
|
opts = []
|
2016-04-19 04:42:12 +08:00
|
|
|
for idx, path in enumerate(disklist):
|
2013-09-28 08:16:35 +08:00
|
|
|
optstr = ""
|
2016-04-19 04:42:12 +08:00
|
|
|
if path:
|
|
|
|
optstr += "path=%s" % path
|
2013-09-28 08:16:35 +08:00
|
|
|
if sizelist[idx]:
|
|
|
|
if optstr:
|
|
|
|
optstr += ","
|
|
|
|
optstr += "size=%s" % sizelist[idx]
|
|
|
|
if options.sparse is False:
|
|
|
|
if optstr:
|
|
|
|
optstr += ","
|
|
|
|
optstr += "sparse=no"
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Converted to new style: --disk %s", optstr)
|
2013-09-28 08:16:35 +08:00
|
|
|
opts.append(optstr)
|
|
|
|
|
2014-01-21 07:04:23 +08:00
|
|
|
options.disk = opts
|
2014-09-21 07:16:13 +08: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)
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Distilled --disk options: %s", options.disk)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
def convert_old_os_options(options):
|
2019-06-14 08:26:26 +08:00
|
|
|
if not options.os_variant and options.old_os_type:
|
|
|
|
options.os_variant = options.old_os_type
|
2019-02-08 04:48:40 +08:00
|
|
|
del(options.old_os_type)
|
2014-09-07 23:57:04 +08:00
|
|
|
|
|
|
|
|
2014-09-20 08:31:22 +08: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
|
2019-06-14 02:47:08 +08:00
|
|
|
|
|
|
|
newvcpus = options.vcpus or []
|
|
|
|
newvcpus.append(",cpuset=%s" % options.cpuset)
|
|
|
|
options.vcpus = newvcpus
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Generated compat cpuset: --vcpus %s", options.vcpus[-1])
|
2014-09-20 08:31:22 +08:00
|
|
|
|
|
|
|
|
2014-09-21 06:56:39 +08:00
|
|
|
def convert_old_networks(options):
|
|
|
|
if options.nonetworks:
|
|
|
|
options.network = ["none"]
|
|
|
|
|
2019-06-08 06:21:24 +08:00
|
|
|
macs = virtinst.xmlutil.listify(options.mac)
|
|
|
|
networks = virtinst.xmlutil.listify(options.network)
|
|
|
|
bridges = virtinst.xmlutil.listify(options.bridge)
|
2014-09-20 08:31:22 +08: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):
|
2019-06-08 06:21:24 +08:00
|
|
|
l = virtinst.xmlutil.listify(l)
|
2014-09-20 08:31:22 +08:00
|
|
|
l.extend((padsize - len(l)) * [None])
|
|
|
|
return l
|
|
|
|
|
|
|
|
# If a plain mac is specified, have it imply a default network
|
2014-09-21 06:56:39 +08:00
|
|
|
networks = padlist(networks, max(len(macs), 1))
|
2014-09-20 08:31:22 +08:00
|
|
|
macs = padlist(macs, len(networks))
|
|
|
|
|
2016-04-19 04:42:12 +08:00
|
|
|
for idx, ignore in enumerate(networks):
|
2014-09-20 08:31:22 +08: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 06:56:39 +08:00
|
|
|
del(options.mac)
|
|
|
|
del(options.bridge)
|
|
|
|
del(options.nonetworks)
|
|
|
|
|
2014-09-20 08:31:22 +08:00
|
|
|
options.network = networks
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Distilled --network options: %s", options.network)
|
2014-09-20 08:31:22 +08:00
|
|
|
|
|
|
|
|
2018-06-06 02:43:19 +08:00
|
|
|
def convert_old_graphics(options):
|
2014-09-20 08:31:22 +08: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
|
|
|
|
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("--graphics compat generated: %s", optstr)
|
2014-09-20 08:31:22 +08:00
|
|
|
options.graphics = [optstr]
|
|
|
|
|
|
|
|
|
|
|
|
def convert_old_features(options):
|
2018-10-02 01:14:43 +08:00
|
|
|
if options.features:
|
2014-09-20 08:31:22 +08:00
|
|
|
return
|
|
|
|
|
2019-06-14 02:47:08 +08:00
|
|
|
opts = []
|
2014-09-20 08:31:22 +08:00
|
|
|
if options.noacpi:
|
2019-06-14 02:47:08 +08:00
|
|
|
opts.append("acpi=off")
|
2014-09-20 08:31:22 +08:00
|
|
|
if options.noapic:
|
2019-06-14 02:47:08 +08:00
|
|
|
opts.append("apic=off")
|
2018-10-02 01:14:43 +08:00
|
|
|
if opts:
|
2019-06-14 02:47:08 +08:00
|
|
|
options.features = [",".join(opts)]
|
2014-09-20 08:31:22 +08:00
|
|
|
|
|
|
|
|
2019-07-03 03:39:51 +08:00
|
|
|
def convert_wait_zero(options):
|
|
|
|
# Historical back compat, --wait 0 is identical to --noautoconsole
|
|
|
|
if options.wait == 0:
|
|
|
|
log.warning("Treating --wait 0 as --noautoconsole")
|
2019-11-25 07:10:56 +08:00
|
|
|
options.autoconsole = "none"
|
2019-07-03 03:39:51 +08:00
|
|
|
options.wait = None
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
##################################
|
|
|
|
# Install media setup/validation #
|
|
|
|
##################################
|
|
|
|
|
2018-09-07 08:28:05 +08:00
|
|
|
def do_test_media_detection(conn, options):
|
|
|
|
url = options.test_media_detection
|
|
|
|
guest = virtinst.Guest(conn)
|
|
|
|
if options.arch:
|
|
|
|
guest.os.arch = options.arch
|
|
|
|
if options.os_type:
|
|
|
|
guest.os.os_type = options.os_type
|
|
|
|
guest.set_capabilities_defaults()
|
|
|
|
|
2018-10-13 06:35:09 +08:00
|
|
|
installer = virtinst.Installer(conn, location=url)
|
2018-09-04 03:21:11 +08:00
|
|
|
print_stdout(installer.detect_distro(guest), do_force=True)
|
2014-09-21 08:32:19 +08:00
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
#############################
|
|
|
|
# General option validation #
|
|
|
|
#############################
|
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
def storage_specified(options, guest):
|
|
|
|
if guest.os.is_container():
|
|
|
|
return True
|
|
|
|
return options.disk or options.filesystem
|
|
|
|
|
|
|
|
|
|
|
|
def memory_specified(guest):
|
|
|
|
return guest.memory or guest.currentMemory or guest.cpu.cells
|
|
|
|
|
|
|
|
|
2018-09-04 03:21:11 +08:00
|
|
|
def validate_required_options(options, guest, installer):
|
2013-03-18 05:06:52 +08:00
|
|
|
# Required config. Don't error right away if nothing is specified,
|
|
|
|
# aggregate the errors to help first time users get it right
|
|
|
|
msg = ""
|
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
if not memory_specified(guest):
|
2014-06-16 11:56:02 +08:00
|
|
|
msg += "\n" + _("--memory amount in MiB is required")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
if not storage_specified(options, guest):
|
2014-05-12 06:58:17 +08:00
|
|
|
msg += "\n" + (
|
2014-09-21 07:16:13 +08:00
|
|
|
_("--disk storage must be specified (override with --disk none)"))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2019-06-14 04:15:21 +08:00
|
|
|
if not guest.os.is_container() and not installer.options_specified():
|
2014-05-12 06:58:17 +08:00
|
|
|
msg += "\n" + (
|
|
|
|
_("An install method must be specified\n(%(methods)s)") %
|
2019-06-14 02:13:29 +08:00
|
|
|
{"methods": INSTALL_METHODS})
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-05 05:16:39 +08:00
|
|
|
if msg:
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(msg)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2019-11-25 07:10:56 +08:00
|
|
|
def show_console_warnings(installer, autoconsole):
|
|
|
|
if not installer.cdrom:
|
2014-02-03 04:17:44 +08:00
|
|
|
return
|
2019-11-25 07:10:56 +08:00
|
|
|
if not autoconsole.is_text():
|
2014-02-03 04:17:44 +08:00
|
|
|
return
|
2019-11-25 07:10:56 +08:00
|
|
|
log.warning(_("CDROM media does not print to the text console "
|
|
|
|
"by default, so you likely will not see text install output. "
|
|
|
|
"You might want to use --location.") + " " +
|
|
|
|
_("See the man page for examples of "
|
|
|
|
"using --location with CDROM media"))
|
2014-02-03 04:17:44 +08:00
|
|
|
|
|
|
|
|
2019-06-14 23:24:10 +08:00
|
|
|
def _show_memory_warnings(guest):
|
|
|
|
if not guest.currentMemory:
|
|
|
|
return
|
|
|
|
|
|
|
|
res = guest.osinfo.get_recommended_resources()
|
|
|
|
rammb = guest.currentMemory // 1024
|
|
|
|
minram = (res.get_minimum_ram(guest.os.arch) or 0)
|
|
|
|
if minram:
|
|
|
|
if (minram // 1024) > guest.currentMemory:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.warning(_("Requested memory %s MiB is less than the "
|
2019-06-14 23:24:10 +08:00
|
|
|
"recommended %s MiB for OS %s"), rammb,
|
|
|
|
minram // (1024 * 1024), guest.osinfo.name)
|
|
|
|
elif rammb < 17:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.warning(_("Requested memory %s MiB is abnormally low. "
|
2019-06-14 23:24:10 +08:00
|
|
|
"Were you trying to specify GiB?"), rammb)
|
|
|
|
|
|
|
|
|
2019-11-25 06:30:49 +08:00
|
|
|
def show_guest_warnings(options, guest, osdata):
|
2014-02-03 04:17:44 +08:00
|
|
|
if options.pxe and not supports_pxe(guest):
|
2020-01-27 03:03:51 +08:00
|
|
|
log.warning(
|
|
|
|
_("The guest's network configuration may not support PXE"))
|
2014-02-03 04:17:44 +08:00
|
|
|
|
2018-10-14 00:55:34 +08:00
|
|
|
# Limit it to hvm x86 guests which presently our defaults
|
|
|
|
# only really matter for
|
2018-09-13 05:23:01 +08:00
|
|
|
if (guest.osinfo.name == "generic" and
|
2019-06-14 06:40:26 +08:00
|
|
|
not osdata.is_none and
|
|
|
|
not osdata.name == "generic" and
|
2018-10-14 00:55:34 +08:00
|
|
|
guest.os.is_x86() and guest.os.is_hvm()):
|
2019-06-17 09:12:39 +08:00
|
|
|
log.warning(_("No operating system detected, VM performance may "
|
2014-09-08 01:55:45 +08:00
|
|
|
"suffer. Specify an OS with --os-variant for optimal results."))
|
|
|
|
|
2019-06-14 23:24:10 +08:00
|
|
|
_show_memory_warnings(guest)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Guest building helpers #
|
|
|
|
##########################
|
|
|
|
|
2019-09-12 00:19:09 +08:00
|
|
|
def get_location_for_os(guest, osname, profile=None):
|
2019-06-14 08:26:26 +08:00
|
|
|
osinfo = virtinst.OSDB.lookup_os(osname, raise_error=True)
|
2019-09-12 00:19:09 +08:00
|
|
|
location = osinfo.get_location(guest.os.arch, profile)
|
2019-06-14 08:26:26 +08:00
|
|
|
print_stdout(_("Using {osname} --location {url}").format(
|
|
|
|
osname=osname, url=location))
|
|
|
|
return location
|
|
|
|
|
|
|
|
|
2019-06-14 08:56:16 +08:00
|
|
|
def build_installer(options, guest, installdata):
|
2018-10-13 06:35:09 +08:00
|
|
|
cdrom = None
|
2018-09-03 22:07:47 +08:00
|
|
|
location = None
|
2019-02-01 07:07:09 +08:00
|
|
|
location_kernel = None
|
|
|
|
location_initrd = None
|
2019-09-12 00:19:09 +08:00
|
|
|
unattended_data = None
|
2019-06-13 04:56:37 +08:00
|
|
|
extra_args = options.extra_args
|
2019-06-14 08:56:16 +08:00
|
|
|
|
|
|
|
install_bootdev = installdata.bootdev
|
|
|
|
install_kernel = installdata.kernel
|
|
|
|
install_initrd = installdata.initrd
|
|
|
|
install_kernel_args = installdata.kernel_args
|
|
|
|
install_os = installdata.os
|
2019-06-17 11:12:24 +08:00
|
|
|
no_install = installdata.no_install
|
2019-06-14 08:56:16 +08:00
|
|
|
if installdata.kernel_args:
|
|
|
|
if installdata.kernel_args_overwrite:
|
|
|
|
install_kernel_args = installdata.kernel_args
|
|
|
|
else:
|
|
|
|
extra_args = [installdata.kernel_args]
|
2019-06-13 04:56:37 +08:00
|
|
|
|
2019-09-12 00:19:09 +08:00
|
|
|
if options.unattended:
|
|
|
|
unattended_data = cli.parse_unattended(options.unattended)
|
|
|
|
|
2019-06-14 08:26:26 +08:00
|
|
|
if install_os:
|
2019-09-12 00:19:09 +08:00
|
|
|
profile = unattended_data.profile if unattended_data else None
|
|
|
|
location = get_location_for_os(guest, install_os, profile)
|
2019-06-14 08:26:26 +08:00
|
|
|
elif options.location:
|
2019-02-01 07:07:09 +08:00
|
|
|
(location,
|
|
|
|
location_kernel,
|
|
|
|
location_initrd) = cli.parse_location(options.location)
|
2018-10-13 06:35:09 +08:00
|
|
|
elif options.cdrom:
|
|
|
|
cdrom = options.cdrom
|
2019-06-14 04:15:21 +08:00
|
|
|
if options.livecd:
|
|
|
|
no_install = True
|
2018-09-03 22:07:47 +08:00
|
|
|
elif options.pxe:
|
2018-10-13 03:15:20 +08:00
|
|
|
install_bootdev = "network"
|
2019-06-14 08:56:16 +08:00
|
|
|
elif installdata.is_set:
|
2018-10-13 06:35:09 +08:00
|
|
|
pass
|
2019-06-14 04:15:21 +08:00
|
|
|
elif (options.import_install or
|
|
|
|
options.xmlonly or
|
|
|
|
options.boot):
|
|
|
|
no_install = True
|
2018-09-03 22:07:47 +08:00
|
|
|
|
2018-10-13 06:35:09 +08:00
|
|
|
installer = virtinst.Installer(guest.conn,
|
|
|
|
cdrom=cdrom,
|
|
|
|
location=location,
|
2019-02-01 07:07:09 +08:00
|
|
|
location_kernel=location_kernel,
|
|
|
|
location_initrd=location_initrd,
|
2019-06-12 05:34:18 +08:00
|
|
|
install_bootdev=install_bootdev,
|
|
|
|
install_kernel=install_kernel,
|
2019-06-13 04:56:37 +08:00
|
|
|
install_initrd=install_initrd,
|
2019-06-14 04:15:21 +08:00
|
|
|
install_kernel_args=install_kernel_args,
|
|
|
|
no_install=no_install)
|
2019-06-13 05:55:30 +08:00
|
|
|
|
2019-09-12 00:19:09 +08:00
|
|
|
if unattended_data:
|
2019-02-22 16:40:21 +08:00
|
|
|
installer.set_unattended_data(unattended_data)
|
2019-06-13 05:55:30 +08:00
|
|
|
if extra_args:
|
|
|
|
installer.set_extra_args(extra_args)
|
|
|
|
if options.initrd_inject:
|
|
|
|
installer.set_initrd_injections(options.initrd_inject)
|
2018-10-13 21:42:15 +08:00
|
|
|
if options.autostart:
|
|
|
|
installer.autostart = True
|
2019-06-29 00:05:18 +08:00
|
|
|
if options.cloud_init:
|
|
|
|
cloudinit_data = cli.parse_cloud_init(options.cloud_init)
|
|
|
|
installer.set_cloudinit_data(cloudinit_data)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return installer
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2019-06-11 23:54:02 +08:00
|
|
|
def set_cli_defaults(options, guest):
|
|
|
|
if not guest.name:
|
|
|
|
default_name = virtinst.Guest.generate_name(guest)
|
|
|
|
cli.print_stdout(_("Using default --name {vm_name}").format(
|
|
|
|
vm_name=default_name))
|
|
|
|
guest.name = default_name
|
|
|
|
|
2019-02-08 03:37:25 +08:00
|
|
|
if guest.os.is_container():
|
2020-01-15 02:07:38 +08:00
|
|
|
if not memory_specified(guest):
|
2020-01-15 23:28:53 +08:00
|
|
|
mbram = 1024
|
2020-01-15 02:07:38 +08:00
|
|
|
# LXC doesn't even do anything with memory settings, but libvirt
|
|
|
|
# XML requires it anyways. Fill in 64 MiB
|
2020-01-15 23:28:53 +08:00
|
|
|
cli.print_stdout(
|
|
|
|
_("Using container default --memory {megabytes}").format(
|
|
|
|
megabytes=mbram))
|
|
|
|
guest.currentMemory = mbram * 1024
|
2019-02-08 03:37:25 +08:00
|
|
|
return
|
2019-06-11 07:31:37 +08:00
|
|
|
|
2019-07-31 21:50:24 +08:00
|
|
|
if (options.unattended and
|
|
|
|
guest.osinfo.is_windows() and
|
|
|
|
guest.osinfo.supports_unattended_drivers(guest.os.arch)):
|
|
|
|
guest.add_extra_drivers(
|
|
|
|
guest.osinfo.get_pre_installable_devices(guest.os.arch))
|
|
|
|
|
2019-05-12 06:05:59 +08:00
|
|
|
res = guest.osinfo.get_recommended_resources()
|
|
|
|
storage = res.get_recommended_storage(guest.os.arch)
|
2019-06-11 07:31:37 +08:00
|
|
|
ram = res.get_recommended_ram(guest.os.arch)
|
|
|
|
ncpus = res.get_recommended_ncpus(guest.os.arch)
|
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
if ram and not memory_specified(guest):
|
2019-06-12 00:15:35 +08:00
|
|
|
mbram = str(ram / (1024 * 1024)).rstrip("0").rstrip(".")
|
|
|
|
cli.print_stdout(
|
|
|
|
_("Using {os_name} default --memory {megabytes}").format(
|
|
|
|
os_name=guest.osinfo.name, megabytes=mbram))
|
2019-06-11 07:31:37 +08:00
|
|
|
guest.currentMemory = ram // 1024
|
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
if ncpus:
|
|
|
|
# We need to do this upfront, so we don't incorrectly set guest.vcpus
|
|
|
|
guest.sync_vcpus_topology()
|
|
|
|
if not guest.vcpus:
|
2019-06-12 00:15:35 +08:00
|
|
|
# I don't think we need to print anything here as this was never
|
|
|
|
# a required value.
|
2019-06-11 07:50:14 +08:00
|
|
|
guest.vcpus = ncpus
|
2019-05-12 06:05:59 +08:00
|
|
|
|
2019-06-11 07:50:14 +08:00
|
|
|
if storage and not storage_specified(options, guest):
|
2019-06-11 07:31:37 +08:00
|
|
|
diskstr = 'size=%d' % (storage // (1024 ** 3))
|
2019-06-12 00:15:35 +08:00
|
|
|
cli.print_stdout(
|
|
|
|
_("Using {os_name} default --disk {disk_options}".format(
|
|
|
|
os_name=guest.osinfo.name, disk_options=diskstr)))
|
2019-06-11 07:31:37 +08:00
|
|
|
options.disk = [diskstr]
|
|
|
|
cli.ParserDisk(diskstr, guest=guest).parse(None)
|
2019-02-08 03:37:25 +08:00
|
|
|
|
|
|
|
|
2019-06-14 06:40:26 +08:00
|
|
|
def set_explicit_guest_options(options, guest):
|
2014-02-05 05:16:39 +08:00
|
|
|
if options.name:
|
|
|
|
guest.name = options.name
|
2019-06-14 06:40:26 +08:00
|
|
|
options.name = None
|
2014-01-21 07:15:08 +08:00
|
|
|
if options.uuid:
|
|
|
|
guest.uuid = options.uuid
|
2019-06-14 06:40:26 +08:00
|
|
|
options.uuid = None
|
2014-01-25 09:03:30 +08:00
|
|
|
if options.description:
|
|
|
|
guest.description = options.description
|
2019-06-14 06:40:26 +08:00
|
|
|
options.description = None
|
2018-09-07 07:07:15 +08:00
|
|
|
if options.os_type:
|
|
|
|
guest.os.os_type = options.os_type
|
2019-06-14 06:40:26 +08:00
|
|
|
options.os_type = None
|
2018-09-07 07:07:15 +08:00
|
|
|
if options.virt_type:
|
|
|
|
guest.type = options.virt_type
|
2019-06-14 06:40:26 +08:00
|
|
|
options.virt_type = None
|
2018-09-07 07:07:15 +08:00
|
|
|
if options.arch:
|
|
|
|
guest.os.arch = options.arch
|
2019-06-14 06:40:26 +08:00
|
|
|
options.arch = None
|
2018-09-07 07:07:15 +08:00
|
|
|
if options.machine:
|
|
|
|
guest.os.machine = options.machine
|
2019-06-14 06:40:26 +08:00
|
|
|
options.machine = None
|
|
|
|
|
|
|
|
|
|
|
|
def installer_detect_distro(guest, installer, osdata):
|
|
|
|
try:
|
2019-11-18 18:00:45 +08:00
|
|
|
# OS name has to be set firstly whenever --os-variant is passed,
|
|
|
|
# otherwise it won't be respected when the installer creates the
|
|
|
|
# Distro Store.
|
|
|
|
if osdata.name:
|
|
|
|
guest.set_os_name(osdata.name)
|
|
|
|
|
2019-06-14 06:40:26 +08:00
|
|
|
# This also validates the install location
|
|
|
|
autodistro = installer.detect_distro(guest)
|
2019-11-18 18:00:45 +08:00
|
|
|
if osdata.is_auto and autodistro:
|
|
|
|
guest.set_os_name(autodistro)
|
2019-06-14 06:40:26 +08:00
|
|
|
except ValueError as e:
|
|
|
|
fail(_("Error validating install location: %s") % str(e))
|
|
|
|
|
2019-02-08 05:26:04 +08:00
|
|
|
|
2019-06-14 06:40:26 +08:00
|
|
|
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)
|
2019-02-08 03:51:28 +08:00
|
|
|
cli.parse_option_strings(options, guest, None)
|
|
|
|
|
|
|
|
# Call set_capabilities_defaults explicitly here rather than depend
|
|
|
|
# on set_defaults calling it. Installer setup needs filled in values.
|
|
|
|
# However we want to do it after parse_option_strings to ensure
|
|
|
|
# we are operating on any arch/os/type values passed in with --boot
|
2018-12-10 17:36:16 +08:00
|
|
|
guest.set_capabilities_defaults()
|
2019-06-14 06:29:39 +08:00
|
|
|
|
2019-06-14 08:56:16 +08:00
|
|
|
installdata = cli.parse_install(options.install)
|
|
|
|
installer = build_installer(options, guest, installdata)
|
2019-06-14 08:26:26 +08:00
|
|
|
|
2019-06-14 08:56:16 +08:00
|
|
|
# Set guest osname, from commandline or detected from media
|
|
|
|
osdata = cli.parse_os_variant(options.os_variant)
|
|
|
|
if installdata.os:
|
|
|
|
osdata.set_installdata_name(installdata.os)
|
2019-06-14 06:29:39 +08:00
|
|
|
guest.set_default_os_name()
|
2019-06-14 06:40:26 +08:00
|
|
|
installer_detect_distro(guest, installer, osdata)
|
2018-12-10 17:36:16 +08:00
|
|
|
|
2019-06-14 06:40:26 +08:00
|
|
|
set_cli_defaults(options, guest)
|
2019-06-14 04:15:21 +08:00
|
|
|
installer.set_install_defaults(guest)
|
|
|
|
for path in installer.get_search_paths(guest):
|
|
|
|
cli.check_path_search(guest.conn, path)
|
2019-02-08 04:00:27 +08:00
|
|
|
|
2018-09-07 07:07:15 +08:00
|
|
|
# cli specific disk validation
|
2018-03-21 05:23:34 +08:00
|
|
|
for disk in guest.devices.disk:
|
2014-02-05 05:16:39 +08:00
|
|
|
cli.validate_disk(disk)
|
|
|
|
|
2018-09-13 05:23:01 +08:00
|
|
|
validate_required_options(options, guest, installer)
|
2019-11-25 06:30:49 +08:00
|
|
|
show_guest_warnings(options, guest, osdata)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-04 03:21:11 +08:00
|
|
|
return guest, installer
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Install process helpers #
|
|
|
|
###########################
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
def _sleep(secs):
|
|
|
|
if not cli.in_testsuite():
|
|
|
|
time.sleep(secs) # pragma: no cover
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
class WaitHandler:
|
|
|
|
"""
|
|
|
|
Helper class for handling the --wait option sleeping and time tracking
|
|
|
|
"""
|
|
|
|
def __init__(self, wait):
|
|
|
|
self.wait_is_requested = False
|
|
|
|
self._wait_mins = 0
|
|
|
|
self._start_time = 0
|
|
|
|
|
|
|
|
if wait is not None:
|
|
|
|
self.wait_is_requested = True
|
|
|
|
self._wait_mins = wait
|
|
|
|
|
|
|
|
@property
|
|
|
|
def wait_for_console_to_exit(self):
|
|
|
|
# If --wait specified, we don't want the default behavior of waiting
|
|
|
|
# for virt-viewer to exit, we want to launch it, then manually count
|
|
|
|
# down time for ourselves
|
|
|
|
return not self.wait_is_requested
|
|
|
|
@property
|
|
|
|
def _wait_forever(self):
|
|
|
|
return self._wait_mins < 0
|
|
|
|
@property
|
|
|
|
def _wait_secs(self):
|
|
|
|
return self._wait_mins * 60
|
|
|
|
|
|
|
|
def start(self):
|
|
|
|
self._start_time = time.time()
|
|
|
|
|
|
|
|
def get_time_string(self):
|
2019-07-25 20:09:53 +08:00
|
|
|
timestr = _(" %d minutes") % self._wait_mins
|
2019-06-14 04:02:58 +08:00
|
|
|
if self._wait_forever:
|
|
|
|
timestr = ""
|
|
|
|
ret = _("Waiting%(time_string)s for installation to complete.") % {
|
|
|
|
"time_string": timestr}
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def wait(self):
|
|
|
|
"""
|
|
|
|
sleep 1 second, then teturn True if wait time has expired
|
|
|
|
"""
|
|
|
|
_sleep(1)
|
|
|
|
if self._wait_forever:
|
|
|
|
if cli.in_testsuite():
|
|
|
|
return True
|
|
|
|
return False # pragma: no cover
|
2014-09-21 06:20:41 +08:00
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
time_elapsed = (time.time() - self._start_time)
|
|
|
|
return (time_elapsed >= self._wait_secs) or cli.in_testsuite()
|
|
|
|
|
|
|
|
|
2019-11-26 02:00:36 +08:00
|
|
|
def _print_cloudinit_passwd(installer):
|
|
|
|
passwd = installer.get_generated_password()
|
|
|
|
if not passwd:
|
|
|
|
return
|
|
|
|
|
|
|
|
print_stdout(_("Password for first root login is: %s") % passwd,
|
|
|
|
do_force=True, do_log=False)
|
|
|
|
|
|
|
|
stdins = [sys.stdin]
|
|
|
|
timeout = 10
|
|
|
|
if sys.stdin.closed or not sys.stdin.isatty():
|
|
|
|
if not cli.in_testsuite(): # pragma: no cover
|
|
|
|
return
|
|
|
|
stdins = []
|
|
|
|
timeout = .0001
|
|
|
|
|
|
|
|
sys.stdout.write(
|
|
|
|
_("Installation will continue in 10 seconds "
|
|
|
|
"(press Enter to skip)..."))
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
select.select(stdins, [], [], timeout)
|
|
|
|
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
def start_install(guest, installer, options):
|
2019-11-26 02:38:52 +08:00
|
|
|
autoconsole = cli.parse_autoconsole(options, guest, installer)
|
2019-11-25 07:10:56 +08:00
|
|
|
show_console_warnings(installer, autoconsole)
|
|
|
|
|
|
|
|
conscb = autoconsole.get_console_cb()
|
|
|
|
if autoconsole.is_default() and not conscb and options.wait is None:
|
|
|
|
# If there isn't any console to actually connect up,
|
|
|
|
# default to --wait -1 to get similarish behavior
|
|
|
|
log.warning(_("No console to launch for the guest, "
|
|
|
|
"defaulting to --wait -1"))
|
|
|
|
options.wait = -1
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
waithandler = WaitHandler(options.wait)
|
2015-04-12 07:25:46 +08:00
|
|
|
meter = cli.get_meter()
|
2019-11-26 02:00:36 +08:00
|
|
|
log.debug("Guest.has_install_phase: %s", installer.has_install_phase())
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# we've got everything -- try to start the install
|
|
|
|
print_stdout(_("\nStarting install..."))
|
|
|
|
|
2018-09-04 01:41:39 +08:00
|
|
|
domain = None
|
2013-03-18 05:06:52 +08:00
|
|
|
try:
|
2019-11-26 02:52:53 +08:00
|
|
|
_print_cloudinit_passwd(installer)
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
waithandler.start()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-04 03:21:11 +08:00
|
|
|
domain = installer.start_install(guest, meter=meter,
|
2018-09-04 01:45:09 +08:00
|
|
|
doboot=not options.noreboot,
|
2018-10-13 21:42:15 +08:00
|
|
|
transient=options.transient)
|
2018-10-12 02:11:37 +08:00
|
|
|
|
|
|
|
if options.destroy_on_exit:
|
|
|
|
atexit.register(_destroy_on_exit, domain)
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
cli.connect_console(guest, domain, conscb,
|
|
|
|
waithandler.wait_for_console_to_exit,
|
2018-10-12 02:11:37 +08:00
|
|
|
options.destroy_on_exit)
|
2019-06-14 04:02:58 +08:00
|
|
|
check_domain(installer, domain, conscb, options.transient, waithandler)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-03-27 04:43:28 +08:00
|
|
|
print_stdout(_("Domain creation completed."))
|
2018-09-04 01:41:39 +08:00
|
|
|
if not options.transient and not domain.isActive():
|
2018-09-04 03:21:11 +08:00
|
|
|
if options.noreboot or not installer.has_install_phase():
|
2019-06-11 06:13:31 +08:00
|
|
|
print_stdout( # pragma: no cover
|
2015-03-27 04:43:28 +08:00
|
|
|
_("You can restart your domain by running:\n %s") %
|
|
|
|
cli.virsh_start_cmd(guest))
|
|
|
|
else:
|
|
|
|
print_stdout(_("Restarting guest."))
|
2018-09-04 01:41:39 +08:00
|
|
|
domain.create()
|
2018-10-12 02:11:37 +08:00
|
|
|
cli.connect_console(guest, domain, conscb, True,
|
|
|
|
options.destroy_on_exit)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2019-06-11 06:13:31 +08:00
|
|
|
except KeyboardInterrupt: # pragma: no cover
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("", exc_info=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
print_stderr(_("Domain install interrupted."))
|
|
|
|
raise
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(e, do_exit=False)
|
2018-09-04 01:41:39 +08:00
|
|
|
if domain is None:
|
2018-09-04 03:21:11 +08:00
|
|
|
installer.cleanup_created_disks(guest, meter)
|
2013-03-18 05:06:52 +08:00
|
|
|
cli.install_fail(guest)
|
|
|
|
|
2019-06-11 06:13:31 +08:00
|
|
|
if cli.in_testsuite() and options.destroy_on_exit:
|
|
|
|
# Helps with unit testing
|
|
|
|
_destroy_on_exit(domain)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
def check_domain(installer, domain, conscb, transient, waithandler):
|
2013-03-18 05:06:52 +08:00
|
|
|
"""
|
|
|
|
Make sure domain ends up in expected state, and wait if for install
|
|
|
|
to complete if requested
|
|
|
|
"""
|
2016-06-18 00:12:17 +08:00
|
|
|
def check_domain_inactive():
|
2016-06-01 21:32:56 +08:00
|
|
|
try:
|
2018-09-04 01:41:39 +08:00
|
|
|
dominfo = domain.info()
|
2016-06-01 21:32:56 +08:00
|
|
|
state = dominfo[0]
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2016-06-01 21:32:56 +08:00
|
|
|
if state == libvirt.VIR_DOMAIN_CRASHED:
|
2019-06-11 06:13:31 +08:00
|
|
|
fail(_("Domain has crashed.")) # pragma: no cover
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-09-04 01:41:39 +08:00
|
|
|
return not domain.isActive()
|
2017-05-06 00:47:21 +08:00
|
|
|
except libvirt.libvirtError as e:
|
2016-06-01 21:32:56 +08:00
|
|
|
if transient and e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("transient VM shutdown and disappeared.")
|
2016-06-01 21:32:56 +08:00
|
|
|
return True
|
2019-06-11 06:13:31 +08:00
|
|
|
raise # pragma: no cover
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2016-06-18 00:12:17 +08:00
|
|
|
if check_domain_inactive():
|
2016-06-17 23:43:41 +08:00
|
|
|
return
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2016-06-18 00:12:17 +08: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
|
2019-06-14 04:02:58 +08:00
|
|
|
_sleep(2)
|
2016-06-18 00:12:17 +08:00
|
|
|
if check_domain_inactive():
|
2019-06-11 06:13:31 +08:00
|
|
|
return # pragma: no cover
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2016-06-18 00:12:17 +08:00
|
|
|
# If we reach here, the VM still appears to be running.
|
2019-06-14 04:02:58 +08:00
|
|
|
if not waithandler.wait_is_requested:
|
2013-03-18 05:06:52 +08:00
|
|
|
# User either:
|
|
|
|
# used --noautoconsole
|
|
|
|
# killed console and guest is still running
|
2018-09-04 03:21:11 +08:00
|
|
|
if not installer.has_install_phase():
|
2016-06-17 23:43:41 +08:00
|
|
|
return
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
print_stdout(
|
|
|
|
_("Domain installation still in progress. You can reconnect"
|
|
|
|
" to \nthe console to complete the installation process."))
|
|
|
|
sys.exit(0)
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
print_stdout(_("Domain installation still in progress."))
|
|
|
|
print_stdout(waithandler.get_time_string())
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Wait loop
|
|
|
|
while True:
|
2020-01-15 23:59:17 +08:00
|
|
|
if check_domain_inactive(): # pragma: no cover
|
2016-06-18 00:12:17 +08:00
|
|
|
print_stdout(_("Domain has shutdown. Continuing."))
|
|
|
|
break
|
|
|
|
|
2019-06-14 04:02:58 +08:00
|
|
|
done = waithandler.wait()
|
|
|
|
if done:
|
|
|
|
print_stdout(
|
|
|
|
_("Installation has exceeded specified time limit. "
|
|
|
|
"Exiting application."))
|
|
|
|
sys.exit(1)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
########################
|
|
|
|
# XML printing helpers #
|
|
|
|
########################
|
|
|
|
|
2018-09-04 03:21:11 +08:00
|
|
|
def xml_to_print(guest, installer, xmlonly, dry):
|
|
|
|
start_xml, final_xml = installer.start_install(
|
|
|
|
guest, dry=dry, return_xml=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
if not start_xml:
|
|
|
|
start_xml = final_xml
|
|
|
|
final_xml = None
|
|
|
|
|
2015-04-05 05:10:45 +08:00
|
|
|
if dry and not xmlonly:
|
2013-03-18 05:06:52 +08: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-17 04:13:54 +08: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 05:10:45 +08:00
|
|
|
if xmlonly == "1":
|
2013-03-18 05:06:52 +08:00
|
|
|
return start_xml
|
2015-04-05 05:10:45 +08: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-17 04:13:54 +08:00
|
|
|
if not final_xml:
|
2013-03-18 05:06:52 +08: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-07-01 03:03:53 +08:00
|
|
|
parser = cli.setupParser(
|
2016-04-08 03:52:07 +08:00
|
|
|
"%(prog)s --name NAME --memory MB STORAGE INSTALL [options]",
|
2014-01-22 22:06:35 +08:00
|
|
|
_("Create a new virtual machine from specified install media."),
|
|
|
|
introspection_epilog=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
cli.add_connect_option(parser)
|
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
geng = parser.add_argument_group(_("General Options"))
|
2014-01-21 07:04:23 +08:00
|
|
|
geng.add_argument("-n", "--name",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Name of the guest instance"))
|
2014-01-25 07:56:59 +08:00
|
|
|
cli.add_memory_option(geng, backcompat=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
cli.vcpu_cli_options(geng)
|
2014-01-25 09:03:30 +08:00
|
|
|
cli.add_metadata_option(geng)
|
|
|
|
geng.add_argument("-u", "--uuid", help=argparse.SUPPRESS)
|
|
|
|
geng.add_argument("--description", help=argparse.SUPPRESS)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
insg = parser.add_argument_group(_("Installation Method Options"))
|
|
|
|
insg.add_argument("-c", dest="cdrom_short", help=argparse.SUPPRESS)
|
2014-01-21 07:04:23 +08:00
|
|
|
insg.add_argument("--cdrom", help=_("CD-ROM installation media"))
|
|
|
|
insg.add_argument("-l", "--location",
|
2018-06-13 01:49:25 +08:00
|
|
|
help=_("Distro install URL, eg. https://host/path. See man "
|
|
|
|
"page for specific distro examples."))
|
2014-01-21 07:04:23 +08:00
|
|
|
insg.add_argument("--pxe", action="store_true",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Boot from the network using the PXE protocol"))
|
2014-01-19 06:01:43 +08:00
|
|
|
insg.add_argument("--import", action="store_true", dest="import_install",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Build guest around an existing disk image"))
|
2019-06-17 11:09:31 +08:00
|
|
|
insg.add_argument("--livecd", action="store_true", help=argparse.SUPPRESS)
|
2016-03-18 10:28:17 +08:00
|
|
|
insg.add_argument("-x", "--extra-args", action="append",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Additional arguments to pass to the install kernel "
|
|
|
|
"booted from --location"))
|
2014-01-21 07:04:23 +08:00
|
|
|
insg.add_argument("--initrd-inject", action="append",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Add given file to root of initrd from --location"))
|
2019-06-12 03:18:47 +08:00
|
|
|
insg.add_argument("--unattended", nargs="?", const=1,
|
2019-06-12 05:34:18 +08:00
|
|
|
help=_("Perform an unattended installation"))
|
|
|
|
insg.add_argument("--install",
|
|
|
|
help=_("Specify fine grained install options"))
|
2019-06-29 00:05:18 +08:00
|
|
|
insg.add_argument("--cloud-init", nargs="?", const=1,
|
|
|
|
help=_("Perform a cloud image installation, configuring cloud-init"))
|
2014-09-07 23:57:04 +08:00
|
|
|
|
2014-09-21 08:32:19 +08:00
|
|
|
# Takes a URL and just prints to stdout the detected distro name
|
|
|
|
insg.add_argument("--test-media-detection", help=argparse.SUPPRESS)
|
2018-06-12 22:50:36 +08:00
|
|
|
# Helper for cli testing, fills in standard stub options
|
|
|
|
insg.add_argument("--test-stub-command", action="store_true",
|
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 08:32:19 +08:00
|
|
|
|
2014-02-11 07:13:42 +08:00
|
|
|
cli.add_boot_options(insg)
|
2014-01-22 04:36:34 +08:00
|
|
|
insg.add_argument("--init", help=argparse.SUPPRESS)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2019-01-09 01:44:53 +08:00
|
|
|
osg = cli.add_os_variant_option(parser, virtinstall=True)
|
2019-02-08 04:48:40 +08:00
|
|
|
osg.add_argument("--os-type", dest="old_os_type", help=argparse.SUPPRESS)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-21 07:30:16 +08: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 06:01:43 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 07:30:16 +08:00
|
|
|
devg.add_argument("-s", "--file-size", type=float,
|
2013-03-18 05:06:52 +08:00
|
|
|
action="append", dest="disksize",
|
2014-01-19 06:01:43 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 07:30:16 +08:00
|
|
|
devg.add_argument("--nonsparse", action="store_false",
|
2013-03-18 05:06:52 +08:00
|
|
|
default=True, dest="sparse",
|
2014-01-19 06:01:43 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 07:30:16 +08:00
|
|
|
devg.add_argument("--nodisks", action="store_true", help=argparse.SUPPRESS)
|
|
|
|
devg.add_argument("--nonetworks", action="store_true",
|
2014-09-21 06:56:39 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 07:30:16 +08:00
|
|
|
devg.add_argument("-b", "--bridge", action="append",
|
2014-09-20 08:31:22 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2014-09-21 07:30:16 +08: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 08:31:22 +08:00
|
|
|
help=argparse.SUPPRESS)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-21 07:30:16 +08:00
|
|
|
|
|
|
|
gxmlg = parser.add_argument_group(_("Guest Configuration Options"))
|
|
|
|
cli.add_guest_xml_options(gxmlg)
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
virg = parser.add_argument_group(_("Virtualization Platform Options"))
|
2018-09-07 07:07:15 +08:00
|
|
|
ostypeg = virg.add_mutually_exclusive_group()
|
|
|
|
ostypeg.add_argument("-v", "--hvm",
|
|
|
|
action="store_const", const="hvm", dest="os_type",
|
|
|
|
help=_("This guest should be a fully virtualized guest"))
|
|
|
|
ostypeg.add_argument("-p", "--paravirt",
|
|
|
|
action="store_const", const="xen", dest="os_type",
|
|
|
|
help=_("This guest should be a paravirtualized guest"))
|
|
|
|
ostypeg.add_argument("--container",
|
|
|
|
action="store_const", const="exe", dest="os_type",
|
|
|
|
help=_("This guest should be a container guest"))
|
|
|
|
virg.add_argument("--virt-type",
|
|
|
|
help=_("Hypervisor name to use (kvm, qemu, xen, ...)"))
|
|
|
|
virg.add_argument("--arch", help=_("The CPU architecture to simulate"))
|
|
|
|
virg.add_argument("--machine", help=_("The machine type to emulate"))
|
|
|
|
virg.add_argument("--accelerate", action="store_true",
|
|
|
|
help=argparse.SUPPRESS)
|
2014-09-20 08:31:22 +08: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 05:06:52 +08:00
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
misc = parser.add_argument_group(_("Miscellaneous Options"))
|
2018-10-12 00:53:03 +08:00
|
|
|
misc.add_argument("--autostart", action="store_true", default=False,
|
|
|
|
help=_("Have domain autostart on host boot up."))
|
|
|
|
misc.add_argument("--transient", action="store_true", default=False,
|
2016-06-01 21:32:56 +08:00
|
|
|
help=_("Create a transient domain."))
|
2018-10-12 02:11:37 +08:00
|
|
|
misc.add_argument("--destroy-on-exit", action="store_true", default=False,
|
|
|
|
help=_("Force power off the domain when the console "
|
|
|
|
"viewer is closed."))
|
2019-06-17 10:46:39 +08:00
|
|
|
misc.add_argument("--wait", type=int, const=-1, nargs="?",
|
2018-10-12 00:53:03 +08:00
|
|
|
help=_("Minutes to wait for install to complete."))
|
2013-09-28 23:27:26 +08:00
|
|
|
|
|
|
|
cli.add_misc_options(misc, prompt=True, printxml=True, printstep=True,
|
2014-02-06 08:09:26 +08:00
|
|
|
noreboot=True, dryrun=True, noautoconsole=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-12-07 16:28:49 +08:00
|
|
|
cli.autocomplete(parser)
|
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
return parser.parse_args()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
# main() handling #
|
|
|
|
###################
|
|
|
|
|
2018-10-12 02:11:37 +08:00
|
|
|
# Catchall for destroying the VM on ex. ctrl-c
|
|
|
|
def _destroy_on_exit(domain):
|
|
|
|
try:
|
|
|
|
isactive = bool(domain and domain.isActive())
|
|
|
|
if isactive:
|
2019-06-14 02:47:08 +08:00
|
|
|
domain.destroy() # pragma: no cover
|
2019-06-11 06:13:31 +08:00
|
|
|
except libvirt.libvirtError as e: # pragma: no cover
|
2018-10-12 02:11:37 +08:00
|
|
|
if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("Error invoking atexit destroy_on_exit",
|
2018-10-12 02:11:37 +08:00
|
|
|
exc_info=True)
|
|
|
|
|
|
|
|
|
2019-06-11 06:13:31 +08:00
|
|
|
def set_test_stub_options(options): # pragma: no cover
|
2018-06-12 22:50:36 +08:00
|
|
|
# Set some basic options that will let virt-install succeed. Helps
|
|
|
|
# save boiler plate typing when testing new command line additions
|
|
|
|
if not options.test_stub_command:
|
|
|
|
return
|
|
|
|
|
2019-06-14 02:13:29 +08:00
|
|
|
options.import_install = True
|
2018-06-12 22:50:36 +08:00
|
|
|
if not options.connect:
|
|
|
|
options.connect = "test:///default"
|
|
|
|
if not options.name:
|
|
|
|
options.name = "test-stub-command"
|
|
|
|
if not options.memory:
|
|
|
|
options.memory = "256"
|
|
|
|
if not options.disk:
|
|
|
|
options.disk = "none"
|
|
|
|
if not options.graphics:
|
|
|
|
options.graphics = "none"
|
2019-02-08 04:48:40 +08:00
|
|
|
if not options.os_variant:
|
|
|
|
options.os_variant = "fedora27"
|
2018-06-12 22:50:36 +08:00
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def main(conn=None):
|
|
|
|
cli.earlyLogging()
|
2014-01-19 06:01:43 +08:00
|
|
|
options = parse_args()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Default setup options
|
2018-06-06 02:54:34 +08:00
|
|
|
convert_old_printxml(options)
|
2015-04-05 05:10:45 +08:00
|
|
|
options.quiet = (options.xmlonly or
|
2014-09-21 08:32:19 +08:00
|
|
|
options.test_media_detection or options.quiet)
|
2013-03-18 05:06:52 +08:00
|
|
|
cli.setupLogging("virt-install", options.debug, options.quiet)
|
|
|
|
|
2018-06-06 02:54:34 +08:00
|
|
|
if cli.check_option_introspection(options):
|
|
|
|
return 0
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2018-06-06 02:54:34 +08:00
|
|
|
check_cdrom_option_error(options)
|
2015-04-12 07:25:46 +08:00
|
|
|
cli.convert_old_force(options)
|
|
|
|
cli.parse_check(options.check)
|
2013-03-18 05:06:52 +08:00
|
|
|
cli.set_prompt(options.prompt)
|
2018-06-06 02:54:34 +08: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)
|
2019-07-03 03:39:51 +08:00
|
|
|
convert_wait_zero(options)
|
2018-06-12 22:50:36 +08:00
|
|
|
set_test_stub_options(options)
|
2018-06-06 02:54:34 +08:00
|
|
|
convert_old_os_options(options)
|
2014-01-22 22:06:35 +08:00
|
|
|
|
2019-06-11 06:13:31 +08:00
|
|
|
conn = cli.getConnection(options.connect, conn=conn)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-21 08:32:19 +08:00
|
|
|
if options.test_media_detection:
|
2018-09-07 08:28:05 +08:00
|
|
|
do_test_media_detection(conn, options)
|
2014-09-21 08:32:19 +08:00
|
|
|
return 0
|
|
|
|
|
2018-09-04 03:21:11 +08:00
|
|
|
guest, installer = build_guest_instance(conn, options)
|
2015-04-05 05:10:45 +08:00
|
|
|
if options.xmlonly or options.dry:
|
2018-09-04 03:21:11 +08:00
|
|
|
xml = xml_to_print(guest, installer, options.xmlonly, options.dry)
|
2013-03-18 05:06:52 +08:00
|
|
|
if xml:
|
|
|
|
print_stdout(xml, do_force=True)
|
|
|
|
else:
|
2018-09-04 03:21:11 +08:00
|
|
|
start_install(guest, installer, options)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
2019-06-11 06:13:31 +08:00
|
|
|
if __name__ == "__main__": # pragma: no cover
|
2013-03-18 05:06:52 +08:00
|
|
|
try:
|
|
|
|
sys.exit(main())
|
2017-05-06 00:47:21 +08:00
|
|
|
except SystemExit as sys_e:
|
2013-03-18 05:06:52 +08:00
|
|
|
sys.exit(sys_e.code)
|
|
|
|
except KeyboardInterrupt:
|
2019-06-17 09:12:39 +08:00
|
|
|
log.debug("", exc_info=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
print_stderr(_("Installation aborted at user request"))
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as main_e:
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(main_e)
|