Commit 9afe59c7 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] Fix container namedtuple

This patch propagates the process object into the container namedtuple,
fix a couple of bad function calls and adapt the run command handler to
use that process object instead of just the pid of it.
parent edeb413b
......@@ -4,11 +4,10 @@ from aci import ImageManifest
from collections import namedtuple
import logging
import os
import signal
from subprograms import ChrtClient, NodeOSClient, resources
logger = logging.getLogger('nrm')
Container = namedtuple('Container', ['uuid', 'manifest', 'pid'])
Container = namedtuple('Container', ['uuid', 'manifest', 'process'])
class ContainerManager(object):
......@@ -72,7 +71,7 @@ class ContainerManager(object):
c = Container(container_name, manifest, process)
self.pids[process.pid] = c
self.containers[container_name] = c
return process.pid
return process
def delete(self, uuid):
"""Delete a container and kill all related processes."""
......@@ -80,7 +79,7 @@ class ContainerManager(object):
self.resourcemanager.update(uuid)
c = self.containers[uuid]
del self.containers[uuid]
del self.pids[c.pid.pid]
del self.pids[c.process.pid]
def kill(self, uuid):
"""Kill all the processes of a container."""
......@@ -88,11 +87,11 @@ class ContainerManager(object):
c = self.containers[uuid]
logger.debug("killing %r:", c)
try:
c.pid.terminate()
c.process.proc.terminate()
except OSError:
pass
def list(self):
"""List the containers in the system."""
return [{'uuid': c.uuid, 'pid': c.pid.pid} for c in
return [{'uuid': c.uuid, 'pid': c.process.pid} for c in
self.containers.values()]
......@@ -119,24 +119,16 @@ class Daemon(object):
logger.info("new target measure: %g", self.target)
elif command == 'run':
logger.info("new container required: %r", msg)
pid = self.container_manager.create(msg)
if pid > 0:
self.containerpids[pid] = msg['uuid']
# TODO: obviously we need to send more info than that
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': 0,
'pid': pid,
}
self.upstream_pub.send_json(update)
else:
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': pid,
}
self.upstream_pub.send_json(update)
process = self.container_manager.create(msg)
self.containerpids[process.pid] = msg['uuid']
# TODO: obviously we need to send more info than that
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': 0,
'pid': process.pid,
}
self.upstream_pub.send_json(update)
elif command == 'kill':
logger.info("asked to kill container: %r", msg)
response = self.container_manager.kill(msg['uuid'])
......
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