2019-09-23 15:04:52 +00:00
|
|
|
#!/usr/bin/python2
|
2015-10-13 18:12:43 +00:00
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
|
|
|
# Copyright 2015 Lenovo
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import optparse
|
|
|
|
import os
|
2018-12-03 20:53:15 +00:00
|
|
|
import subprocess
|
2015-10-13 18:12:43 +00:00
|
|
|
import sys
|
2018-12-03 20:53:15 +00:00
|
|
|
path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
|
|
|
|
if path.startswith('/opt'):
|
|
|
|
sys.path.append(path)
|
|
|
|
import confluent.client as client
|
|
|
|
import confluent.sortutil as sortutil
|
2022-04-08 16:29:45 +00:00
|
|
|
import confluent.logreader as logreader
|
2015-10-13 18:12:43 +00:00
|
|
|
|
|
|
|
confettypath = os.path.join(os.path.dirname(sys.argv[0]), 'confetty')
|
|
|
|
argparser = optparse.OptionParser(
|
|
|
|
usage="Usage: %prog [options] node",
|
|
|
|
epilog="Command sequences are available while connected to a console, hit "
|
|
|
|
"ctrl-'e', then release ctrl, then 'c', then '?' for a full list. "
|
|
|
|
"For example, ctrl-'e', then 'c', then '.' will exit the current "
|
|
|
|
"console")
|
2018-12-03 20:53:15 +00:00
|
|
|
argparser.add_option('-t', '--tile', action='store_true', default=False,
|
|
|
|
help='Tile console windows in the terminal')
|
2022-04-08 16:29:45 +00:00
|
|
|
argparser.add_option('-l', '--log', action='store_true', default=False,
|
|
|
|
help='Enter log replay mode instead of showing a live console')
|
2015-10-13 18:12:43 +00:00
|
|
|
(options, args) = argparser.parse_args()
|
|
|
|
if len(args) != 1:
|
|
|
|
argparser.print_help()
|
|
|
|
sys.exit(1)
|
2022-04-08 16:29:45 +00:00
|
|
|
if options.log:
|
|
|
|
logname = args[0]
|
|
|
|
if not os.path.exists(logname) and logname[0] != '/':
|
|
|
|
logname = os.path.join('/var/log/confluent/consoles', logname)
|
|
|
|
if not os.path.exists(logname):
|
|
|
|
sys.stderr.write('Unable to locate {0} on local system\n'.format(logname))
|
|
|
|
sys.exit(1)
|
|
|
|
logreader.replay_to_console(logname)
|
|
|
|
sys.exit(0)
|
2018-12-03 20:53:15 +00:00
|
|
|
if options.tile:
|
2019-01-29 21:02:54 +00:00
|
|
|
null = open('/dev/null', 'w')
|
2018-12-03 20:53:15 +00:00
|
|
|
nodes = []
|
|
|
|
sess = client.Command()
|
|
|
|
for res in sess.read('/noderange/{0}/nodes/'.format(args[0])):
|
|
|
|
node = res.get('item', {}).get('href', '/').replace('/', '')
|
|
|
|
if not node:
|
|
|
|
sys.stderr.write(res.get('error', repr(res)) + '\n')
|
|
|
|
sys.exit(1)
|
|
|
|
nodes.append(node)
|
|
|
|
initial = True
|
|
|
|
pane = 0
|
2020-03-27 14:57:14 +00:00
|
|
|
sessname = 'nodeconsole_{0}'.format(os.getpid())
|
2018-12-03 20:53:15 +00:00
|
|
|
for node in sortutil.natural_sort(nodes):
|
2020-03-27 14:57:14 +00:00
|
|
|
panename = '{0}:{1}'.format(sessname, pane)
|
2018-12-03 20:53:15 +00:00
|
|
|
if initial:
|
|
|
|
initial = False
|
|
|
|
subprocess.call(
|
|
|
|
['tmux', 'new-session', '-d', '-s',
|
2020-03-27 14:57:14 +00:00
|
|
|
sessname, '-x', '800', '-y',
|
2018-12-03 20:53:15 +00:00
|
|
|
'800', '{0} -m 5 start /nodes/{1}/console/session'.format(
|
|
|
|
confettypath, node)])
|
|
|
|
else:
|
2020-03-27 14:57:14 +00:00
|
|
|
subprocess.call(['tmux', 'select-pane', '-t', sessname])
|
|
|
|
subprocess.call(['tmux', 'set-option', '-t', panename, 'pane-border-status', 'top'], stderr=null)
|
2018-12-03 20:53:15 +00:00
|
|
|
subprocess.call(
|
2020-03-27 14:57:14 +00:00
|
|
|
['tmux', 'split', '-h', '-t', sessname,
|
2018-12-03 20:53:15 +00:00
|
|
|
'{0} -m 5 start /nodes/{1}/console/session'.format(
|
|
|
|
confettypath, node)])
|
2020-03-27 14:57:14 +00:00
|
|
|
subprocess.call(['tmux', 'select-layout', '-t', sessname, 'tiled'], stdout=null)
|
|
|
|
pane += 1
|
|
|
|
subprocess.call(['tmux', 'select-pane', '-t', sessname])
|
|
|
|
subprocess.call(['tmux', 'set-option', '-t', panename, 'pane-border-status', 'top'], stderr=null)
|
|
|
|
os.execlp('tmux', 'tmux', 'attach', '-t', sessname)
|
2018-12-03 20:53:15 +00:00
|
|
|
else:
|
|
|
|
os.execl(confettypath, confettypath, 'start',
|
|
|
|
'/nodes/{0}/console/session'.format(args[0]))
|