cli: Expose default console handling through _AutoconsoleData
Rework all console queries to go through that object API Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
44c519200c
commit
85a33caa76
|
@ -78,9 +78,8 @@ def parse_args():
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
def start_convert(guest, installer, options):
|
def start_convert(guest, installer, options):
|
||||||
autoconsole = cli.parse_autoconsole(options.autoconsole)
|
autoconsole = cli.parse_autoconsole(options, guest)
|
||||||
if autoconsole.is_default():
|
conscb = autoconsole.get_console_cb()
|
||||||
conscb = cli.get_console_cb(guest)
|
|
||||||
print_stdout(_("Creating guest '%s'.") % guest.name)
|
print_stdout(_("Creating guest '%s'.") % guest.name)
|
||||||
domain = installer.start_install(guest)
|
domain = installer.start_install(guest)
|
||||||
cli.connect_console(guest, domain, conscb, True, False)
|
cli.connect_console(guest, domain, conscb, True, False)
|
||||||
|
|
41
virt-install
41
virt-install
|
@ -263,7 +263,7 @@ def convert_wait_zero(options):
|
||||||
# Historical back compat, --wait 0 is identical to --noautoconsole
|
# Historical back compat, --wait 0 is identical to --noautoconsole
|
||||||
if options.wait == 0:
|
if options.wait == 0:
|
||||||
log.warning("Treating --wait 0 as --noautoconsole")
|
log.warning("Treating --wait 0 as --noautoconsole")
|
||||||
options.autoconsole = False
|
options.autoconsole = "none"
|
||||||
options.wait = None
|
options.wait = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -319,18 +319,16 @@ def validate_required_options(options, guest, installer):
|
||||||
fail(msg)
|
fail(msg)
|
||||||
|
|
||||||
|
|
||||||
def show_console_warnings(options, guest, installer):
|
def show_console_warnings(installer, autoconsole):
|
||||||
if guest.devices.graphics:
|
if not installer.cdrom:
|
||||||
return
|
return
|
||||||
if not options.autoconsole:
|
if not autoconsole.is_text():
|
||||||
return
|
return
|
||||||
|
log.warning(_("CDROM media does not print to the text console "
|
||||||
if installer.cdrom:
|
"by default, so you likely will not see text install output. "
|
||||||
log.warning(_("CDROM media does not print to the text console "
|
"You might want to use --location.") + " " +
|
||||||
"by default, so you likely will not see text install output. "
|
_("See the man page for examples of "
|
||||||
"You might want to use --location.") + " " +
|
"using --location with CDROM media"))
|
||||||
_("See the man page for examples of "
|
|
||||||
"using --location with CDROM media"))
|
|
||||||
|
|
||||||
|
|
||||||
def _show_memory_warnings(guest):
|
def _show_memory_warnings(guest):
|
||||||
|
@ -633,18 +631,17 @@ class WaitHandler:
|
||||||
|
|
||||||
|
|
||||||
def start_install(guest, installer, options):
|
def start_install(guest, installer, options):
|
||||||
show_console_warnings(options, guest, installer)
|
autoconsole = cli.parse_autoconsole(options, guest)
|
||||||
autoconsole = cli.parse_autoconsole(options.autoconsole)
|
show_console_warnings(installer, autoconsole)
|
||||||
|
conscb = autoconsole.get_console_cb()
|
||||||
|
|
||||||
conscb = None
|
conscb = autoconsole.get_console_cb()
|
||||||
if autoconsole.is_default():
|
if autoconsole.is_default() and not conscb and options.wait is None:
|
||||||
conscb = cli.get_console_cb(guest)
|
# If there isn't any console to actually connect up,
|
||||||
if not conscb and options.wait is None:
|
# default to --wait -1 to get similarish behavior
|
||||||
# If there isn't any console to actually connect up,
|
log.warning(_("No console to launch for the guest, "
|
||||||
# default to --wait -1 to get similarish behavior
|
"defaulting to --wait -1"))
|
||||||
log.warning(_("No console to launch for the guest, "
|
options.wait = -1
|
||||||
"defaulting to --wait -1"))
|
|
||||||
options.wait = -1
|
|
||||||
|
|
||||||
waithandler = WaitHandler(options.wait)
|
waithandler = WaitHandler(options.wait)
|
||||||
meter = cli.get_meter()
|
meter = cli.get_meter()
|
||||||
|
|
|
@ -393,8 +393,6 @@ def _gfx_console(guest, domain):
|
||||||
if guest.has_gl() or guest.has_listen_none():
|
if guest.has_gl() or guest.has_listen_none():
|
||||||
args.append("--attach")
|
args.append("--attach")
|
||||||
|
|
||||||
log.debug("Launching virt-viewer for graphics type '%s'",
|
|
||||||
guest.devices.graphics[0].type)
|
|
||||||
return _run_console(domain, args)
|
return _run_console(domain, args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -403,7 +401,6 @@ def _txt_console(guest, domain):
|
||||||
"--connect", guest.conn.uri,
|
"--connect", guest.conn.uri,
|
||||||
"console", guest.name]
|
"console", guest.name]
|
||||||
|
|
||||||
log.debug("Connecting to text console")
|
|
||||||
return _run_console(domain, args)
|
return _run_console(domain, args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,33 +427,6 @@ def connect_console(guest, domain, consolecb, wait, destroy_on_exit):
|
||||||
domain.destroy()
|
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():
|
def get_meter():
|
||||||
import virtinst.progress
|
import virtinst.progress
|
||||||
quiet = (get_global_state().quiet or in_testsuite())
|
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)
|
default=False, help=argparse.SUPPRESS)
|
||||||
|
|
||||||
if noautoconsole:
|
if noautoconsole:
|
||||||
grp.add_argument("--noautoconsole", action="store_false",
|
grp.add_argument("--noautoconsole", action="store_const",
|
||||||
dest="autoconsole", default=True,
|
dest="autoconsole", const="none", default="default",
|
||||||
help=_("Don't automatically try to connect to the guest console"))
|
help=_("Don't automatically try to connect to the guest console"))
|
||||||
|
|
||||||
if noreboot:
|
if noreboot:
|
||||||
|
@ -1726,18 +1696,66 @@ def parse_os_variant(optstr):
|
||||||
# --noautoconsole parsing #
|
# --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):
|
class _AutoconsoleData(object):
|
||||||
def __init__(self, autoconsole):
|
def __init__(self, autoconsole, guest):
|
||||||
self._autoconsole = autoconsole
|
self._autoconsole = autoconsole
|
||||||
|
if self._autoconsole not in ["none", "default", "text", "graphical"]:
|
||||||
|
fail(_("Unknown autoconsole type '%s'") % self._autoconsole)
|
||||||
|
|
||||||
def is_none(self):
|
self._is_default = self._autoconsole == "default"
|
||||||
return self._autoconsole is False
|
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):
|
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):
|
def parse_autoconsole(options, guest):
|
||||||
return _AutoconsoleData(optstr)
|
return _AutoconsoleData(options.autoconsole, guest)
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
|
|
Loading…
Reference in New Issue