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
/
f5pool_deploy.py
executable file
·106 lines (79 loc) · 2.86 KB
/
f5pool_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
105
106
#!/usr/bin/env python26
"""Create pools from pool config files"""
import glob
import os
import sys
import f5utility
import logging
import subprocess
from time import sleep
def main():
"""Create pools from pool config files"""
#Set directory for pool conf files
src_dir = 'pools/'
#Create Connection to the f5
f5 = f5utility.f5Connection()
print " "
print "------------------------------"
print " Checking Configuration"
print "------------------------------"
print " "
#Create empty queue for pool create/changes
queue = []
for infile in sorted(glob.glob(os.path.join(src_dir, '*_pool'))):
#Build a pool from the config file and check that its valid
pool = f5.pool.build(infile)
name = pool['name']
# Check if the pool already exists
if f5.pool.exists(name):
# Check if the pool has changed
if f5.pool.changed(pool):
# if the pool is valid add it to the queue
# if the pool is not valid this will fail and exit the script
if f5.pool.test(pool):
print "Marking pool %s for modification" % name
pool['operation'] = 'modify'
queue.append(pool)
else:
print "No Changes made to %s" % name
else:
# Check if there is a monitor available for the pool, exit if not.
monitor_name = f5utility.swap_suffix("_health", name)
if f5.monitor.exists(monitor_name):
# Add pool to queue for creation
print "Marking pool %s for creation" % name
pool['operation'] = 'create'
queue.append(pool)
else:
print "NO Monitor exists for %s ... STOPPING!" % name
sys.exit("exit.")
#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 pool in queue:
f5.pool.commit(pool)
sleep(5)
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","pools"],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()