async def command(rq, host, port, domain, family, member, cmd): """ Display device command info """ if rq.method == "PUT": raise HTTP501_NotImplemented device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) info = proxy.get_command_config(cmd) return json({ "name": cmd, "info": { "cmd_name": info.cmd_name, "cmd_tag": info.cmd_tag, "level": str(info.disp_level), "in_type": str(info.in_type), "out_type": str(info.out_type), "in_type_desc": info.in_type_desc, "out_type_desc": info.out_type_desc }, "history": buildurl(rq, "rc3.command_history", tango_host, device, cmd=cmd), "_links": { "_self": buildurl(rq, "rc3.command", tango_host, device, cmd=cmd) } })
async def commands(rq, host, port, domain, family, member): """ List of device commands """ device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) cmds = proxy.get_command_list() cmds_w_info = [] for cmd in cmds: info = proxy.get_command_config(cmd) cmds_w_info.append({ "name": cmd, "info": { "cmd_name": info.cmd_name, "cmd_tag": info.cmd_tag, "level": str(info.disp_level), "in_type": str(info.in_type), "out_type": str(info.out_type), "in_type_desc": info.in_type_desc, "out_type_desc": info.out_type_desc }, "history": buildurl(rq, "rc3.command_history", tango_host, device, cmd=cmd), "_links": { "_self": buildurl(rq, "rc3.commands", tango_host, device) } }) return json(cmds_w_info)
async def db_info(rq, host, port): """ Database information """ info = db.get_info() return json({ "name": info.split()[2], "host": db.get_db_host(), "port": db.get_db_port_num(), "info": info.split("\n"), "devices": buildurl(rq, "rc3.devices", tango_host) })
async def pipes(rq, host, port, domain, family, member): """ Device pipes list """ device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) pipes = proxy.get_pipe_list() return json([{ "name": pipe, "href": buildurl(rq, "rc3.pipe", tango_host, device, pipe=pipe) } for pipe in pipes])
async def device_state(rq, host, port, domain, family, member): """ Device state """ device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) state = await proxy.State() status = await proxy.Status() return json({ "state": str(state), "status": status, "_links": { "_state": buildurl(rq, "rc3.attribute", tango_host, device, attr="State"), "_status": buildurl(rq, "rc3.attribute", tango_host, device, attr="Status"), "_parent": buildurl(rq, "rc3.device", tango_host, device), "_self": buildurl(rq, "rc3.device_state", tango_host, device) } })
async def command(rq, host, port, domain, family, member, cmd): """ Display device command info or Execute a command""" result = {} device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) info = proxy.get_command_config(cmd) if rq.method == "PUT": # Set None if no argument for DevVoid Argin if str(info.in_type) == "DevVarStringArray": argument = rq.body.decode().split(',') else: argument = rq.body or None output = await proxy.command_inout(cmd, argument) result = {"name": cmd} if output: result["output"] = output else: result = { "name": cmd, "info": { "cmd_name": info.cmd_name, "cmd_tag": info.cmd_tag, "level": str(info.disp_level), "in_type": str(info.in_type), "out_type": str(info.out_type), "in_type_desc": info.in_type_desc, "out_type_desc": info.out_type_desc }, "history": buildurl(rq, "rc3.command_history", tango_host, device, cmd=cmd), "_links": { "_self": buildurl(rq, "rc3.command", tango_host, device, cmd=cmd) } } return json(result)
async def attributes(rq, host, port, domain, family, member): """ Device attributes list """ device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) attrs = proxy.get_attribute_list() return json([{ "name": attr, "value": buildurl(rq, "rc3.attribute_value", tango_host, device, attr=attr), "info": buildurl(rq, "rc3.attribute_info", tango_host, device, attr=attr), "properties": buildurl(rq, "rc3.attribute_properties", tango_host, device, attr=attr), "history": buildurl(rq, "rc3.attribute_history", tango_host, device, attr=attr), "_links": { "_self": buildurl(rq, "rc3.attributes", tango_host, device) } } for attr in attrs])
async def attribute(rq, host, port, domain, family, member, attr): """ Links for different things for device attribute """ device = "/".join((domain, family, member)) return json({ "name": attr, "value": buildurl(rq, "rc3.attribute_value", tango_host, device, attr=attr), "info": buildurl(rq, "rc3.attribute_info", tango_host, device, attr=attr), "properties": buildurl(rq, "rc3.attribute_properties", tango_host, device, attr=attr), "history": buildurl(rq, "rc3.attribute_history", tango_host, device, attr=attr), "_links": { "_self": buildurl(rq, "rc3.attribute", tango_host, device, attr=attr) } })
async def devices(rq, host, port): """ Device list """ devs = [] domains = db.get_device_domain("*") for d in domains: families = db.get_device_family("%s/*" % d) for f in families: members = db.get_device_member("%s/%s/*" % (d, f)) for m in members: devs.append('/'.join((d, f, m))) return json([{ "name": dev, "href": buildurl(rq, "rc3.device", tango_host, dev) } for dev in devs])
async def devices(rq, host, port): """ Device list url args can be ?domain=reg1&family=reg2&member=reg3&wildcard=sys/tg_test&range=0-25 if pattern is present the other filters are ignored """ devs = [] dev_range = rq.args.pop("range", None) filters = rq.args db_proxy = await getDeviceProxy(db.dev_name()) devs = await db_proxy.DbGetDeviceList(['*', '*']) devs = device_filtering(devs, filters, dev_range) return json([{ "name": dev, "href": buildurl(rq, "rc3.device", tango_host, dev) } for dev in devs])
async def pipe(rq, host, port, domain, family, member, pipe): """ Display pipe info and contents """ if rq.method == "PUT": raise HTTP501_NotImplemented device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) value = await proxy.read_pipe(pipe) data = [] for v in value[1]: data.append({"name": v["name"], "value": [v["value"]]}) return json({ "name": pipe, "size": len(value), "timestamp": int(time()), "data": data, "_links": { "_self": buildurl(rq, "rc3.pipe", tango_host, device, pipe=pipe) } })
async def api_root(rq): """ System API entry point: links to other functions """ return json({ "stats": buildurl(rq, "sys.stats"), "gc": [buildurl(rq, "sys.clean_devs"), buildurl(rq, "sys.clean_attrs")], "active": [buildurl(rq, "sys.cache_devs"), buildurl(rq, "sys.cache_attrs")], "config": buildurl(rq, "sys.config"), "version": "mtango-py %s" % str(conf.version) })
async def device(rq, host, port, domain, family, member): """ Device info """ device = "/".join((domain, family, member)) proxy = await getDeviceProxy(device) import_info = proxy.import_info() info = proxy.info() return json({ "name": import_info.name, "info": { "last_exported": "---", "last_unexported": "---", "name": import_info.name, "ior": import_info.ior, "version": import_info.version, "exported": bool(import_info.exported), "pid": "---", "server": info.server_id, "hostname": info.server_host, "classname": info.dev_class, "is_taco": "---" }, "attributes": buildurl(rq, "rc3.attributes", tango_host, device), "commands": buildurl(rq, "rc3.commands", tango_host, device), "pipes": buildurl(rq, "rc3.pipes", tango_host, device), "properties": buildurl(rq, "rc3.properties", tango_host, device), "state": buildurl(rq, "rc3.device_state", tango_host, device), "_links": { "_self": buildurl(rq, "rc3.device", tango_host, device), "_parent": buildurl(rq, "rc3.devices", tango_host) } })
async def hosts(rq): """ List available TANGO_HOSTs Actually, it returns only the system configured TANGO_HOST """ return json( {"%s:%s" % tango_host: buildurl(rq, "rc3.db_info", tango_host)})
async def api_root(rq): """ rc3 API entry point """ return json({"hosts": buildurl(rq, "rc3.hosts"), "x-auth-method": "none"})
async def list_api_versions(rq): """ Application entry point: list available APIs """ return json({ "rc3": buildurl(rq, "rc3.api_root"), # mTango rc3 API "sys": buildurl(rq, "sys.api_root") # server system API })