Commit 78f63cd4 authored by Swann Perarnau's avatar Swann Perarnau

[feature] Add stdout/stderr streaming

This patch adds stdout/stderr streaming capabilities, based on partial
evaluation of a tornado.iostream callback. The bin/cmd CLI is updated to
wait until an exit message, although that doesn't guaranty anything on
message ordering...

The next step is obviously to figure out a message flow that allows the
CLI to send and receive the command IO properly, in order...
parent 9afe59c7
......@@ -75,8 +75,9 @@ class CommandLineInterface(object):
# ignore other messages
if isinstance(msg, dict) and msg.get('type') == 'container':
if msg['uuid'] == containerid:
logger.info("container response: %r", msg)
break
logger.info("container msg: %r", msg)
if msg['event'] == 'exit':
break
def do_list(self, argv):
"""Connect to the NRM and ask to list the containers present on the
......
......@@ -2,6 +2,7 @@ from __future__ import print_function
from containers import ContainerManager
from resources import ResourceManager
from functools import partial
import json
import logging
import os
......@@ -129,6 +130,13 @@ class Daemon(object):
'pid': process.pid,
}
self.upstream_pub.send_json(update)
# setup io callbacks
process.stdout.read_until_close(partial(self.do_children_io,
msg['uuid'],
'stdout'))
process.stderr.read_until_close(partial(self.do_children_io,
msg['uuid'],
'stderr'))
elif command == 'kill':
logger.info("asked to kill container: %r", msg)
response = self.container_manager.kill(msg['uuid'])
......@@ -144,6 +152,18 @@ class Daemon(object):
else:
logger.error("invalid command: %r", command)
def do_children_io(self, uuid, io, data):
"""Receive data from one of the children, and send it down the pipe.
Meant to be partially defined on a children basis."""
logger.info("%r received %r data: %r", uuid, io, data)
update = {'type': 'container',
'event': io,
'uuid': uuid,
'payload': data or 'eof',
}
self.upstream_pub.send_json(update)
def do_sensor(self):
self.machine_info = self.sensor.do_update()
logger.info("current state: %r", self.machine_info)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment