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

Further make the sockapi and confetty client fleshed out

Here, fix a few mistakes with how relation objects got messaged out.
Add the ability to cd and ls in the confetty interactive mode
This commit is contained in:
Jarrod Johnson 2014-02-09 19:26:48 -05:00
parent abab0e5cae
commit 5aa6e6a26c
3 changed files with 31 additions and 9 deletions

View File

@ -71,8 +71,19 @@ def parse_command(command):
args = shlex.split(command, posix=True)
return args
currchildren = None
def send_request(operation, path, server):
tlvdata.send_tlvdata(server, {'operation': operation, 'path': path})
result = tlvdata.recv_tlvdata(server)
while '_requestdone' not in result:
yield result
result = tlvdata.recv_tlvdata(server)
def do_command(command, server):
global target
global currchildren
if command == "": # result of ctrl-d
command = "exit\n"
print("exit")
@ -88,11 +99,19 @@ def do_command(command, server):
if argv[0] == "cd":
otarget = target
change_target(argv[1])
tlvdata.send_tlvdata(server, {"operation": 'retrieve', 'path': target})
result = tlvdata.recv_tlvdata(server)
if 'error' in result:
print target + ':' + result['error']
target = otarget
for res in send_request('retrieve', target, server):
if 'error' in res:
print target + ': ' + res['error']
target = otarget
if argv[0] in ('show', 'ls'):
for res in send_request('retrieve', target, server):
if type(res['item']) == dict:
print res['item']["href"]
else:
for item in res['item']:
print item["href"]

View File

@ -98,7 +98,7 @@ class LinkRelation(ConfluentMessage):
"""
return {self.rel: '{ "href": "%s" }' % self.href}
def raw_rel(self):
def raw(self):
"""Provide python structure of the relation.
This currently is only sensible to consume from httpapi.

View File

@ -61,8 +61,11 @@ def sessionhdl(connection, authname):
def send_response(responses, connection):
if responses is None:
return
for rsp in responses:
tlvdata.send_tlvdata(connection, json.dumps(rsp.json()))
tlvdata.send_tlvdata(connection, rsp.raw())
def process_request(connection, request, cfm, authdata):
#TODO(jbjohnso): authorize each request
@ -70,17 +73,17 @@ def process_request(connection, request, cfm, authdata):
operation = request['operation']
path = request['path']
params = request.get('parameters', None)
hdlr = None
try:
hdlr = pluginapi.handle_path(path, operation, cfm, params)
except exc.NotFoundException:
tlvdata.send_tlvdata(connection, {"errorcode": 404,
"error": "Target not found"})
return
except exc.InvalidArgumentException:
tlvdata.send_tlvdata(connection, {"errorcode": 400,
"error": "Bad Request"})
return
send_response(hdlr, connection)
tlvdata.send_tlvdata(connection, {'_requestdone': 1})
return
ccons = ClientConsole(connection)
consession = consoleserver.ConsoleSession(node='n4', configmanager=cfm,