mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-07 14:03:01 +07:00
Check if node alive or not
This commit is contained in:
parent
96df8062d5
commit
8f73f92a96
@ -28,20 +28,28 @@ nodes = [
|
||||
}
|
||||
]
|
||||
|
||||
def poweroff(nodes):
|
||||
for node in nodes:
|
||||
def is_alive(node):
|
||||
return os.system(f"ping -c 1 {node['ip']}") == 0
|
||||
|
||||
def poweroff(node):
|
||||
if is_alive(node):
|
||||
print(f"Poweroff {node['hostname']}")
|
||||
os.system(f"ssh {user}@{node['ip']} poweroff")
|
||||
else:
|
||||
print(f"Node {node['hostname']} is already dead!")
|
||||
|
||||
def wake(nodes):
|
||||
for node in nodes:
|
||||
print(f"Waking up {node['hostname']}")
|
||||
os.system(f"wol {node['mac']}")
|
||||
print(f"Waking up {node['hostname']}")
|
||||
os.system(f"wol {node['mac']}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(f"./infra/pxe-server")
|
||||
os.system(f"docker-compose up -d --build")
|
||||
|
||||
poweroff(nodes)
|
||||
for node in nodes:
|
||||
poweroff(node)
|
||||
|
||||
time.sleep(10)
|
||||
wake(nodes)
|
||||
|
||||
for node in nodes:
|
||||
wake(node)
|
||||
|
Loading…
Reference in New Issue
Block a user