DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
amc_butler Namespace Reference

Classes

class  Commands
 

Functions

 ping (host)
 
 main (crate_ip, amcs, cmd)
 

Detailed Description

Created on: 05/06/2025 11:16

Author: Shyam Bhuller, Alessandro Thea

Description: Check the status of an AMC or multiple AMCs to ensure they can be reached.

Function Documentation

◆ main()

amc_butler.main ( crate_ip,
amcs,
cmd )

Definition at line 62 of file amc_butler.py.

62def main(crate_ip, amcs, cmd):
63
64 # get list of amcs from the command arguments
65 try:
66 sh.ping(["-c", '1', crate_ip])
67 print(f"[green]uTCA crate {crate_ip} is active[/green]")
68 except sh.ErrorReturnCode as e:
69 print(f"[red]Could not ping uTCA Crate at IP: {crate_ip}[/red]")
70 exit(1)
71
72 crate_subnet = crate_ip.rsplit(".", 1)[0]
73 nic_ip = crate_subnet+'.129'
74
75 amc_ips = { i: crate_subnet + f".{i + 1}" for i in amcs}
76
77 if cmd=='arping':
78
79
80 devices = {
81 'crate': crate_ip,
82 'nic': nic_ip
83 }
84
85 devices.update({f'AMC {amc}': amc_ip for amc, amc_ip in amc_ips.items()})
86
87
88
89 from concurrent.futures import ThreadPoolExecutor, as_completed
90 import subprocess as sp
91 import sys
92
93 failures = []
94 MAX_WORKERS=10
95 def arping(amc_ip):
96 return sh.arping(["-c", '1', amc_ip])
97 try:
98
99 with ThreadPoolExecutor(max_workers=MAX_WORKERS) as pool:
100 futures = {pool.submit(arping, amc_ip):(amc, amc_ip) for amc, amc_ip in devices.items()}
101 for fut in as_completed(futures):
102 amc, amc_ip = futures[fut]
103 try:
104 rc = fut.result()
105 except sp.TimeoutExpired:
106 print(f"[TIMEOUT] {amc}", file=sys.stderr)
107 failures.append((amc, "timeout"))
108 continue
109 except sh.ErrorReturnCode as e:
110 print(f"- [red]Could not arping device at IP: {amc_ip}[/red]")
111 continue
112 except Exception as ex:
113 print(f"[EXCEPTION] {amc}: {ex}", file=sys.stderr)
114 failures.append((amc, "exception"))
115 continue
116
117 match = re.search(r"Unicast reply from\s+([\d.]+)\s+\[([0-9A-Fa-f:]{17})\]", rc)
118 if match:
119 ipaddr, mac = match.group(1), match.group(2)
120 print(f"- [green]{amc} ({amc_ip}) responded to arping : mac {mac}[/green]")
121
122
123 except KeyboardInterrupt:
124 print("\nInterrupted. Shutting down workers…", file=sys.stderr)
125 # ProcessPool will terminate on context exit
126 else:
127 controllers = { amc_ip:tdemodules.AMCController(amc_ip, 54321 + (i + 1)) for i,amc_ip in amc_ips.items() }
128 print(controllers)
129 cmds = Commands(controllers)
130 getattr(cmds, cmd)()
131
132 return
133
134 return
135
int main(int argc, char *argv[])
Definition list_apps.cxx:81

◆ ping()

amc_butler.ping ( host)

Definition at line 19 of file amc_butler.py.

19def ping(host):
20 return subprocess.call(['ping', "-c", '1', host]) == 0
21