Permalink
Browse files

added a fab file to deploy named.conf files. This needs to be refacto…

…red and engineered.
  • Loading branch information...
1 parent d5ea615 commit 1195f554ad6c2e03ffc65a97725af262ba1160ae @uberj committed Jan 4, 2012
Showing with 106 additions and 5 deletions.
  1. +3 −2 configurator.py
  2. +90 −0 deploy_configs.py
  3. +1 −1 documentation/README.mkd
  4. +2 −2 main.py
  5. +10 −0 ns1.pp
View
@@ -9,7 +9,7 @@ class Configurator(object):
@param build_dir: Where the actual zone files will be placed after the build completes (bind needs to know this).
@test_file: a generated bashscript that tests all zone files generated for syntax errors.
"""
- def __init__( self, db_cur, filename="named.conf", bind_dir="/etc/bind", build_dir="/var/named" ):
+ def __init__( self, db_cur, filename="named.conf", bind_dir="/etc/bind", build_dir="/etc/bind/zones" ):
self.bind_dir = bind_dir # Where to put the named.conf file
self.build_dir = build_dir # Where the zone files are kept
self.cur = db_cur # Database cursor
@@ -20,7 +20,8 @@ def __init__( self, db_cur, filename="named.conf", bind_dir="/etc/bind", build_d
self.bind_tests = build_test.Tester()
self.test_cases = [] # tests cases to be run later.
# The format for a test case should be ( 'test_name', [args to subprocess] )
- self.test_cases.append( ("config", ["named-checkconf","-z", self.bind_dir+"/"+filename ]) )
+ # Hard coded test
+ #self.test_cases.append( ("config", ["named-checkconf", "/etc/bind/"+filename ]) )
def build_named_conf_master( self ):
print "Building "+self.master_filename+" in "+self.bind_dir
View
@@ -0,0 +1,90 @@
+from fabric.api import *
+
+master = 'ns-dev.nws.oregonstate.edu'
+slaves = ['ns4jr.nws.oregonstate.edu']
+env.hosts = slaves
+
+maintain_dir = "/data/maintain"
+
+def uname():
+ run('uname -a')
+
+def build():
+ pass
+
+def deploy_maintain_named_conf():
+ local_conf = maintain_dir + "/staging/named.conf.maintain"
+ for slave in slaves:
+ local("scp "+local_conf+" "+slave+":/etc/bind/")
+
+ local("cp "+local_conf+" /etc/bind/named.conf.maintain")
+ if run("/etc/init.d/bind9 reload").failed:
+ print "Slaved failed to reload"
+
+def deploy_slave_delegated_conf():
+ local_conf = "/etc/bind/named.conf.delegated"
+ for slave in slaves:
+ local("scp "+local_conf+" "+slave+":/etc/bind/")
+
+ run("/etc/init.d/bind9 reload")
+
+
+def deploy_slave_named_conf():
+ local_conf = maintain_dir + "/staging/named.conf.maintain.slave"
+ for slave in slaves:
+ local("scp "+local_conf+" "+slave+":/etc/bind/")
+
+ local("cp "+local_conf+" /etc/bind/named.conf.maintain.slave")
+ if run("/etc/init.d/bind9 reload").failed:
+ print "Slaved failed to reload"
+
+def reload_bind():
+ if local("/etc/init.d/bind9 reload").failed:
+ print "oops"
+
+def build_configs_into_staging():
+ local("python main.py -c -d staging")
+
+def setup():
+ with settings(warn_only=True):
+ if local("test -d build").failed:
+ local("mkdir build")
+ if local("test -d staging").failed:
+ local("mkdir staging")
+
+def changes_in_maintain_named_conf():
+ local_conf = "named.conf.maintain"
+ with settings(warn_only=True):
+ if local("diff /etc/bind/"+local_conf+" "+maintain_dir+"/staging/"+local_conf+" > /dev/null").failed:
+ return True
+ else:
+ return False
+
+
+def changes_in_slave_named_conf():
+ local_conf = "named.conf.maintain.slave"
+ with settings(warn_only=True):
+ if local("diff /etc/bind/"+local_conf+" "+maintain_dir+"/staging/"+local_conf+" > /dev/null").failed:
+ #if local("diff /etc/bind/"+local_conf+" "+maintain_dir+"/staging/"+local_conf).failed:
+ return True
+ else:
+ return False
+
+def fix_perms():
+ local("chown -R bind /etc/bind")
+
+def deploy():
+ cd( maintain_dir )
+ setup()
+ ### Build all
+ local("pwd")
+ local("python main.py -c --build_dir=/etc/bind/zones --bind_dir="+maintain_dir+"/staging")
+ fix_perms()
+ ### Build bind configs
+ if changes_in_maintain_named_conf():
+ deploy_maintain_named_conf()
+ if changes_in_slave_named_conf():
+ deploy_slave_named_conf()
+ deploy_slave_delegated_conf()
+ fix_perms()
+ reload_bind()
View
@@ -27,7 +27,7 @@ print's are not in final place
Printing class and subclass defintions (dynamic host records)
for dyn_range in Range.filter( type='dynamic' ):
- for local_ctnr in range_CTNR.filter( range = dyn_range.id ).get_related( CTNR ): #Join
+ for local_ctnr in Range_CTNR.objects.filter( range = dyn_range ).get_related( CTNR ): #Join
class_name = '"'+local_ctnr.name+':'+dyn_range.start+':'+dyn_range.stop+'"'
print 'class ${class_name} {'
print_class_options( dyn_range.id ) #TODO
View
@@ -47,7 +47,7 @@ def run( self ):
# build named.conf.maintain file
def config_build( self, bind_dir, build_dir ):
- cf_master = Configurator( db_cur = self.cur, filename ="named.conf.maintain", bind_dir=bind_dir, build_dir=build_dir)
+ cf_master = Configurator( db_cur = self.cur, filename ="named.conf", bind_dir=bind_dir, build_dir=build_dir)
cf_master.build_named_conf_master()
cf_master.build_named_conf_slave()
@@ -78,7 +78,7 @@ def reverse_zones_build( self, build_dir ):
parser.add_option("-z", "--zone", default=False, action="store_true", dest="build_zone", help="Build forward zones")
parser.add_option("-r", "--rev_zone", default=False, action="store_true", dest="build_rev", help="Build reverse zones")
parser.add_option("-c", "--config", default=False, action="store_true", dest="build_config", help="Build named.conf.maintain file")
- parser.add_option("-b", "--build_dir", default="/var/named", dest="build_dir", help="A directory to store the build output")
+ parser.add_option("-b", "--build_dir", default="/etc/bind/zones", dest="build_dir", help="A directory to store the build output")
parser.add_option("-d", "--bind_dir", default="/etc/bind", dest="bind_dir", help="Where to place the named.conf.maintain file")
parser.add_option("-t", "--records_test", default=False, action="store_true", dest="run_records_test", help="Run records test claus")
parser.add_option("-k", "--test_zone_files", default=False, action="store_true", dest="test_zone_files", help="Run records test claus")
View
10 ns1.pp
@@ -31,6 +31,16 @@
package { 'python-mysqldb':
ensure => "present",
}
+
+ package { 'pip':
+ ensure => "present",
+ }
+
+ package { 'Fabric':
+ provider => 'pip',
+ ensure => "present",
+ require => Package['pip'],
+ }
#### Maintain stuff (write module, soon).
package { 'libdbi-perl':
ensure => "present",

0 comments on commit 1195f55

Please sign in to comment.