Support providing console log lines from API

This commit is contained in:
2019-12-25 19:10:12 -05:00
parent 8a0a278fe9
commit 1f77b382ef
3 changed files with 74 additions and 8 deletions

View File

@ -564,19 +564,13 @@ def get_console_log(zk_conn, domain, lines=1000):
# Get the data from ZK
console_log = zkhandler.readdata(zk_conn, '/domains/{}/consolelog'.format(dom_uuid))
print(lines)
# Shrink the log buffer to length lines
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:
return False, 'ERROR: The "less" pager is required to view console logs.'
return True, ''
return True, loglines
def follow_console_log(zk_conn, domain, lines=10):
# Validate that VM exists in cluster