From 9e7d86d5cfdbf3e17f07d1eaca844abe818b0cd3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 8 Jan 2020 10:06:34 -0500 Subject: [PATCH] Use click.echo_via_pager for VM log output Addresses #67 --- client-cli/cli_lib/vm.py | 14 ++------------ client-cli/pvc.py | 6 ++++-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/client-cli/cli_lib/vm.py b/client-cli/cli_lib/vm.py index 54aed5b3..289e4576 100644 --- a/client-cli/cli_lib/vm.py +++ b/client-cli/cli_lib/vm.py @@ -311,7 +311,7 @@ def vm_locks(config, vm): def view_console_log(config, vm, lines=100): """ - Return console log lines from the API and display them in a pager + Return console log lines from the API (and display them in a pager in the main CLI) API endpoint: GET /vm/{vm}/console API arguments: lines={lines} @@ -334,17 +334,7 @@ def view_console_log(config, vm, lines=100): shrunk_log = console_log.split('\n')[-lines:] loglines = '\n'.join(shrunk_log) - # Show it in the pager (less) - try: - pager = subprocess.Popen(['less', '-R'], stdin=subprocess.PIPE) - pager.communicate(input=loglines.encode('utf8')) - except FileNotFoundError: - ainformation = list() - ainformation.append("Error: `less` pager not found, dumping log ({} lines) to stdout".format(lines)) - ainformation.append(loglines) - return False, '\n'.join(ainformation) - - return True, '' + return True, loglines def follow_console_log(config, vm, lines=10): """ diff --git a/client-cli/pvc.py b/client-cli/pvc.py index cf519226..366f1da2 100755 --- a/client-cli/pvc.py +++ b/client-cli/pvc.py @@ -779,7 +779,7 @@ def vm_flush_locks(domain): 'domain' ) @click.option( - '-l', '--lines', 'lines', default=100, show_default=True, + '-l', '--lines', 'lines', default=1000, show_default=True, help='Display this many log lines from the end of the log buffer.' ) @click.option( @@ -788,13 +788,15 @@ def vm_flush_locks(domain): ) def vm_log(domain, lines, follow): """ - Show console logs of virtual machine DOMAIN on its current node in the 'less' pager or continuously. DOMAIN may be a UUID or name. Note that migrating a VM to a different node will cause the log buffer to be overwritten by entries from the new node. + Show console logs of virtual machine DOMAIN on its current node in a pager or continuously. DOMAIN may be a UUID or name. Note that migrating a VM to a different node will cause the log buffer to be overwritten by entries from the new node. """ if follow: retcode, retmsg = pvc_vm.follow_console_log(config, domain, lines) else: retcode, retmsg = pvc_vm.view_console_log(config, domain, lines) + click.echo_via_pager(retmsg) + retmsg = '' cleanup(retcode, retmsg) ###############################################################################