diff options
author | khilman <khilman@users.noreply.github.com> | 2018-09-11 11:19:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-11 11:19:40 -0700 |
commit | 0d143406d41fcd7a4b03a3941cc3a66c294b21b2 (patch) | |
tree | 7593e9f148930f39479a2a5b6ea9bf49fcfd2732 /lavalab-gen.py | |
parent | 37566b908c442e1e27e1da5b24c384a78c20ca87 (diff) | |
parent | e010e54db9afbf8c7b1315ec6e998649f12a2558 (diff) |
Merge pull request #44 from montjoie/ser2net_multiconnections
Ser2net multiconnections
Diffstat (limited to 'lavalab-gen.py')
-rwxr-xr-x | lavalab-gen.py | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/lavalab-gen.py b/lavalab-gen.py index b327813..010839f 100755 --- a/lavalab-gen.py +++ b/lavalab-gen.py @@ -12,6 +12,8 @@ import shutil boards_yaml = "boards.yaml" tokens_yaml = "tokens.yaml" baud_default = 115200 +ser2net_port_start = 63001 +ser2net_ports = {} template_conmux = string.Template("""# # auto-generated by lavalab-gen.py for ${board} @@ -219,7 +221,7 @@ def main(): sys.exit(1) slaves = workers["slaves"] for slave in slaves: - keywords_slaves = [ "name", "host", "dispatcher_ip", "remote_user", "remote_master", "remote_address", "remote_rpc_port", "remote_proto", "extra_actions", "zmq_auth_key", "zmq_auth_key_secret", "default_slave" ] + keywords_slaves = [ "name", "host", "dispatcher_ip", "remote_user", "remote_master", "remote_address", "remote_rpc_port", "remote_proto", "extra_actions", "zmq_auth_key", "zmq_auth_key_secret", "default_slave", "export_ser2net" ] for keyword in slave: if not keyword in keywords_slaves: print("WARNING: unknown keyword %s" % keyword) @@ -326,7 +328,6 @@ def main(): if "boards" not in workers: print("Missing boards") sys.exit(1) - ser2net_port = 60000 boards = workers["boards"] for board in boards: board_name = board["name"] @@ -418,9 +419,14 @@ def main(): fp.write(conmuxline) fp.close() if use_ser2net: - ser2net_line = template_ser2net.substitute(port=ser2net_port,baud=baud,board=board_name) - device_line += template_device_ser2net.substitute(port=ser2net_port) - ser2net_port += 1 + if not worker_name in ser2net_ports: + ser2net_ports[worker_name] = ser2net_port_start + fp = open("%s/ser2net.conf" % workerdir, "a") + fp.write("DEFAULT:max-connections:10") + fp.close() + ser2net_line = template_ser2net.substitute(port=ser2net_ports[worker_name],baud=baud,board=board_name) + device_line += template_device_ser2net.substitute(port=ser2net_ports[worker_name]) + ser2net_ports[worker_name] += 1 fp = open("%s/ser2net.conf" % workerdir, "a") fp.write(ser2net_line) fp.close() @@ -453,6 +459,30 @@ def main(): fp.close() with open(dockcomposeymlpath, 'w') as f: yaml.dump(dockcomp, f) + #end for board + + for slave_name in ser2net_ports: + export_ser2net = False + for fs in workers["slaves"]: + if fs["name"] == slave_name: + if not "host" in fs: + host = "local" + else: + host = fs["host"] + if "export_ser2net" in fs: + export_ser2net = fs["export_ser2net"] + if not export_ser2net: + continue + print("Add ser2net ports for %s (%s) %s-%s" % (slave_name, host, ser2net_port_start, ser2net_ports[slave_name])) + dockcomposeymlpath = "output/%s/docker-compose.yml" % host + fp = open(dockcomposeymlpath, "r") + dockcomp = yaml.load(fp) + fp.close() + ser2net_port_max = ser2net_ports[slave_name] - 1 + dockcomp["services"][slave_name]["ports"].append("%s-%s:%s-%s" % (ser2net_port_start, ser2net_port_max, ser2net_port_start, ser2net_port_max)) + with open(dockcomposeymlpath, 'w') as f: + yaml.dump(dockcomp, f) + zmq_auth_genlist.close() if need_zmq_auth_gen: print("Gen ZMQ auth files") |