62def main(crate_ip, amcs, cmd):
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]")
72 crate_subnet = crate_ip.rsplit(
".", 1)[0]
73 nic_ip = crate_subnet+
'.129'
75 amc_ips = { i: crate_subnet + f
".{i + 1}" for i
in amcs}
85 devices.update({f
'AMC {amc}': amc_ip
for amc, amc_ip
in amc_ips.items()})
89 from concurrent.futures
import ThreadPoolExecutor, as_completed
90 import subprocess
as sp
96 return sh.arping([
"-c",
'1', amc_ip])
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]
105 except sp.TimeoutExpired:
106 print(f
"[TIMEOUT] {amc}", file=sys.stderr)
107 failures.append((amc,
"timeout"))
109 except sh.ErrorReturnCode
as e:
110 print(f
"- [red]Could not arping device at IP: {amc_ip}[/red]")
112 except Exception
as ex:
113 print(f
"[EXCEPTION] {amc}: {ex}", file=sys.stderr)
114 failures.append((amc,
"exception"))
117 match = re.search(
r"Unicast reply from\s+([\d.]+)\s+\[([0-9A-Fa-f:]{17})\]", rc)
119 ipaddr, mac = match.group(1), match.group(2)
120 print(f
"- [green]{amc} ({amc_ip}) responded to arping : mac {mac}[/green]")
123 except KeyboardInterrupt:
124 print(
"\nInterrupted. Shutting down workers…", file=sys.stderr)
127 controllers = { amc_ip:tdemodules.AMCController(amc_ip, 54321 + (i + 1))
for i,amc_ip
in amc_ips.items() }