From 44c519200c8db61a7ae8c06259f5d69a3383d4c8 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 24 Nov 2019 17:40:27 -0500 Subject: [PATCH] cli: Add _AutoconsoleData and use it This will be expanded later to track explicit requests for certain console types Signed-off-by: Cole Robinson --- virt-convert | 18 ++++++++++-------- virt-install | 3 ++- virtinst/cli.py | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/virt-convert b/virt-convert index df7fa844..be3acaba 100755 --- a/virt-convert +++ b/virt-convert @@ -77,6 +77,15 @@ def parse_args(): # Functional handlers # ####################### +def start_convert(guest, installer, options): + autoconsole = cli.parse_autoconsole(options.autoconsole) + if autoconsole.is_default(): + conscb = cli.get_console_cb(guest) + print_stdout(_("Creating guest '%s'.") % guest.name) + domain = installer.start_install(guest) + cli.connect_console(guest, domain, conscb, True, False) + + def main(conn=None): cli.earlyLogging() options = parse_args() @@ -86,7 +95,6 @@ def main(conn=None): if options.xmlonly: options.dry = True options.quiet = True - options.autoconsole = False print_cb = print_stdout if options.quiet: @@ -102,17 +110,11 @@ def main(conn=None): installer = Installer(guest.conn) installer.set_install_defaults(guest) - conscb = None - if options.autoconsole: - conscb = cli.get_console_cb(guest) or None - if options.xmlonly: print_stdout(installer.start_install(guest, return_xml=True)[1], do_force=True) elif not options.dry or cli.in_testsuite(): - print_stdout(_("Creating guest '%s'.") % guest.name) - domain = installer.start_install(guest) - cli.connect_console(guest, domain, conscb, True, False) + start_convert(guest, installer, options) except Exception: # pragma: no cover converter.cleanup() raise diff --git a/virt-install b/virt-install index a51c78e4..f7fb624f 100755 --- a/virt-install +++ b/virt-install @@ -634,9 +634,10 @@ class WaitHandler: def start_install(guest, installer, options): show_console_warnings(options, guest, installer) + autoconsole = cli.parse_autoconsole(options.autoconsole) conscb = None - if options.autoconsole: + 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, diff --git a/virtinst/cli.py b/virtinst/cli.py index f7170600..29d7eb46 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1722,6 +1722,24 @@ def parse_os_variant(optstr): return OSVariantData(optstr) +########################### +# --noautoconsole parsing # +########################### + +class _AutoconsoleData(object): + def __init__(self, autoconsole): + self._autoconsole = autoconsole + + def is_none(self): + return self._autoconsole is False + def is_default(self): + return self._autoconsole is True + + +def parse_autoconsole(optstr): + return _AutoconsoleData(optstr) + + ###################### # --metadata parsing # ######################