diff --git a/confluent/console.py b/confluent/console.py new file mode 100644 index 00000000..84e20b54 --- /dev/null +++ b/confluent/console.py @@ -0,0 +1,84 @@ +# Copyright 2013 IBM Corporation +# All rights reserved + +# This is the common console support for confluent. It takes over +# whatever filehandle is conversing with the client and starts +# relaying data. It uses Ctrl-] like telnet for escape back to prompt + +#we track nodes that are actively being logged, watched, or have attached +#there should be no more than one handler per node +import confluent.pluginapi as plugin +_handled_consoles = {} + +class _ConsoleHandler(object): + def __init__(self, node, configmanager): + self._console = plugin.handle_path("/node/%s/_console/session" % node, + "create", configmanager) + self._console.connect(self.get_console_output) + + def get_console_output(self, data): + #TODO: logging, forwarding, etc + print "huzzah" + print data + +#this represents some api view of a console handler. This handles things like +#holding the caller specific queue data, for example, when http api should be +#sending data, but there is no outstanding POST request to hold it, +# this object has the job of halding the data +class ConsoleSession(object): + """Create a new socket to converse with node console + + This object provides a filehandle that can be read/written + too in a normal fashion and the concurrency, logging, and + event watching will all be handled seamlessly + + :param node: Name of the node for which this session will be created + """ + + def __init__(self, node, configmanager): + if node not in _handled_consoles: + _handled_consoles[node] = _ConsoleHandler(node, configmanager) + pass + # TODO(jbjohnso): actually do the cool stuff + + +def handle_request(request=None, connection=None, releaseconnection=False): + """ + Process a request from confluent. + + :param request: For 'datagram' style console, this represents a wait for + data or input. + :param connection: For socket style console, this is a read/write socket + that the caller has released from it's control and + console plugin will do all IO + :param releaseconnection: A function for console to call to indicate confluent + should resume control over the connection + + """ + if request is not None: # This is indicative of http style + pass # TODO(jbjohnso): support AJAX style interaction. + # a web ui looking to actually take advantage will + # probably have to pull in the GPL javascript + # from shellinabox or something similar + # the way that works is URI encoded input with width, heiht, + # session or rooturl:opening + # opening session + # width=120&height=24&rooturl=/nodes/n1/console/session + # making a request to wait for data: + # width=120&height=24&session=blahblahblah + # : + # width=120&height=24&session=blahblahblah&keys=0D + # pasting 'rabbit' + # width=120&height=24&session=blahblah&keys=726162626974 + # if no client session indicated, it expects some session number + # in return. + # the responses: + # : (the session seems to be opaque + # {"session":"h5lrOKViIeQGp1nXjKWpAQ","data":""} + # + # {"session":"blah","data":"\r\n\u001B]0;bob@thor:~\u0007[bob@thor ~]$ "} + #