def __remove(self, state, containers=[], force=False, time=docker.DOCKER_STOP_TIME): logger.debug("REMOVE %s" % containers) ops = [] for container in containers: if container in state: if state[container].running: if not force: logger.error( "'%s' is running and 'force' was not specified." % container) else: op = docker.stop(container, time=time) \ .then(defer(docker.remove, container=container)) \ .then(dinfo("'%s' has been stopped and removed." % container)) \ .then(defer(self.clearPid, container=container)) ops.append(op) else: ops.append( docker.remove(container).bind( dinfo("'%s' has been removed." % container))) return Try.sequence(ops)
def __stop(self, state, containers=[], time=docker.DOCKER_STOP_TIME): ops = [] for container in containers: if container not in state: logger.warn("Container '%s' does not exist." % container) else: if state[container].running: op = docker.stop(container, time) \ .then(dinfo("'%s' has been stopped." % container)) \ .then(defer(self.clearPid, container=container)) else: logger.warn("'%s' is not running." % container) return Try.sequence(ops)
def __restart(self, state, containers=[], time=docker.DOCKER_STOP_TIME): ops = [] for container in containers: if container not in state: logger.error("'%s' does not exist." % container) else: if state[container].running: op = docker.stop(container, time=time) \ .then(defer(docker.start, container=container)) \ .then(dinfo("'%s' has been restarted." % container)) \ .then(defer(self.writePid, container=container)) ops.append(op) else: ops.append(docker.start(container) .then(dinfo("'%s' has been started." % container))) \ .then(defer(self.writePid, container=container)) return Try.sequence(ops)