-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpower_restore_boot.py
42 lines (38 loc) · 1.09 KB
/
power_restore_boot.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
#!/usr/bin/env python
import os
import paramiko
import sys
import time
hostname = "hostip" # hostip
idrac = "idracip" # idracip
idracUN = "YourUsername"
idracPW = "YourPassword"
waittime = "WaitTimeInSeconds"
# ping host
PingHOST = os.system("ping -c 1 -w2 " + hostname + " > /dev/null 2>&1")
# ping idrac
PingIDRAC = os.system("ping -c 1 -w2 " + idrac + " > /dev/null 2>&1")
# time.sleep(waittime) #Uncomment if you'd like a dealy
# check response
if PingHOST == 0: # host is up
print('Host online')
sys.exit()
else: # if host can't be pinged
if PingIDRAC == 0: # idrac is up
# ssh into idrac
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(
idrac,
port=22,
username=idracUN,
password=idracPW,
look_for_keys=False
)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(
'racadm serveraction powerup'
)
print('Starting host')
else: # if idrac is down
print('iDrac down!')
sys.exit()