def create(): dm = DockerManager(CONTAINER_PREFIX, update_stats=False) port = 6379 masterNum = 2 replicate = 1 configs = [] for i in range(masterNum + masterNum * replicate): conf = {} conf['host_config'] = dm.client.create_host_config(port_bindings={port: None}) conf['ports'] = [port] configs.append(conf) dm.add_containers(len(configs), 'redis', 'redis-server --appendonly yes --cluster-enabled yes --cluster-node-timeout 5000', configs, update_stats=False) masters = [] slaves = [] for _, c in dm.containers.items(): c.update_cache() if len(masters) < masterNum: masters.append(c.cache['ip']) else: slaves.append(c.cache['ip']) startup_nodes = [(m, port) for m in masters] print('Masters') print('\n'.join(masters)) command.start_cluster_on_multi(startup_nodes, max_slots=16384) print('Start cluster') slaveN = 0 for r in range(replicate): for m in masters: s = slaves[slaveN] command.join_cluster(m, port, s, port) print('Add slave: {}'.format(s)) slaveN += 1
import sys sys.path.append("../src") import sys from pprint import pprint from distrpy.utils.cluster import DockerManager CONTAINER_PREFIX = "distrpy_worker_" if __name__ == "__main__": dm = DockerManager(CONTAINER_PREFIX) port = 23000 configs = [] for i in range(1): worker_port = port + 1 host_port = port + i conf = {} conf["host_config"] = dm.client.create_host_config( binds={"/home/techteam/Distrpy/": {"bind": "/Distrpy", "mode": "ro"}}, port_bindings={worker_port: host_port}, mem_limit="500M", ) conf["working_dir"] = "/Distrpy/example" conf["volumes"] = ["/Distrpy"] conf["ports"] = [worker_port] configs.append(conf) dm.add_containers(len(configs), "distrpy/python", "python start_worker.py {}".format(host_port), configs) for n, c in dm.containers.items(): if n.startswith(CONTAINER_PREFIX):
def remove(): dm = DockerManager(CONTAINER_PREFIX, update_stats=False) dm.rm_all()
def stop(): dm = DockerManager(CONTAINER_PREFIX, update_stats=False) dm.stop_all()