2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 19:10:10 +00:00

Support console exit and dedicated console mode

Have confetty assume that a plain nodename is a requset for console.
If a console session is started from interactive mode, return to
interactive mode on ctrl-e, c, . rather than exiting.
This commit is contained in:
Jarrod Johnson 2014-02-10 18:28:45 -05:00
parent de06cb1c34
commit ca87aacaf2
2 changed files with 25 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import sys
import termios
import tty
consoleonly = False
target = "/"
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..'))
@ -83,6 +84,7 @@ def send_request(operation, path, server):
def do_command(command, server):
global target
global currconsole
global currchildren
if command == "": # result of ctrl-d
command = "exit\n"
@ -112,6 +114,7 @@ def do_command(command, server):
print item["href"]
if argv[0] == 'start':
targpath = fullpath_target(argv[1])
currconsole = targpath
tlvdata.send_tlvdata(server, {'operation': 'start', 'path': targpath})
status = tlvdata.recv_tlvdata(server)
if 'error' in status:
@ -151,10 +154,18 @@ def startconsole():
inconsole = True
def exit(code=0):
global consoleonly
global inconsole
global currconsole
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr)
server.shutdown(socket.SHUT_RDWR)
server.close()
sys.exit(code)
if consoleonly:
server.shutdown(socket.SHUT_RDWR)
server.close()
sys.exit(code)
else:
tlvdata.send_tlvdata(server, {'operation': 'stop', 'path': currconsole})
inconsole = False
prompt()
def conserver_command(fh, command):
while not command:
@ -249,6 +260,7 @@ doexit = False
inconsole = False
pendingcommand = ""
if len(args) == 1: # a node name, go straight to trying to console
consoleonly = True
do_command("start /node/%s/console/session" % args[0], server)
else:
prompt()
@ -256,6 +268,10 @@ while not doexit:
rdylist, _, _ = select.select((sys.stdin, server), (), (), 60)
for fh in rdylist:
if fh == server:
# this only should get called in the
# case of a console session
# each command should slurp up all relevant
# recv_tlvdata potential
#fh.read()
try:
data = tlvdata.recv_tlvdata(fh)

View File

@ -105,6 +105,12 @@ def process_request(connection, request, cfm, authdata):
ccons.startsending()
while consession is not None:
data = tlvdata.recv_tlvdata(connection)
if type(data) == dict:
if data['operation'] == 'stop':
consession.destroy()
return
else:
raise Exception("TODO")
if not data:
consession.destroy()
return