-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_sim.py
More file actions
32 lines (27 loc) · 823 Bytes
/
node_sim.py
File metadata and controls
32 lines (27 loc) · 823 Bytes
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
import requests, time, os, random
import uuid
NODE_ID = str(uuid.uuid4())
API_SERVER = os.getenv("API_SERVER", "http://host.docker.internal:5000")
CPU = os.getenv("CPU", "4")
pod_ids = []
def heartbeat():
while True:
try:
res = requests.post(f"{API_SERVER}/heartbeat", json={
"node_id": NODE_ID,
"cpu": int(CPU),
"pods": pod_ids
})
print(res.text)
except:
print("API Server unreachable")
time.sleep(5)
def register():
try:
res = requests.post(f"{API_SERVER}/register", json={"node_id": NODE_ID, "cpu": int(CPU)})
print("Node Registered:", res.text)
except Exception as e:
print("Registration failed", e)
if __name__ == "__main__":
register()
heartbeat()