fester/backend/nodes.py

43 lines
806 B
Python

import json
import requests
from config import CONFIG
from scheduler import build_distcc_hosts
AGENT_PORT = 8787
def fetch_agent(node):
try:
r = requests.get(f"http://{node['host']}:{AGENT_PORT}/status", timeout=1.5)
return r.json()
except:
return None
def enrich(node):
agent = fetch_agent(node)
return {
"name": node["name"],
"host": node["host"],
"state": "online" if agent else "offline",
"agent": agent,
"release_ready": agent is not None
}
def main():
nodes = [enrich(n) for n in CONFIG["nodes"]]
output = {
"master": CONFIG["master"],
"nodes": nodes,
"distcc": build_distcc_hosts(nodes)
}
print(json.dumps(output, indent=2))
if __name__ == "__main__":
main()