DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
felixRPCMonitor.py
Go to the documentation of this file.
1from SimpleXMLRPCServer import SimpleXMLRPCServer
2from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
3from subprocess import call, Popen, PIPE
4import re
5
6pathBase="<felix_dist_dir>"
7
8def shell_source(script):
9 """Sometime you want to emulate the action of "source" in bash,
10 settings some environment variables. Here is a way to do it."""
11 import subprocess, os
12 pipe = subprocess.Popen(". %s; env" % script, stdout=subprocess.PIPE, shell=True)
13 output = pipe.communicate()[0]
14 #print output
15 env = dict((line.split("=", 1) for line in output.splitlines()))
16 os.environ.update(env)
17
18def callSubp(appDict):
19 p = Popen(appDict, stdin=PIPE, stdout=PIPE, stderr=PIPE)
20 output, err = p.communicate(b"input data that is passed to subprocess' stdin")
21 return output, err, p.returncode
22
23shell_source("<felix_dist_dir>/setup.sh")
24
25# Restrict to a particular path.
26class RequestHandler(SimpleXMLRPCRequestHandler):
27 rpc_paths = ('/RPC2',)
28
29# Create server
30server = SimpleXMLRPCServer(("0.0.0.0", 10001),requestHandler=RequestHandler)
31server.register_introspection_functions()
32
34
35 def heartbeat(self):
36 return "OK"
37
38 def lspci(self, card=0):
39 ret1 = callSubp(["lspci"])
40 ret1Split = ret1[0].split('\n')
41 devid = [line for line in ret1Split if "FPGA Card" in line]
42 if not devid:
43 return " ", " ", " ", " "
44 ret2 = callSubp(["lspci", "-s", devid[0].split(' ')[0], "-vvvvv"])
45 ret2Split = ret2[0].split('\n')
46 control = [line for line in ret2Split if "Control" in line]
47 status = [line for line in ret2Split if "Status" in line]
48 numa = [line for line in ret2Split if "NUMA" in line]
49 return devid, control, status, numa
50
51 def driver(self, card=0):
52 ret = callSubp(["/etc/init.d/drivers_flx", "status"])
53 retSplit = ret[0].split('\n')
54 version = [line for line in retSplit if "FLX driver" in line]
55 cmem = [line for line in retSplit if "GFPBPA" in line]
56 githash = [line for line in retSplit if "GIT hash" in line]
57 return version, cmem, githash
58
59 def links(self, card=0):
60 c0 = "-d "+str(card)
61 c1 = "-d "+str(card+1)
62 ret = callSubp([pathBase+"flxcard/flx-info", "GBT"])
63 return ret
64 retSplit = ret[0].split('\n')
65 channel = [line for line in retSplit if "Channel" in line]
66 aligned = [line for line in retSplit if "Aligned" in line]
67 return channel, aligned
68
69server.register_instance(FelixMonitors())
70
71# Run the server's main loop
72server.serve_forever()
73
74