This repository has been archived by the owner on Nov 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
f5monitor_deploy.py
executable file
·105 lines (76 loc) · 2.85 KB
/
f5monitor_deploy.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python26
"""Create monitors from config files"""
import glob
import os
import sys
import f5utility
import subprocess
def main():
"""Create Monitors from config files"""
#Set directory for monitor conf files
src_dir = 'monitors/'
#Create Connection to the f5
f5 = f5utility.f5Connection()
print " "
print "------------------------------"
print " Checking Configuration"
print "------------------------------"
print " "
#Create empty queue for monitor create/changes
queue = []
for infile in sorted(glob.glob(os.path.join(src_dir, '*_health'))):
#Build a monitor from the config file and check that its valid
monitor = f5.monitor.build(infile)
name = monitor['monitor_template'].template_name
# Check if the monitor already exists
if f5.monitor.exists(name):
# Check if the monitor has changed
changed = f5.monitor.changed(monitor)
if (changed == 2):
if f5.monitor.test(monitor):
print "Marking monitor %s for re-creation" % name
monitor['operation'] = 'recreate'
queue.append(monitor)
elif (changed == 1):
# if the monitor is valid add it to the queue
# if the monitor is not valid this will fail and exit the script
if f5.monitor.test(monitor):
print "Marking monitor %s for modification" % name
monitor['operation'] = 'modify'
queue.append(monitor)
else:
print "No Changes made to %s" % name
else:
# Add monitor to queue for creation
print "Marking monitor %s for creation" % name
monitor['operation'] = 'create'
queue.append(monitor)
#Process the queue and commit changes to f5
print " "
print "------------------------------"
print " Committing Changes"
print "------------------------------"
print " "
# If the queue is empty print message, otherwise commit items in queue
if queue == []:
print "No Changes to Commit."
else:
for monitor in queue:
f5.monitor.commit(monitor)
print " "
print "------------------------------"
print " Syncing Changes"
print "------------------------------"
print " "
# sync the F5s
f5.config_sync.sync_all()
print " "
print "done."
if __name__ == "__main__":
try:
with open(os.devnull,'wb') as devnull:
subprocess.check_call(["/usr/bin/cvs","diff","monitors"],stdout=devnull,stderr=devnull)
except subprocess.CalledProcessError:
print "Changes have not been committed to cvs. Run 'cvs diff' confirm the changes and then commit them"
sys.exit(1)
main()