2014-02-12 17:21:38 +08:00
|
|
|
#!/usr/bin/python2 -tt
|
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
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import re
|
2013-03-18 05:06:52 +08:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2013-08-10 03:00:16 +08:00
|
|
|
import libvirt
|
2013-03-18 05:06:52 +08:00
|
|
|
import urlgrabber.progress as progress
|
|
|
|
|
|
|
|
import virtinst
|
2014-09-20 08:31:22 +08:00
|
|
|
from virtinst import cli
|
2013-03-18 05:06:52 +08: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-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def install_specified(location, cdpath, pxe, import_install):
|
|
|
|
return bool(pxe or cdpath or location or import_install)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2014-01-21 07:04:23 +08:00
|
|
|
def cdrom_specified(guest, disk=None):
|
2013-04-12 21:39:34 +08:00
|
|
|
disks = guest.get_devices("disk")
|
|
|
|
|
|
|
|
for disk in disks:
|
2013-03-18 05:06:52 +08:00
|
|
|
if disk.device == virtinst.VirtualDisk.DEVICE_CDROM:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Probably haven't set up disks yet
|
2014-01-21 07:04:23 +08:00
|
|
|
if not disks and disk:
|
|
|
|
for opts in disk:
|
2013-03-18 05:06:52 +08:00
|
|
|
if opts.count("device=cdrom"):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
for nic in guest.get_devices("interface"):
|
|
|
|
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))
|
|
|
|
if xmlobj.can_pxe():
|
2013-03-18 05:06:52 +08:00
|
|
|
return True
|
|
|
|
except:
|
|
|
|
logging.debug("Error checking if PXE supported", exc_info=True)
|
|
|
|
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:
|
|
|
|
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-05 00:04:07 +08:00
|
|
|
if not options.cdrom:
|
|
|
|
return
|
|
|
|
|
2013-04-22 00:28:14 +08: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-05 00:04:07 +08: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")
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
##############################
|
|
|
|
# Device validation wrappers #
|
|
|
|
##############################
|
|
|
|
|
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:
|
|
|
|
options.boot = ""
|
|
|
|
options.boot += ",init=%s" % options.init
|
|
|
|
logging.debug("Converted old --init to --boot %s", options.boot)
|
|
|
|
|
|
|
|
|
2014-09-21 07:16:13 +08:00
|
|
|
def _do_convert_old_disks(options):
|
2013-09-28 08:16:35 +08:00
|
|
|
paths = virtinst.util.listify(options.file_paths)
|
|
|
|
sizes = virtinst.util.listify(options.disksize)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def padlist(l, padsize):
|
2013-09-28 08:16:35 +08:00
|
|
|
l = virtinst.util.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 = []
|
2013-03-18 05:06:52 +08:00
|
|
|
for idx in range(len(disklist)):
|
2013-09-28 08:16:35 +08:00
|
|
|
optstr = ""
|
|
|
|
if disklist[idx]:
|
|
|
|
optstr += "path=%s" % disklist[idx]
|
|
|
|
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 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)
|
|
|
|
logging.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):
|
|
|
|
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 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
|
|
|
|
if not options.vcpus:
|
|
|
|
options.vcpus = ""
|
|
|
|
options.vcpus += ",cpuset=%s" % options.cpuset
|
|
|
|
logging.debug("Generated compat cpuset: --vcpus %s", options.vcpus)
|
|
|
|
|
|
|
|
|
2014-09-21 06:56:39 +08: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"]
|
|
|
|
|
|
|
|
macs = virtinst.util.listify(options.mac)
|
2014-09-20 08:31:22 +08:00
|
|
|
networks = virtinst.util.listify(options.network)
|
2014-09-21 06:56:39 +08:00
|
|
|
bridges = virtinst.util.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):
|
|
|
|
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 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))
|
|
|
|
|
|
|
|
for idx in range(len(networks)):
|
|
|
|
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
|
2014-09-21 06:56:39 +08:00
|
|
|
logging.debug("Distilled --network options: %s", options.network)
|
2014-09-20 08:31:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
def _determine_default_graphics(guest, default_override):
|
|
|
|
if default_override is True:
|
|
|
|
return
|
|
|
|
elif default_override is False:
|
|
|
|
guest.skip_default_graphics = True
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def convert_old_graphics(guest, options, default_override=None):
|
|
|
|
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:
|
|
|
|
_determine_default_graphics(guest, default_override)
|
|
|
|
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 05:06:52 +08:00
|
|
|
########################
|
|
|
|
# Virt type validation #
|
|
|
|
########################
|
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
def get_guest(conn, options):
|
2013-03-18 05:06:52 +08:00
|
|
|
# Set up all virt/hypervisor parameters
|
2013-04-12 04:32:00 +08:00
|
|
|
if sum([bool(f) for f in [options.fullvirt,
|
|
|
|
options.paravirt,
|
|
|
|
options.container]]) > 1:
|
2013-03-18 05:06:52 +08: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:
|
|
|
|
(capsguest,
|
2013-07-07 02:12:13 +08:00
|
|
|
capsdomain) = conn.caps.guest_lookup(
|
2013-03-18 05:06:52 +08:00
|
|
|
os_type=req_virt_type,
|
|
|
|
arch=arch,
|
2013-04-12 20:26:21 +08:00
|
|
|
typ=req_hv_type,
|
2013-03-18 05:06:52 +08:00
|
|
|
machine=options.machine)
|
2013-07-17 19:53:47 +08:00
|
|
|
guest = conn.caps.build_virtinst_guest(conn, capsguest, capsdomain)
|
|
|
|
guest.os.machine = options.machine
|
2013-03-18 05:06:52 +08:00
|
|
|
except Exception, e:
|
|
|
|
fail(e)
|
|
|
|
|
|
|
|
if (not req_virt_type and
|
|
|
|
not req_hv_type and
|
2013-07-06 08:36:28 +08:00
|
|
|
conn.is_qemu() and
|
2013-03-18 05:06:52 +08:00
|
|
|
capsguest.arch in ["i686", "x86_64"] and
|
|
|
|
not capsdomain.is_accelerated()):
|
|
|
|
logging.warn("KVM acceleration not available, using '%s'",
|
|
|
|
capsdomain.hypervisor_type)
|
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
return guest
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Install media setup/validation #
|
|
|
|
##################################
|
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
def set_install_media(guest, location, cdpath, distro_variant):
|
|
|
|
try:
|
|
|
|
cdinstall = bool(not location and (cdpath or cdrom_specified(guest)))
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
if cdinstall or cdpath:
|
|
|
|
guest.installer.cdrom = True
|
|
|
|
if location or cdpath:
|
|
|
|
guest.installer.location = (location or cdpath)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
guest.installer.check_location(guest)
|
|
|
|
|
|
|
|
if distro_variant == "auto":
|
|
|
|
guest.os_variant = guest.installer.detect_distro(guest)
|
|
|
|
elif distro_variant != "none":
|
|
|
|
guest.os_variant = distro_variant
|
2013-03-18 05:06:52 +08:00
|
|
|
except ValueError, e:
|
|
|
|
fail(_("Error validating install location: %s" % str(e)))
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08: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:
|
|
|
|
msg += "\n" + cli.name_missing
|
|
|
|
|
|
|
|
if not options.memory:
|
2014-06-16 11:56:02 +08:00
|
|
|
msg += "\n" + _("--memory amount in MiB is required")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
if (not guest.os.is_container() and
|
2014-09-21 07:16:13 +08:00
|
|
|
not (options.disk or options.filesystem)):
|
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
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
if (not guest.os.is_container() and
|
2014-05-12 07:19:00 +08:00
|
|
|
not (options.xmlonly or options.xmlstep) and
|
2013-03-18 05:06:52 +08:00
|
|
|
(not install_specified(options.location, options.cdrom,
|
|
|
|
options.pxe, options.import_install)) and
|
2014-01-21 07:04:23 +08:00
|
|
|
(not cdrom_specified(guest, options.disk))):
|
2014-05-12 06:58:17 +08:00
|
|
|
msg += "\n" + (
|
|
|
|
_("An install method must be specified\n(%(methods)s)") %
|
|
|
|
{"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
|
|
|
|
2014-09-08 01:50:22 +08:00
|
|
|
_cdrom_location_man_page = _("See the man page for examples of "
|
|
|
|
"using --location with CDROM media")
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def check_option_collisions(options, guest):
|
|
|
|
# Install collisions
|
2013-04-12 04:32:00 +08:00
|
|
|
if sum([bool(l) for l in [options.pxe, options.location,
|
|
|
|
options.cdrom, options.import_install]]) > 1:
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(_("Only one install method can be used (%(methods)s)") %
|
|
|
|
{"methods" : install_methods})
|
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
if (guest.os.is_container() and
|
2013-03-18 05:06:52 +08: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 19:53:47 +08:00
|
|
|
if guest.os.is_xenpv():
|
2013-03-18 05:06:52 +08: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 08:36:28 +08:00
|
|
|
guest.conn.is_remote() and not
|
2013-10-06 22:08:04 +08:00
|
|
|
guest.conn.support_remote_url_install()):
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(_("Libvirt version does not support remote --location installs"))
|
|
|
|
|
2014-02-03 04:17:44 +08:00
|
|
|
cdrom_err = ""
|
|
|
|
if guest.installer.cdrom:
|
2014-09-08 01:50:22 +08:00
|
|
|
cdrom_err = _cdrom_location_man_page
|
2014-01-21 07:04:23 +08:00
|
|
|
if not options.location and options.extra_args:
|
2014-02-03 04:17:44 +08:00
|
|
|
fail(_("--extra-args only work if specified with --location.") +
|
|
|
|
cdrom_err)
|
2014-01-21 07:04:23 +08:00
|
|
|
if not options.location and options.initrd_inject:
|
2014-02-03 04:17:44 +08:00
|
|
|
fail(_("--initrd-inject only works if specified with --location.") +
|
|
|
|
cdrom_err)
|
|
|
|
|
|
|
|
|
|
|
|
def _show_nographics_warnings(options, guest):
|
|
|
|
if guest.get_devices("graphics"):
|
|
|
|
return
|
|
|
|
if not options.autoconsole:
|
|
|
|
return
|
|
|
|
|
|
|
|
if guest.installer.cdrom:
|
|
|
|
logging.warn(_("CDROM media does not print to the text console "
|
|
|
|
"by default, so you likely will not see text install output. "
|
2014-09-08 01:50:22 +08:00
|
|
|
"You might want to use --location.") + _cdrom_location_man_page)
|
2014-02-03 04:17:44 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
if not options.location:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Trying --location --nographics with console connect. Warn if
|
|
|
|
# they likely won't see any output.
|
|
|
|
|
|
|
|
if not guest.get_devices("console"):
|
|
|
|
logging.warn(_("No --console device added, you likely will not "
|
|
|
|
"see text install output from the guest."))
|
|
|
|
return
|
|
|
|
|
|
|
|
serial_arg = "console=ttyS0"
|
2014-08-04 04:22:07 +08:00
|
|
|
serial_arm_arg = "console=ttyAMA0"
|
2014-02-03 04:17:44 +08:00
|
|
|
virtio_arg = "console=hvc0"
|
|
|
|
console_type = None
|
|
|
|
if guest.conn.is_test() or guest.conn.is_qemu():
|
|
|
|
console_type = serial_arg
|
2014-08-04 04:22:07 +08:00
|
|
|
if guest.os.arch.startswith("arm") or guest.os.arch == "aarch64":
|
|
|
|
console_type = serial_arm_arg
|
2014-02-03 04:17:44 +08:00
|
|
|
if guest.get_devices("console")[0].target_type == "virtio":
|
|
|
|
console_type = virtio_arg
|
|
|
|
|
|
|
|
if not options.extra_args or "console=" not in options.extra_args:
|
|
|
|
logging.warn(_("No 'console' seen in --extra-args, a '%s' kernel "
|
|
|
|
"argument is likely required to see text install output from "
|
|
|
|
"the guest."), console_type or "console=")
|
|
|
|
return
|
|
|
|
|
|
|
|
if console_type in options.extra_args:
|
|
|
|
return
|
|
|
|
if (serial_arg not in options.extra_args and
|
|
|
|
virtio_arg not in options.extra_args):
|
|
|
|
return
|
|
|
|
|
|
|
|
has = (serial_arg in options.extra_args) and serial_arg or virtio_arg
|
|
|
|
need = (serial_arg in options.extra_args) and virtio_arg or serial_arg
|
|
|
|
logging.warn(_("'%s' found in --extra-args, but the device attached "
|
|
|
|
"to the guest likely requires '%s'. You may not see text install "
|
|
|
|
"output from the guest."), has, need)
|
|
|
|
if has == serial_arg:
|
|
|
|
logging.warn(_("To make '--extra-args %s' work, you can force a "
|
|
|
|
"plain serial device with '--console pty'"), serial_arg)
|
|
|
|
|
|
|
|
|
|
|
|
def show_warnings(options, guest):
|
|
|
|
if options.pxe and not supports_pxe(guest):
|
|
|
|
logging.warn(_("The guest's network configuration does not support "
|
|
|
|
"PXE"))
|
|
|
|
|
2014-09-08 01:55:45 +08:00
|
|
|
if not guest.os_variant and options.distro_variant != "none":
|
|
|
|
logging.warn(_("No operating system detected, VM performance may "
|
|
|
|
"suffer. Specify an OS with --os-variant for optimal results."))
|
|
|
|
|
2014-02-03 04:17:44 +08:00
|
|
|
_show_nographics_warnings(options, guest)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Guest building helpers #
|
|
|
|
##########################
|
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
def build_installer(options, conn, virt_type):
|
2013-03-18 05:06:52 +08:00
|
|
|
# Build the Installer instance
|
2014-09-08 01:42:56 +08:00
|
|
|
if options.pxe:
|
2013-03-18 05:06:52 +08:00
|
|
|
instclass = virtinst.PXEInstaller
|
2014-09-08 01:42:56 +08:00
|
|
|
elif options.cdrom or options.location or options.livecd:
|
2013-03-18 05:06:52 +08:00
|
|
|
instclass = virtinst.DistroInstaller
|
2014-02-03 19:03:21 +08:00
|
|
|
elif virt_type == "exe":
|
|
|
|
instclass = virtinst.ContainerInstaller
|
2014-01-21 07:04:23 +08:00
|
|
|
elif options.import_install or options.boot:
|
2013-03-18 05:06:52 +08:00
|
|
|
if options.import_install and options.nodisks:
|
|
|
|
fail(_("A disk device must be specified with --import."))
|
|
|
|
options.import_install = True
|
|
|
|
instclass = virtinst.ImportInstaller
|
2014-05-12 07:19:00 +08:00
|
|
|
elif options.xmlstep or options.xmlonly:
|
|
|
|
instclass = virtinst.ImportInstaller
|
2013-03-18 05:06:52 +08:00
|
|
|
else:
|
|
|
|
instclass = virtinst.DistroInstaller
|
|
|
|
|
2013-07-17 04:47:08 +08:00
|
|
|
installer = instclass(conn)
|
2014-09-08 01:42:56 +08:00
|
|
|
if options.livecd:
|
|
|
|
installer.livecd = True
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return installer
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2014-01-22 22:06:35 +08:00
|
|
|
def build_guest_instance(conn, options, parsermap):
|
2013-07-17 19:53:47 +08:00
|
|
|
guest = get_guest(conn, options)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
logging.debug("Received virt method '%s'", guest.type)
|
|
|
|
logging.debug("Hypervisor name is '%s'", guest.os.os_type)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-07-17 19:53:47 +08:00
|
|
|
guest.installer = build_installer(options, conn, guest.os.os_type)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-20 08:31:22 +08:00
|
|
|
convert_old_memory(options)
|
2013-09-28 08:16:35 +08:00
|
|
|
convert_old_sound(options)
|
2014-09-21 06:56:39 +08:00
|
|
|
convert_old_networks(options)
|
2014-09-20 08:31:22 +08:00
|
|
|
convert_old_graphics(guest, options)
|
2013-09-28 08:16:35 +08:00
|
|
|
convert_old_disks(options)
|
2014-09-20 08:31:22 +08:00
|
|
|
convert_old_features(options)
|
|
|
|
convert_old_cpuset(options)
|
2014-01-22 04:36:34 +08:00
|
|
|
convert_old_init(options)
|
2014-09-07 23:57:04 +08:00
|
|
|
convert_old_os_options(options)
|
2013-09-28 08:16:35 +08:00
|
|
|
|
2014-01-21 07:15:08 +08:00
|
|
|
# non-xml install options
|
2014-01-25 08:34:38 +08:00
|
|
|
guest.installer.extraargs = options.extra_args
|
2014-01-21 07:04:23 +08:00
|
|
|
guest.installer.initrd_injections = options.initrd_inject
|
2014-01-21 07:15:08 +08:00
|
|
|
guest.autostart = options.autostart
|
2013-10-06 20:53:05 +08:00
|
|
|
|
2014-02-05 05:16:39 +08:00
|
|
|
if options.name:
|
|
|
|
guest.name = options.name
|
2014-01-21 07:15:08 +08:00
|
|
|
if options.uuid:
|
|
|
|
guest.uuid = options.uuid
|
2014-01-25 09:03:30 +08:00
|
|
|
if options.description:
|
|
|
|
guest.description = options.description
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-05 05:16:39 +08:00
|
|
|
validate_required_options(options, guest)
|
|
|
|
|
2014-01-22 22:06:35 +08:00
|
|
|
# We don't want to auto-parse --disk, but we wanted it for earlier
|
|
|
|
# parameter introspection
|
2014-01-22 03:28:47 +08:00
|
|
|
cli.parse_option_strings(parsermap, options, guest, None)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-05 05:16:39 +08:00
|
|
|
# Extra disk validation
|
|
|
|
for disk in guest.get_devices("disk"):
|
|
|
|
cli.validate_disk(disk)
|
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
set_install_media(guest, options.location, options.cdrom,
|
|
|
|
options.distro_variant)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-07 23:57:04 +08:00
|
|
|
guest.add_default_devices()
|
2013-03-18 05:06:52 +08: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 04:17:44 +08:00
|
|
|
show_warnings(options, guest)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
return guest
|
|
|
|
|
|
|
|
|
|
|
|
###########################
|
|
|
|
# Install process helpers #
|
|
|
|
###########################
|
|
|
|
|
2013-08-10 03:00:16 +08:00
|
|
|
def domain_is_crashed(domain):
|
|
|
|
"""
|
|
|
|
Return True if the created domain object is in a crashed state
|
|
|
|
"""
|
|
|
|
if not domain:
|
|
|
|
return False
|
|
|
|
|
|
|
|
dominfo = domain.info()
|
|
|
|
state = dominfo[0]
|
|
|
|
|
|
|
|
return state == libvirt.VIR_DOMAIN_CRASHED
|
|
|
|
|
|
|
|
|
|
|
|
def domain_is_shutdown(domain):
|
|
|
|
"""
|
|
|
|
Return True if the created domain object is shutdown
|
|
|
|
"""
|
|
|
|
if not domain:
|
|
|
|
return False
|
|
|
|
|
|
|
|
dominfo = domain.info()
|
|
|
|
|
|
|
|
state = dominfo[0]
|
|
|
|
cpu_time = dominfo[4]
|
|
|
|
|
|
|
|
if state == libvirt.VIR_DOMAIN_SHUTOFF:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# If 'wait' was specified, the dom object we have was looked up
|
|
|
|
# before initially shutting down, which seems to bogus up the
|
|
|
|
# info data (all 0's). So, if it is bogus, assume the domain is
|
|
|
|
# shutdown. We will catch the error later.
|
|
|
|
return state == libvirt.VIR_DOMAIN_NOSTATE and cpu_time == 0
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def start_install(guest, continue_inst, options):
|
|
|
|
# There are two main cases we care about:
|
|
|
|
#
|
|
|
|
# Scripts: these should specify --wait always, maintaining the
|
|
|
|
# semantics of virt-install exit implying the domain has finished
|
|
|
|
# installing.
|
|
|
|
#
|
|
|
|
# Interactive: If this is a continue_inst domain, we default to
|
|
|
|
# waiting. Otherwise, we can exit before the domain has finished
|
|
|
|
# installing. Passing --wait will give the above semantics.
|
|
|
|
#
|
2014-09-21 06:20:41 +08:00
|
|
|
if options.wait is None:
|
|
|
|
wait_on_install = continue_inst
|
|
|
|
wait_time = -1
|
|
|
|
else:
|
2013-03-18 05:06:52 +08:00
|
|
|
wait_on_install = True
|
|
|
|
wait_time = options.wait * 60
|
|
|
|
|
|
|
|
# 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 06:20:41 +08: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 05:06:52 +08:00
|
|
|
|
|
|
|
meter = (options.quiet and
|
|
|
|
progress.BaseMeter() or
|
|
|
|
progress.TextMeter(fo=sys.stdout))
|
|
|
|
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
|
2013-08-09 23:25:05 +08:00
|
|
|
dom = guest.start_install(meter=meter, noboot=options.noreboot)
|
2014-02-06 08:09:26 +08:00
|
|
|
cli.connect_console(guest, conscb, wait_on_console)
|
2013-03-18 05:06:52 +08:00
|
|
|
dom = check_domain(guest, dom, conscb,
|
|
|
|
wait_on_install, wait_time, start_time)
|
|
|
|
|
|
|
|
if continue_inst:
|
2013-08-09 23:25:05 +08:00
|
|
|
dom = guest.continue_install(meter=meter)
|
2014-02-06 08:09:26 +08:00
|
|
|
cli.connect_console(guest, conscb, wait_on_console)
|
2013-03-18 05:06:52 +08:00
|
|
|
dom = check_domain(guest, dom, conscb,
|
|
|
|
wait_on_install, wait_time, start_time)
|
|
|
|
|
|
|
|
if options.noreboot or not guest.installer.has_install_phase():
|
|
|
|
print_stdout(
|
|
|
|
_("Domain creation completed. You can restart your domain by "
|
|
|
|
"running:\n %s") % cli.virsh_start_cmd(guest))
|
|
|
|
else:
|
|
|
|
print_stdout(
|
|
|
|
_("Guest installation complete... restarting guest."))
|
|
|
|
dom.create()
|
2014-02-06 08:09:26 +08:00
|
|
|
cli.connect_console(guest, conscb, True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
logging.debug("", exc_info=True)
|
|
|
|
print_stderr(_("Domain install interrupted."))
|
|
|
|
raise
|
|
|
|
except RuntimeError, e:
|
|
|
|
fail(e)
|
|
|
|
except Exception, e:
|
|
|
|
fail(e, do_exit=False)
|
|
|
|
cli.install_fail(guest)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def check_domain(guest, dom, conscb, wait_for_install, wait_time, start_time):
|
|
|
|
"""
|
|
|
|
Make sure domain ends up in expected state, and wait if for install
|
|
|
|
to complete if requested
|
|
|
|
"""
|
|
|
|
wait_forever = (wait_time < 0)
|
|
|
|
|
|
|
|
# Wait a bit so info is accurate
|
|
|
|
def check_domain_state():
|
|
|
|
dominfo = dom.info()
|
|
|
|
state = dominfo[0]
|
|
|
|
|
2013-08-10 03:00:16 +08:00
|
|
|
if domain_is_crashed(guest.domain):
|
2013-03-18 05:06:52 +08:00
|
|
|
fail(_("Domain has crashed."))
|
|
|
|
|
2013-08-10 03:00:16 +08:00
|
|
|
if domain_is_shutdown(guest.domain):
|
2013-03-18 05:06:52 +08:00
|
|
|
return dom, state
|
|
|
|
|
|
|
|
return None, state
|
|
|
|
|
|
|
|
do_sleep = bool(conscb)
|
|
|
|
try:
|
|
|
|
ret, state = check_domain_state()
|
|
|
|
if ret:
|
|
|
|
return ret
|
|
|
|
except Exception, e:
|
|
|
|
# Sometimes we see errors from libvirt here due to races
|
|
|
|
logging.exception(e)
|
|
|
|
do_sleep = True
|
|
|
|
|
|
|
|
if do_sleep:
|
|
|
|
# Sleep a bit and try again to be sure the HV has caught up
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
ret, state = check_domain_state()
|
|
|
|
if ret:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
# Domain seems to be running
|
|
|
|
logging.debug("Domain state after install: %s", state)
|
|
|
|
|
|
|
|
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():
|
|
|
|
return dom
|
|
|
|
|
|
|
|
print_stdout(
|
|
|
|
_("Domain installation still in progress. You can reconnect"
|
|
|
|
" to \nthe console to complete the installation process."))
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
timestr = (not wait_forever and
|
2014-09-21 06:20:41 +08:00
|
|
|
_(" %d minutes") % (int(wait_time) / 60) or "")
|
2013-03-18 05:06:52 +08:00
|
|
|
print_stdout(
|
2014-09-21 06:20:41 +08:00
|
|
|
_("Domain installation still in progress. Waiting"
|
2013-09-21 00:10:34 +08:00
|
|
|
"%(time_string)s for installation to complete.") %
|
|
|
|
{"time_string": timestr})
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Wait loop
|
|
|
|
while True:
|
2013-08-10 03:00:16 +08:00
|
|
|
if domain_is_shutdown(guest.domain):
|
2013-03-18 05:06:52 +08:00
|
|
|
print_stdout(_("Domain has shutdown. Continuing."))
|
|
|
|
try:
|
|
|
|
# Lookup a new domain object incase current
|
|
|
|
# one returned bogus data (see comment in
|
2013-08-10 03:00:16 +08:00
|
|
|
# domain_is_shutdown)
|
2013-03-18 05:06:52 +08:00
|
|
|
dom = guest.conn.lookupByName(guest.name)
|
|
|
|
except Exception, e:
|
|
|
|
raise RuntimeError(_("Could not lookup domain after "
|
|
|
|
"install: %s" % str(e)))
|
|
|
|
break
|
|
|
|
|
|
|
|
time_elapsed = (time.time() - start_time)
|
|
|
|
if not wait_forever and time_elapsed >= wait_time:
|
|
|
|
print_stdout(
|
|
|
|
_("Installation has exceeded specified time limit. "
|
|
|
|
"Exiting application."))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
return dom
|
|
|
|
|
|
|
|
|
|
|
|
########################
|
|
|
|
# XML printing helpers #
|
|
|
|
########################
|
|
|
|
|
|
|
|
def xml_to_print(guest, continue_inst, xmlonly, xmlstep, dry):
|
|
|
|
start_xml, final_xml = guest.start_install(dry=dry, return_xml=True)
|
|
|
|
second_xml = None
|
|
|
|
if not start_xml:
|
|
|
|
start_xml = final_xml
|
|
|
|
final_xml = None
|
|
|
|
|
|
|
|
if continue_inst:
|
|
|
|
second_xml, final_xml = guest.continue_install(dry=dry,
|
|
|
|
return_xml=True)
|
|
|
|
|
|
|
|
if dry and not (xmlonly or xmlstep):
|
|
|
|
print_stdout(_("Dry run completed successfully"))
|
|
|
|
return
|
|
|
|
|
|
|
|
# --print-xml
|
|
|
|
if xmlonly and not xmlstep:
|
|
|
|
if second_xml or final_xml:
|
|
|
|
fail(_("--print-xml can only be used with guests that do not have "
|
|
|
|
"an installation phase (--import, --boot, etc.). To see all"
|
|
|
|
" generated XML, please use --print-step all."))
|
|
|
|
return start_xml
|
|
|
|
|
|
|
|
# --print-step
|
|
|
|
if xmlstep == "1":
|
|
|
|
return start_xml
|
|
|
|
if xmlstep == "2":
|
|
|
|
if not (second_xml or final_xml):
|
|
|
|
fail(_("Requested installation does not have XML step 2"))
|
|
|
|
return second_xml or final_xml
|
|
|
|
if xmlstep == "3":
|
|
|
|
if not second_xml:
|
|
|
|
fail(_("Requested installation does not have XML step 3"))
|
|
|
|
return final_xml
|
|
|
|
|
|
|
|
# "all" case
|
|
|
|
xml = start_xml
|
|
|
|
if second_xml:
|
|
|
|
xml += second_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(
|
2014-01-19 06:01:43 +08:00
|
|
|
"%(prog)s --name NAME --ram RAM 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",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Installation source (eg, nfs:host:/path, "
|
|
|
|
"http://host/path, ftp://host/path)"))
|
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"))
|
2014-01-21 07:04:23 +08:00
|
|
|
insg.add_argument("--livecd", action="store_true",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("Treat the CD-ROM media as a Live CD"))
|
2014-01-21 07:04:23 +08:00
|
|
|
insg.add_argument("-x", "--extra-args",
|
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"))
|
2014-09-07 23:57:04 +08: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 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
|
|
|
|
|
|
|
|
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"))
|
|
|
|
virg.add_argument("-v", "--hvm", action="store_true", dest="fullvirt",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("This guest should be a fully virtualized guest"))
|
2014-01-21 07:04:23 +08:00
|
|
|
virg.add_argument("-p", "--paravirt", action="store_true",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("This guest should be a paravirtualized guest"))
|
2014-01-19 06:01:43 +08:00
|
|
|
virg.add_argument("--container", action="store_true", default=False,
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("This guest should be a container guest"))
|
2014-01-19 06:01:43 +08:00
|
|
|
virg.add_argument("--virt-type", dest="hv_type",
|
2013-03-18 05:06:52 +08:00
|
|
|
default="",
|
|
|
|
help=_("Hypervisor name to use (kvm, qemu, xen, ...)"))
|
2014-01-19 06:01:43 +08:00
|
|
|
virg.add_argument("--accelerate", action="store_true", default=False,
|
2014-01-21 07:04:23 +08:00
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
virg.add_argument("--arch",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("The CPU architecture to simulate"))
|
2014-01-21 07:04:23 +08:00
|
|
|
virg.add_argument("--machine",
|
2013-03-18 05:06:52 +08:00
|
|
|
help=_("The machine type to emulate"))
|
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"))
|
|
|
|
misc.add_argument("--autostart", action="store_true", dest="autostart",
|
2013-03-18 05:06:52 +08:00
|
|
|
default=False,
|
|
|
|
help=_("Have domain autostart on host boot up."))
|
2014-01-19 06:01:43 +08:00
|
|
|
misc.add_argument("--wait", type=int, dest="wait",
|
2013-09-28 23:27:26 +08:00
|
|
|
help=_("Minutes to wait for install to complete."))
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-01-19 06:01:43 +08:00
|
|
|
return parser.parse_args()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
# main() handling #
|
|
|
|
###################
|
|
|
|
|
|
|
|
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
|
|
|
|
options.quiet = options.xmlstep or options.xmlonly or options.quiet
|
|
|
|
|
|
|
|
cli.setupLogging("virt-install", options.debug, options.quiet)
|
|
|
|
|
2013-04-22 00:28:14 +08:00
|
|
|
check_cdrom_option_error(options)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
cli.set_force(options.force)
|
|
|
|
cli.set_prompt(options.prompt)
|
|
|
|
|
2014-01-22 22:06:35 +08:00
|
|
|
parsermap = cli.build_parser_map(options)
|
|
|
|
if cli.check_option_introspection(options, parsermap):
|
|
|
|
return 0
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
if conn is None:
|
|
|
|
conn = cli.getConnection(options.connect)
|
|
|
|
|
|
|
|
if options.xmlstep not in [None, "1", "2", "3", "all"]:
|
|
|
|
fail(_("--print-step must be 1, 2, 3, or all"))
|
|
|
|
|
2014-01-22 22:06:35 +08:00
|
|
|
guest = build_guest_instance(conn, options, parsermap)
|
2013-03-18 05:06:52 +08:00
|
|
|
continue_inst = guest.get_continue_inst()
|
|
|
|
|
|
|
|
if options.xmlstep or options.xmlonly or options.dry:
|
|
|
|
xml = xml_to_print(guest, continue_inst,
|
|
|
|
options.xmlonly, options.xmlstep, options.dry)
|
|
|
|
if xml:
|
|
|
|
print_stdout(xml, do_force=True)
|
|
|
|
else:
|
|
|
|
start_install(guest, continue_inst, options)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
sys.exit(main())
|
|
|
|
except SystemExit, sys_e:
|
|
|
|
sys.exit(sys_e.code)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
logging.debug("", exc_info=True)
|
|
|
|
print_stderr(_("Installation aborted at user request"))
|
|
|
|
except Exception, main_e:
|
|
|
|
fail(main_e)
|