forked from M-Labs/artiq
1
0
Fork 0

ctlmgr: get local bind address, format commands

This commit is contained in:
Sebastien Bourdeauducq 2015-02-07 01:14:27 +08:00
parent 0d0a05a487
commit aba749093b
2 changed files with 15 additions and 3 deletions

View File

@ -28,8 +28,15 @@ def get_argparser():
class Controllers: class Controllers:
def __init__(self):
self.host_filter = None
def __setitem__(self, k, v): 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): def __delitem__(self, k):
print("del {}".format(k)) print("del {}".format(k))
@ -64,8 +71,13 @@ def main():
subscriber = Subscriber("devices", controller_db.sync_struct_init) subscriber = Subscriber("devices", controller_db.sync_struct_init)
while True: while True:
try: 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( loop.run_until_complete(
subscriber.connect(args.server, args.port)) subscriber.connect(args.server, args.port,
set_host_filter))
try: try:
loop.run_until_complete(subscriber.receive_task) loop.run_until_complete(subscriber.receive_task)
finally: finally:

View File

@ -87,7 +87,7 @@
"host": "::1", "host": "::1",
"port": 3253, "port": 3253,
"target_name": "lda", "target_name": "lda",
"command": "lda_controller -p {port} -d sim" "command": "lda_controller -p {port} --bind {bind} -d sim"
}, },
"pmt": "pmt0", "pmt": "pmt0",