initial commit
This commit is contained in:
parent
b0270c07d4
commit
6eb52268a0
|
@ -0,0 +1,67 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from dimclient import DimClient
|
||||||
|
# needs to be adjusted for python3
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
|
||||||
|
def print_help():
|
||||||
|
print("Usage: bind_zone_output <config_file>")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print_help()
|
||||||
|
sys.exit(-1)
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read(sys.argv[1])
|
||||||
|
|
||||||
|
if not config.has_section('default'):
|
||||||
|
print("default section not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
if not config.has_section('command'):
|
||||||
|
print("command section not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
if not config.has_option('default', 'server'):
|
||||||
|
print("setting 'server' not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
if not config.has_option('default', 'output'):
|
||||||
|
print("setting 'output' not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
if not config.has_option('default', 'zone_dir'):
|
||||||
|
print("setting 'zone_dir' not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
if not config.has_option('default', 'filename'):
|
||||||
|
print("setting 'filename' not found in config file")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
c = DimClient(config.get('default', 'server'))
|
||||||
|
if config.has_option('default', 'username'):
|
||||||
|
c.login(config.get('default', 'username'), config.get('default', 'password'))
|
||||||
|
|
||||||
|
to_update = c.output_update_list(output=config.get('default', 'output'))
|
||||||
|
for update in to_update:
|
||||||
|
filename = config.get('default', 'filename') % (update['zone_name'])
|
||||||
|
filepath = os.path.join(config.get('default', 'zone_dir'), filename)
|
||||||
|
if update['action'] != 'delete_zone':
|
||||||
|
output = c.zone_dump(update['zone_name'])
|
||||||
|
try:
|
||||||
|
with open(filepath, 'w+', 0644) as fp:
|
||||||
|
fp.write(output)
|
||||||
|
except IOError as e:
|
||||||
|
print("could not write zone file '%s': %s" % (update['zone_name'], e))
|
||||||
|
sys.exit(-1)
|
||||||
|
if update['action'] == 'create_zone' and config.has_option('command', 'add_zone'):
|
||||||
|
command = config.get('command', 'add_zone') % (update['zone_name'])
|
||||||
|
subprocess.call(command)
|
||||||
|
elif update['action'] != 'create_zone' and config.has_option('command', 'reload_zone'):
|
||||||
|
command = config.get('command', 'reload_zone') % (update['zone_name'])
|
||||||
|
subprocess.call(command)
|
||||||
|
elif update['action'] == 'delete_zone':
|
||||||
|
os.remove(filepath)
|
||||||
|
if config.has_option('command', 'del_zone'):
|
||||||
|
command = config.get('command', 'del_zone') % (update['zone_name'])
|
||||||
|
subprocess.call(command)
|
||||||
|
c.output_update_delete([update['id']])
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
[default]
|
||||||
|
# server defines the server address to pull the update list from.
|
||||||
|
server = http://url.to.dim
|
||||||
|
|
||||||
|
# Set the output name to update the specific output queue.
|
||||||
|
output = test
|
||||||
|
|
||||||
|
# username is the user as which to connect.
|
||||||
|
# This is important as the user requires the permission to update the
|
||||||
|
# output queue.
|
||||||
|
username = myuser
|
||||||
|
|
||||||
|
# Set a password if one was set for the user account.
|
||||||
|
password = none
|
||||||
|
|
||||||
|
# Set the directory where all zone files are located. It should be outside
|
||||||
|
# of any other config files.
|
||||||
|
zone_dir = /tmp/zones/
|
||||||
|
|
||||||
|
# Set the filename format for the generated zone files. %s will be replaced
|
||||||
|
# with the zone name.
|
||||||
|
filename = %s.zone
|
||||||
|
|
||||||
|
[command]
|
||||||
|
# Set the command to run, when a zone was added.
|
||||||
|
# add_zone = nsd-control addzone %s forward
|
||||||
|
|
||||||
|
# Set the command to run after a zone was deleted.
|
||||||
|
# del_zone = nsd-control delzone %s
|
||||||
|
|
||||||
|
# Set the command to reload a zone after the file was updated.
|
||||||
|
# reload_zone = nsd-control reload %s
|
|
@ -0,0 +1 @@
|
||||||
|
dimclient>=0.4.2
|
|
@ -0,0 +1,8 @@
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
setup(name='dim_output_bind',
|
||||||
|
version='0.1',
|
||||||
|
description='A plugin to write bind files from dim output.',
|
||||||
|
scripts=['dim_output_bind'],
|
||||||
|
data_files=[('share/dim_outout_bind', ['dim_output_bind.ini'])],
|
||||||
|
install_requires=['dimclient>=0.4.2'])
|
Loading…
Reference in New Issue