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
/
f5irule_deploy.py
executable file
·75 lines (57 loc) · 2.09 KB
/
f5irule_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
#!/usr/bin/env python26
"""irule deployment"""
import os
import sys
import f5utility
import suds
import subprocess
def main():
"""Evalutes irules in subdirs, tests them individually on the
load balancer before collating rules and pushing to f5"""
f5 = f5utility.f5Connection()
# Fetching a list of subdirectories which we need to process
subdirs = os.listdir('./irules')
for dirs in subdirs:
if dirs == 'CVS':
continue
print " "
print "------------------------------"
print " Processing subdirectory %s" % dirs
print "------------------------------"
print " "
full_path = './irules/'+dirs
if os.path.isdir(full_path):
# Build the rule
rule_def = f5.irule.rule_build(full_path, dirs)
# Check the rule for basic errors
print "Built rules for "+dirs
# Check if the rule exists, create if it doesn't
try:
rule = f5.irule.rule.query_rule(rule_names=[dirs+"_rule"])
except:
rule = f5.irule.rule.create(rules=[rule_def])
# Modify the rule if it exists already
try:
rule = f5.irule.rule.modify_rule(rules=[rule_def])
except suds.WebFault as detail:
print "Failed to update the rule, probably due to a syntax error"
sys.exit(detail)
f = open(dirs+"_rule",'w')
f.write(str(rule_def))
f.close()
print "Rules uploaded to f5"
print " "
print "------------------------------"
print " Syncing Changes"
print "------------------------------"
print " "
# sync the F5s
f5.config_sync.sync_all()
if __name__ == "__main__":
try:
with open(os.devnull,'wb') as devnull:
subprocess.check_call(["/usr/bin/cvs","diff","irules"],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()