Commit 5f6f9415 authored by Swann Perarnau's avatar Swann Perarnau

[feature] Add container run skeleton

This is the first step in a series of patches to integrate the container
launching code from Argus (globalos) into the NRM infrastructure.

This patch creates a valid command on the CLI, and sends the necessary
info to the NRM. We still need to take care of the actual container
creation.

Note that the CLI waits for an event indicating that the container was
launched, at that at this point the event is never generated by the NRM.
parent e9848601
......@@ -50,7 +50,31 @@ class CommandLineInterface(object):
self.logger.info("client uuid: %r", self.uuid)
def do_run(self, argv):
pass
""" Connect to the NRM and ask to spawn a container and run a command
in it.
The NRM should notify us on the pub socket of the container
creation."""
# build the command as a JSON dict containing enough info. We add to
# the command a container uuid as a way to make sure that we can make
# the command idempotent.
containerid = str(uuid.uuid4())
command = {'command': 'run',
'manifest': argv.manifest,
'file': argv.command,
'args': argv.args,
'uuid': containerid,
}
while(True):
self.upstream_pub_socket.send_json(command)
msg = self.upstream_sub_socket.recv_json()
self.logger.info("new message: %r", msg)
# ignore other messages
if isinstance(msg, dict) and msg.get('type') == 'container':
if msg['uuid'] == containerid:
pass
def do_setpower(self, argv):
""" Connect to the NRM and ask to change the power limit.
......@@ -85,7 +109,10 @@ class CommandLineInterface(object):
# run container
parser_run = subparsers.add_parser("run")
parser_run.add_argument("container")
parser_run.add_argument("manifest", help="manifest file to apply")
parser_run.add_argument("command", help="command to execute")
parser_run.add_argument("args", help="command arguments",
nargs=argparse.REMAINDER)
parser_run.set_defaults(func=self.do_run)
# setpowerlimit
......
......@@ -99,12 +99,22 @@ class Daemon(object):
def do_upstream_receive(self, parts):
self.logger.info("receiving upstream message: %r", parts)
if len(parts) != 1:
self.logger.error("unexpected msg length, droping it: %r", parts)
self.logger.error("unexpected msg length, dropping it: %r", parts)
return
msg = json.loads(parts[0])
if isinstance(msg, dict) and msg.get('command') == 'setpower':
self.target = float(msg['limit'])
self.logger.info("new target measure: %g", self.target)
if isinstance(msg, dict):
command = msg.get('command')
# TODO: switch to a dispatch dictionary
if command is None:
self.logger.error("missing command in message: %r", msg)
return
if command == 'setpower':
self.target = float(msg['limit'])
self.logger.info("new target measure: %g", self.target)
elif command == 'run':
self.logger.info("new container required: %r", msg)
else:
self.logger.error("invalid command: %r", command)
def do_sensor(self):
self.machine_info = self.sensor.do_update()
......
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