43 lines
820 B
Python
43 lines
820 B
Python
from governor import thermal_cap
|
|
|
|
|
|
def score_node(node):
|
|
if node["state"] == "offline":
|
|
return 0.0
|
|
|
|
agent = node.get("agent") or {}
|
|
|
|
try:
|
|
load = float(agent.get("load", "1 1 1").split()[0])
|
|
except:
|
|
load = 1.0
|
|
|
|
base = 10.0
|
|
capacity = node.get("max_jobs", 8)
|
|
|
|
score = (base + capacity) - (load * 3.0)
|
|
|
|
return max(score, 0.1) * thermal_cap(agent)
|
|
|
|
|
|
def build_distcc_hosts(nodes):
|
|
scored = []
|
|
|
|
for n in nodes:
|
|
scored.append((n, score_node(n)))
|
|
|
|
total = sum(s for _, s in scored) or 1.0
|
|
|
|
hosts = []
|
|
|
|
for node, score in scored:
|
|
if node["state"] == "offline":
|
|
continue
|
|
|
|
weight = int((score / total) * 64)
|
|
weight = max(1, weight)
|
|
|
|
hosts.append(f"{node['host']}/{weight}")
|
|
|
|
return " ".join(hosts)
|