diff --git a/virt-convert b/virt-convert index be3acaba..bd1b9fa2 100755 --- a/virt-convert +++ b/virt-convert @@ -78,9 +78,8 @@ def parse_args(): ####################### def start_convert(guest, installer, options): - autoconsole = cli.parse_autoconsole(options.autoconsole) - if autoconsole.is_default(): - conscb = cli.get_console_cb(guest) + autoconsole = cli.parse_autoconsole(options, guest) + conscb = autoconsole.get_console_cb() print_stdout(_("Creating guest '%s'.") % guest.name) domain = installer.start_install(guest) cli.connect_console(guest, domain, conscb, True, False) diff --git a/virt-install b/virt-install index f7fb624f..fc0ab0ac 100755 --- a/virt-install +++ b/virt-install @@ -263,7 +263,7 @@ 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") - options.autoconsole = False + options.autoconsole = "none" options.wait = None @@ -319,18 +319,16 @@ def validate_required_options(options, guest, installer): fail(msg) -def show_console_warnings(options, guest, installer): - if guest.devices.graphics: +def show_console_warnings(installer, autoconsole): + if not installer.cdrom: return - if not options.autoconsole: + if not autoconsole.is_text(): return - - if installer.cdrom: - 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")) + 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")) def _show_memory_warnings(guest): @@ -633,18 +631,17 @@ class WaitHandler: def start_install(guest, installer, options): - show_console_warnings(options, guest, installer) - autoconsole = cli.parse_autoconsole(options.autoconsole) + autoconsole = cli.parse_autoconsole(options, guest) + show_console_warnings(installer, autoconsole) + conscb = autoconsole.get_console_cb() - conscb = None - if autoconsole.is_default(): - conscb = cli.get_console_cb(guest) - if 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 + 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 waithandler = WaitHandler(options.wait) meter = cli.get_meter() diff --git a/virtinst/cli.py b/virtinst/cli.py index 29d7eb46..2dae4097 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -393,8 +393,6 @@ def _gfx_console(guest, domain): if guest.has_gl() or guest.has_listen_none(): args.append("--attach") - log.debug("Launching virt-viewer for graphics type '%s'", - guest.devices.graphics[0].type) return _run_console(domain, args) @@ -403,7 +401,6 @@ def _txt_console(guest, domain): "--connect", guest.conn.uri, "console", guest.name] - log.debug("Connecting to text console") return _run_console(domain, args) @@ -430,33 +427,6 @@ def connect_console(guest, domain, consolecb, wait, destroy_on_exit): domain.destroy() -def get_console_cb(guest): - gdevs = guest.devices.graphics - if not gdevs: - return _txt_console - - gtype = gdevs[0].type - if gtype not in ["default", - DeviceGraphics.TYPE_VNC, - DeviceGraphics.TYPE_SPICE]: - log.debug("No viewer to launch for graphics type '%s'", gtype) - return - - if not HAS_VIRTVIEWER and not in_testsuite(): # pragma: no cover - log.warning(_("Unable to connect to graphical console: " - "virt-viewer not installed. Please install " - "the 'virt-viewer' package.")) - return None - - if (not os.environ.get("DISPLAY", "") and - not in_testsuite()): # pragma: no cover - log.warning(_("Graphics requested but DISPLAY is not set. " - "Not running virt-viewer.")) - return None - - return _gfx_console - - def get_meter(): import virtinst.progress quiet = (get_global_state().quiet or in_testsuite()) @@ -563,8 +533,8 @@ def add_misc_options(grp, prompt=False, replace=False, default=False, help=argparse.SUPPRESS) if noautoconsole: - grp.add_argument("--noautoconsole", action="store_false", - dest="autoconsole", default=True, + grp.add_argument("--noautoconsole", action="store_const", + dest="autoconsole", const="none", default="default", help=_("Don't automatically try to connect to the guest console")) if noreboot: @@ -1726,18 +1696,66 @@ def parse_os_variant(optstr): # --noautoconsole parsing # ########################### +def _determine_default_autoconsole_type(guest): + """ + Determine the default console for the passed guest config + + :returns: 'text', 'graphical', or None + """ + gdevs = guest.devices.graphics + if not gdevs: + return "text" + + gtype = gdevs[0].type + if gtype not in ["default", + DeviceGraphics.TYPE_VNC, + DeviceGraphics.TYPE_SPICE]: + log.debug("No viewer to launch for graphics type '%s'", gtype) + return None + + if not HAS_VIRTVIEWER and not in_testsuite(): # pragma: no cover + log.warning(_("Unable to connect to graphical console: " + "virt-viewer not installed. Please install " + "the 'virt-viewer' package.")) + return None + + if (not os.environ.get("DISPLAY", "") and + not in_testsuite()): # pragma: no cover + log.warning(_("Graphics requested but DISPLAY is not set. " + "Not running virt-viewer.")) + return None + + return "graphical" + + class _AutoconsoleData(object): - def __init__(self, autoconsole): + def __init__(self, autoconsole, guest): self._autoconsole = autoconsole + if self._autoconsole not in ["none", "default", "text", "graphical"]: + fail(_("Unknown autoconsole type '%s'") % self._autoconsole) - def is_none(self): - return self._autoconsole is False + self._is_default = self._autoconsole == "default" + if self._is_default: + default = _determine_default_autoconsole_type(guest) + self._autoconsole = default or "none" + + def is_text(self): + return self._autoconsole == "text" + def is_graphical(self): + return self._autoconsole == "graphical" def is_default(self): - return self._autoconsole is True + return self._is_default + + def get_console_cb(self): + if self.is_graphical(): + return _gfx_console + if self.is_text(): + return _txt_console + return None -def parse_autoconsole(optstr): - return _AutoconsoleData(optstr) +def parse_autoconsole(options, guest): + return _AutoconsoleData(options.autoconsole, guest) ######################