forked from cms-DQM/fff_dqmtools
/
fff_cluster.py
executable file
·62 lines (46 loc) · 1.55 KB
/
fff_cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# this should later become a reader for a configuration file in /etc/
import socket
clusters = {
#'production': ["bu-c2f13-31-01", "fu-c2f13-39-01", "fu-c2f13-39-02", "fu-c2f13-39-03", "fu-c2f13-39-04"],
#'playback': [ "bu-c2f13-29-01", "fu-c2f13-41-01", "fu-c2f13-41-02", "fu-c2f13-41-03"],
'production_c2f11': ["bu-c2f11-09-01", "fu-c2f11-11-01", "fu-c2f11-11-02", "fu-c2f11-11-03","fu-c2f11-11-04", ],
'playback_c2f11': ["bu-c2f11-13-01", "fu-c2f11-15-01", "fu-c2f11-15-02", "fu-c2f11-15-03", "fu-c2f11-15-04", ],
'lookarea_c2f11': ["bu-c2f11-19-01", ]
}
def get_host():
host = socket.gethostname()
host = host.lower()
return host
def get_node():
host = get_host()
current = {
"_all": clusters,
}
for key, lst in clusters.items():
if host in lst:
current["node"] = host
current["nodes"] = lst
current["label"] = key
break
return current
def host_wrapper(allow = []):
""" This is decorator for function.
Runs a function of the given hosts,
just returns on others.
"""
host = get_host()
def run_wrapper(f):
return f
def noop_wrapper(f):
def noop(*args, **kwargs):
name = kwargs["name"]
log = kwargs["logger"]
log.info("The %s applet is not allowed to run on %s, disabling", name, host)
return None
return noop
if host in allow:
return run_wrapper
else:
return noop_wrapper
if __name__ == "__main__":
print get_node()