-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.py
55 lines (44 loc) · 1.53 KB
/
patch.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
43
44
45
46
47
48
49
50
51
52
53
__author__ = 'tatroc'
from fabric.api import run, env, settings
import os
import time
import requests
from datetime import datetime
import syslog
from datetime import timedelta
import sys
def get_couch_status(hostname, rtimeout):
status = 400
now = datetime.now()
future_time = now + timedelta(seconds=rtimeout)
while status != 200:
time.sleep(5)
try:
url = 'http://' + hostname + ':8091'
resp = requests.get(url, params=None)
status = resp.status_code
msg = str(datetime.now()) + " : Connection success, status: " + str(status)
print msg
syslog.syslog(syslog.LOG_INFO, msg)
if rtimeout != 0:
if datetime.now() > future_time:
msg = str(datetime.now()) + " : Reboot timeout " + str(rtimeout) + " seconds exceeded, exiting script!"
print msg
syslog.syslog(syslog.LOG_INFO, msg)
sys.exit(-1)
except Exception as e:
pass
msg = str(datetime.now()) + " : Connection failed, status: " + str(status)
print msg
syslog.syslog(syslog.LOG_ERR, msg)
def patch_and_reboot(hostname, osuser, ospassword, rtimeout):
env.hosts = [hostname]
env.user = osuser
env.password = ospassword
for host in env.hosts:
#print host
env.host_string = host
run('yum update -y')
run('shutdown -r now')
time.sleep(20)
get_couch_status(hostname, rtimeout)