mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-25 19:10:10 +00:00
Add 'start /node/<node>/console/session' to confetty
This commit is contained in:
parent
b2d54bf2f5
commit
563a96f87f
36
bin/confetty
36
bin/confetty
@ -98,7 +98,7 @@ def do_command(command, server):
|
||||
sys.exit(0)
|
||||
if argv[0] == "cd":
|
||||
otarget = target
|
||||
change_target(argv[1])
|
||||
target = fullpath_target(argv[1])
|
||||
for res in send_request('retrieve', target, server):
|
||||
if 'error' in res:
|
||||
print target + ': ' + res['error']
|
||||
@ -110,19 +110,24 @@ def do_command(command, server):
|
||||
else:
|
||||
for item in res['item']:
|
||||
print item["href"]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if argv[0] == 'start':
|
||||
targpath = fullpath_target(argv[1])
|
||||
tlvdata.send_tlvdata(server, {'operation': 'start', 'path': targpath})
|
||||
status = tlvdata.recv_tlvdata(server)
|
||||
if 'error' in status:
|
||||
print 'Error: ' + status['error']
|
||||
return
|
||||
print '[console session started]'
|
||||
startconsole()
|
||||
return
|
||||
prompt()
|
||||
|
||||
|
||||
def change_target(path):
|
||||
def fullpath_target(path):
|
||||
global target
|
||||
pathcomponents = path.split("/")
|
||||
if pathcomponents[0] == "": # absolute path
|
||||
target = path
|
||||
ntarget = path
|
||||
else:
|
||||
targparts = target.split("/")[:-1]
|
||||
for component in pathcomponents:
|
||||
@ -134,13 +139,16 @@ def change_target(path):
|
||||
else:
|
||||
targparts.append(component)
|
||||
targparts.append('')
|
||||
target = '/'.join(targparts)
|
||||
if len(target) ==0 or target[-1] != '/':
|
||||
target += '/'
|
||||
ntarget = '/'.join(targparts)
|
||||
if len(ntarget) ==0 or ntarget[-1] != '/':
|
||||
ntarget += '/'
|
||||
return ntarget
|
||||
|
||||
def startconsole():
|
||||
global inconsole
|
||||
tty.setraw(sys.stdin.fileno())
|
||||
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
|
||||
inconsole = True
|
||||
|
||||
def exit(code=0):
|
||||
termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr)
|
||||
@ -250,6 +258,9 @@ while not doexit:
|
||||
data = tlvdata.recv_tlvdata(fh)
|
||||
except Exception:
|
||||
data = None
|
||||
if type(data) == dict:
|
||||
print repr(data)
|
||||
continue
|
||||
if data is not None:
|
||||
sys.stdout.write(data)
|
||||
sys.stdout.flush()
|
||||
@ -265,6 +276,5 @@ while not doexit:
|
||||
tlvdata.send_tlvdata(server, input)
|
||||
else:
|
||||
command = fh.readline()
|
||||
inconsole = do_command(command, server)
|
||||
|
||||
do_command(command, server)
|
||||
exit()
|
||||
|
@ -23,11 +23,23 @@ SO_PEERCRED = 17
|
||||
|
||||
class ClientConsole(object):
|
||||
def __init__(self, client):
|
||||
self.client = clientn
|
||||
self.client = client
|
||||
self.xmit = False
|
||||
self.pendingdata = ""
|
||||
|
||||
def sendall(self, data):
|
||||
if not self.xmit:
|
||||
self.pendingdata += data
|
||||
return
|
||||
tlvdata.send_tlvdata(self.client, data)
|
||||
|
||||
def startsending(self):
|
||||
self.xmit = True
|
||||
if self.pendingdata != "":
|
||||
tlvdata.send_tlvdata(self.client, self.pendingdata)
|
||||
self.pendingdata = None
|
||||
|
||||
|
||||
def sessionhdl(connection, authname):
|
||||
# For now, trying to test the console stuff, so let's just do n4.
|
||||
authenticated = False
|
||||
@ -65,6 +77,7 @@ def send_response(responses, connection):
|
||||
return
|
||||
for rsp in responses:
|
||||
tlvdata.send_tlvdata(connection, rsp.raw())
|
||||
tlvdata.send_tlvdata(connection, {'_requestdone': 1})
|
||||
|
||||
|
||||
def process_request(connection, request, cfm, authdata):
|
||||
@ -75,25 +88,37 @@ def process_request(connection, request, cfm, authdata):
|
||||
params = request.get('parameters', None)
|
||||
hdlr = None
|
||||
try:
|
||||
hdlr = pluginapi.handle_path(path, operation, cfm, params)
|
||||
if operation == 'start':
|
||||
elems = path.split('/')
|
||||
if elems[3] != "console":
|
||||
raise exc.InvalidArgumentException()
|
||||
node = elems[2]
|
||||
ccons = ClientConsole(connection)
|
||||
consession = consoleserver.ConsoleSession(
|
||||
node=node, configmanager=cfm, datacallback=ccons.sendall)
|
||||
if consession is None:
|
||||
raise Exception("TODO")
|
||||
tlvdata.send_tlvdata(connection, {'started': 1})
|
||||
ccons.startsending()
|
||||
while consession is not None:
|
||||
data = tlvdata.recv_tlvdata(connection)
|
||||
if not data:
|
||||
consession.destroy()
|
||||
return
|
||||
consession.write(data)
|
||||
else:
|
||||
hdlr = pluginapi.handle_path(path, operation, cfm, params)
|
||||
except exc.NotFoundException:
|
||||
tlvdata.send_tlvdata(connection, {"errorcode": 404,
|
||||
"error": "Target not found"})
|
||||
tlvdata.send_tlvdata(connection, {"_requestdone": 1})
|
||||
except exc.InvalidArgumentException:
|
||||
tlvdata.send_tlvdata(connection, {"errorcode": 400,
|
||||
"error": "Bad Request"})
|
||||
"error": "Bad Request",
|
||||
"_requestdone": 1})
|
||||
tlvdata.send_tlvdata(connection, {"_requestdone": 1})
|
||||
send_response(hdlr, connection)
|
||||
tlvdata.send_tlvdata(connection, {'_requestdone': 1})
|
||||
return
|
||||
ccons = ClientConsole(connection)
|
||||
consession = consoleserver.ConsoleSession(node='n4', configmanager=cfm,
|
||||
datacallback=ccons.sendall)
|
||||
while (1):
|
||||
data = tlvdata.recv_tlvdata(connection)
|
||||
if not data:
|
||||
consession.destroy()
|
||||
return
|
||||
consession.write(data)
|
||||
|
||||
|
||||
def _tlshandler():
|
||||
|
Loading…
Reference in New Issue
Block a user