From aba749093b31707aa4938f774f5c1517e9f6f46f Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 7 Feb 2015 01:14:27 +0800 Subject: [PATCH] ctlmgr: get local bind address, format commands --- artiq/frontend/artiq_ctlmgr.py | 16 ++++++++++++++-- examples/ddb.pyon | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/artiq/frontend/artiq_ctlmgr.py b/artiq/frontend/artiq_ctlmgr.py index 100eae10b..74b2b5191 100755 --- a/artiq/frontend/artiq_ctlmgr.py +++ b/artiq/frontend/artiq_ctlmgr.py @@ -28,8 +28,15 @@ def get_argparser(): class Controllers: + def __init__(self): + self.host_filter = None + def __setitem__(self, k, v): - print("set {} {}".format(k, v)) + if (isinstance(v, dict) and v["type"] == "controller" + and v["host"] == self.host_filter): + command = v["command"].format(bind=self.host_filter, + port=v["port"]) + print("start controller {}: {}".format(k, command)) def __delitem__(self, k): print("del {}".format(k)) @@ -64,8 +71,13 @@ def main(): subscriber = Subscriber("devices", controller_db.sync_struct_init) while True: try: + def set_host_filter(): + s = subscriber.writer.get_extra_info("socket") + localhost = s.getsockname()[0] + controller_db.current_controllers.host_filter = localhost loop.run_until_complete( - subscriber.connect(args.server, args.port)) + subscriber.connect(args.server, args.port, + set_host_filter)) try: loop.run_until_complete(subscriber.receive_task) finally: diff --git a/examples/ddb.pyon b/examples/ddb.pyon index 4d55f30f1..4f666f7db 100644 --- a/examples/ddb.pyon +++ b/examples/ddb.pyon @@ -87,7 +87,7 @@ "host": "::1", "port": 3253, "target_name": "lda", - "command": "lda_controller -p {port} -d sim" + "command": "lda_controller -p {port} --bind {bind} -d sim" }, "pmt": "pmt0",