Switch everything to Python
This commit is contained in:
42
dns-confgen
Executable file
42
dns-confgen
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import dnsmgr
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Generate Bind config files.')
|
||||
parser.add_argument('-c', '--config', help='path to config file', default=dnsmgr.DEFAULT_CFGFILE)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
manager = dnsmgr.DNSManager(cfgfile=args.config)
|
||||
except RuntimeError as e:
|
||||
dnsmgr.printe(f'config: {e}')
|
||||
sys.exit(100)
|
||||
|
||||
try:
|
||||
views = sorted(set([zone.view for zone in manager.zones]))
|
||||
|
||||
for view in views:
|
||||
print(f'Generate config of view \'{view}\'... ', end='')
|
||||
manager.generate_config(view)
|
||||
print('OK')
|
||||
|
||||
except RuntimeError as e:
|
||||
dnsmgr.printe(e)
|
||||
sys.exit(150)
|
||||
|
||||
print('Reloading named... ', end='')
|
||||
|
||||
try:
|
||||
manager.named_reload()
|
||||
print('OK')
|
||||
except RuntimeError as e:
|
||||
dnsmgr.printe(e)
|
||||
sys.exit(170)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user