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

[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

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,6 +50,30 @@ class CommandLineInterface(object): ...@@ -50,6 +50,30 @@ class CommandLineInterface(object):"client uuid: %r", self.uuid)"client uuid: %r", self.uuid)
def do_run(self, argv): def do_run(self, argv):
""" 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
# 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,
msg = self.upstream_sub_socket.recv_json()"new message: %r", msg)
# ignore other messages
if isinstance(msg, dict) and msg.get('type') == 'container':
if msg['uuid'] == containerid:
pass pass
def do_setpower(self, argv): def do_setpower(self, argv):
...@@ -85,7 +109,10 @@ class CommandLineInterface(object): ...@@ -85,7 +109,10 @@ class CommandLineInterface(object):
# run container # run container
parser_run = subparsers.add_parser("run") 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",
parser_run.set_defaults(func=self.do_run) parser_run.set_defaults(func=self.do_run)
# setpowerlimit # setpowerlimit
...@@ -99,12 +99,22 @@ class Daemon(object): ...@@ -99,12 +99,22 @@ class Daemon(object):
def do_upstream_receive(self, parts): def do_upstream_receive(self, parts):"receiving upstream message: %r", parts)"receiving upstream message: %r", parts)
if len(parts) != 1: 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 return
msg = json.loads(parts[0]) msg = json.loads(parts[0])
if isinstance(msg, dict) and msg.get('command') == 'setpower': 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)
if command == 'setpower': = float(msg['limit']) = float(msg['limit'])"new target measure: %g","new target measure: %g",
elif command == 'run':"new container required: %r", msg)
self.logger.error("invalid command: %r", command)
def do_sensor(self): def do_sensor(self):
self.machine_info = self.sensor.do_update() 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