mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 19:28:26 +08:00
master/client: remote management of dpdb
This commit is contained in:
parent
7ada30e07a
commit
a073a7e055
@ -3,12 +3,15 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import sys
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
|
|
||||||
from artiq.management.pc_rpc import Client
|
from artiq.management.pc_rpc import Client
|
||||||
from artiq.management.sync_struct import Subscriber
|
from artiq.management.sync_struct import Subscriber
|
||||||
from artiq.management.tools import clear_screen
|
from artiq.management.tools import clear_screen
|
||||||
|
from artiq.management import pyon
|
||||||
|
|
||||||
|
|
||||||
def _get_args():
|
def _get_args():
|
||||||
@ -44,11 +47,31 @@ def _get_args():
|
|||||||
parser_cancel.add_argument("rid", type=int,
|
parser_cancel.add_argument("rid", type=int,
|
||||||
help="run identifier (RID/PRID)")
|
help="run identifier (RID/PRID)")
|
||||||
|
|
||||||
parser_show_queue = subparsers.add_parser(
|
parser_set_device = subparsers.add_parser(
|
||||||
"show-queue", help="show the experiment queue")
|
"set-device", help="add or modify a device")
|
||||||
|
parser_set_device.add_argument("name", help="name of the device")
|
||||||
|
parser_set_device.add_argument("description",
|
||||||
|
help="description in PYON format")
|
||||||
|
|
||||||
parser_show_periodic = subparsers.add_parser(
|
parser_del_device = subparsers.add_parser(
|
||||||
"show-periodic", help="show the periodic experiment table")
|
"del-device", help="delete a device")
|
||||||
|
parser_del_device.add_argument("name", help="name of the device")
|
||||||
|
|
||||||
|
parser_set_parameter = subparsers.add_parser(
|
||||||
|
"set-parameter", help="add or modify a parameter")
|
||||||
|
parser_set_parameter.add_argument("name", help="name of the parameter")
|
||||||
|
parser_set_parameter.add_argument("value",
|
||||||
|
help="value in PYON format")
|
||||||
|
|
||||||
|
parser_del_parameter = subparsers.add_parser(
|
||||||
|
"del-parameter", help="delete a parameter")
|
||||||
|
parser_del_parameter.add_argument("name", help="name of the parameter")
|
||||||
|
|
||||||
|
parser_show = subparsers.add_parser(
|
||||||
|
"show", help="show schedule, devices or parameters")
|
||||||
|
parser_show.add_argument(
|
||||||
|
"what",
|
||||||
|
help="select object to show: queue/periodic/devices/parameters")
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -75,6 +98,22 @@ def _action_cancel(remote, args):
|
|||||||
remote.cancel_once(args.rid)
|
remote.cancel_once(args.rid)
|
||||||
|
|
||||||
|
|
||||||
|
def _action_set_device(remote, args):
|
||||||
|
remote.set_device(args.name, pyon.decode(args.description))
|
||||||
|
|
||||||
|
|
||||||
|
def _action_del_device(remote, args):
|
||||||
|
remote.del_device(args.name)
|
||||||
|
|
||||||
|
|
||||||
|
def _action_set_parameter(remote, args):
|
||||||
|
remote.set_parameter(args.name, pyon.decode(args.value))
|
||||||
|
|
||||||
|
|
||||||
|
def _action_del_parameter(remote, args):
|
||||||
|
remote.del_parameter(args.name)
|
||||||
|
|
||||||
|
|
||||||
def _show_queue(queue):
|
def _show_queue(queue):
|
||||||
clear_screen()
|
clear_screen()
|
||||||
if queue:
|
if queue:
|
||||||
@ -107,6 +146,23 @@ def _show_periodic(periodic):
|
|||||||
print("No periodic schedule")
|
print("No periodic schedule")
|
||||||
|
|
||||||
|
|
||||||
|
def _show_devices(devices):
|
||||||
|
clear_screen()
|
||||||
|
table = PrettyTable(["Name", "Description"])
|
||||||
|
table.align["Description"] = "l"
|
||||||
|
for k, v in sorted(devices.items(), key=itemgetter(0)):
|
||||||
|
table.add_row([k, pyon.encode(v, True)])
|
||||||
|
print(table)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_parameters(parameters):
|
||||||
|
clear_screen()
|
||||||
|
table = PrettyTable(["Parameter", "Value"])
|
||||||
|
for k, v in sorted(parameters.items(), key=itemgetter(0)):
|
||||||
|
table.add_row([k, str(v)])
|
||||||
|
print(table)
|
||||||
|
|
||||||
|
|
||||||
def _run_subscriber(host, port, subscriber):
|
def _run_subscriber(host, port, subscriber):
|
||||||
if port is None:
|
if port is None:
|
||||||
port = 8887
|
port = 8887
|
||||||
@ -123,30 +179,51 @@ def _run_subscriber(host, port, subscriber):
|
|||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
||||||
|
def _show_list(args, notifier_name, display_fun):
|
||||||
|
l = []
|
||||||
|
def init_l(x):
|
||||||
|
l[:] = x
|
||||||
|
return l
|
||||||
|
subscriber = Subscriber(notifier_name, init_l,
|
||||||
|
lambda: display_fun(l))
|
||||||
|
_run_subscriber(args.server, args.port, subscriber)
|
||||||
|
|
||||||
|
|
||||||
|
def _show_dict(args, notifier_name, display_fun):
|
||||||
|
d = dict()
|
||||||
|
def init_d(x):
|
||||||
|
d.clear()
|
||||||
|
d.update(x)
|
||||||
|
return d
|
||||||
|
subscriber = Subscriber(notifier_name, init_d,
|
||||||
|
lambda: display_fun(d))
|
||||||
|
_run_subscriber(args.server, args.port, subscriber)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = _get_args()
|
args = _get_args()
|
||||||
if args.action == "show-queue":
|
action = args.action.replace("-", "_")
|
||||||
queue = []
|
if action == "show":
|
||||||
def init_queue(x):
|
if args.what == "queue":
|
||||||
queue[:] = x
|
_show_list(args, "queue", _show_queue)
|
||||||
return queue
|
elif args.what == "periodic":
|
||||||
subscriber = Subscriber("queue", init_queue,
|
_show_dict(args, "periodic", _show_periodic)
|
||||||
lambda: _show_queue(queue))
|
elif args.what == "devices":
|
||||||
_run_subscriber(args.server, args.port, subscriber)
|
_show_dict(args, "devices", _show_devices)
|
||||||
elif args.action == "show-periodic":
|
elif args.what == "parameters":
|
||||||
periodic = dict()
|
_show_dict(args, "parameters", _show_parameters)
|
||||||
def init_periodic(x):
|
else:
|
||||||
periodic.clear()
|
print("Unknown object to show, use -h to list valid names.")
|
||||||
periodic.update(x)
|
sys.exit(1)
|
||||||
return periodic
|
|
||||||
subscriber = Subscriber("periodic", init_periodic,
|
|
||||||
lambda: _show_periodic(periodic))
|
|
||||||
_run_subscriber(args.server, args.port, subscriber)
|
|
||||||
else:
|
else:
|
||||||
port = 8888 if args.port is None else args.port
|
port = 8888 if args.port is None else args.port
|
||||||
remote = Client(args.server, port, "master_schedule")
|
if action in ("submit", "cancel"):
|
||||||
|
target_name = "master_schedule"
|
||||||
|
else:
|
||||||
|
target_name = "master_dpdb"
|
||||||
|
remote = Client(args.server, port, target_name)
|
||||||
try:
|
try:
|
||||||
globals()["_action_" + args.action](remote, args)
|
globals()["_action_" + action](remote, args)
|
||||||
finally:
|
finally:
|
||||||
remote.close_rpc()
|
remote.close_rpc()
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ def main():
|
|||||||
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
||||||
|
|
||||||
server_control = Server({
|
server_control = Server({
|
||||||
"master_schedule": scheduler
|
"master_schedule": scheduler,
|
||||||
|
"master_dpdb": dpdb
|
||||||
})
|
})
|
||||||
loop.run_until_complete(server_control.start(
|
loop.run_until_complete(server_control.start(
|
||||||
args.bind, args.port_control))
|
args.bind, args.port_control))
|
||||||
@ -47,7 +48,9 @@ def main():
|
|||||||
|
|
||||||
server_notify = Publisher({
|
server_notify = Publisher({
|
||||||
"queue": scheduler.queue,
|
"queue": scheduler.queue,
|
||||||
"periodic": scheduler.periodic
|
"periodic": scheduler.periodic,
|
||||||
|
"devices": dpdb.ddb,
|
||||||
|
"parameters": dpdb.pdb
|
||||||
})
|
})
|
||||||
loop.run_until_complete(server_notify.start(
|
loop.run_until_complete(server_notify.start(
|
||||||
args.bind, args.port_notify))
|
args.bind, args.port_notify))
|
||||||
|
Loading…
Reference in New Issue
Block a user