A Pythonic method to managing PowerDNS via API calls.
This is being converted to Python3 and will change over time obiously.
Create a Python virtual environment to keep things clean.
python3 -m venv venv
source venv/bin/activate
Install Python requirements for using the script:
pip install -r requirements.txt
Install development Python requirements:
pip install -r requirements-dev.txt
- Zone: dev.vagrant.local
- ZoneType: MASTER
- Master: 192.168.202.200
- Nameservers:
- 192.168.202.200
- 192.168.202.201
- 192.168.202.202
python pdns.py add_zones --apihost 192.168.202.200 --zone dev.vagrant.local --zoneType MASTER --nameservers 192.168.202.200,192.168.202.201,192.168.202.202
We have included a Vagrant environment for testing and general usages. You can spin this up by:
cd Vagrant
vagrant up
Once the provisioning occurs, you will have a usable Vagrant environment with three nodes running PowerDNS. There are three in case you'd like to play with master/slave scenarios.
When you are done testing you can tear down the Vagrant environment by:
./cleanup.sh
- Zone: dev.vagrant.local
- ZoneType: SLAVE
- Master: 192.168.202.200
- Slaves:
- 192.168.202.201
- 192.168.202.202
python pdns.py add_zones --apihost 192.168.202.201 --zone dev.vagrant.local --zoneType SLAVE --masters 192.168.202.200
Create a examples/master_zones.csv similar to below:
zone,zoneType,masters,nameservers
128.28.172.in-addr.arpa,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
202.168.192.in-addr.arpa,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
dev.vagrant.local,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
prod.vagrant.local,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
test.vagrant.local,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
vagrant.local,MASTER,,"192.168.202.200,192.168.202.201,192.168.202.202"
The first row is the header...
Now read the csv file using CLI argument:
python pdns.py add_zones --apihost 192.168.202.200 --readcsv examples/master_zones.csv
- Zone: dev.vagrant.local
- name: test01.dev.vagrant.local
- recordType: A
- content: 192.168.202.161
- name: development.dev.vagrant.local
- recordType: CNAME
- content: test01.dev.vagrant.local
python pdns.py add_records --zone dev.vagrant.local --name test01 --content 192.168.202.161 --recordType A
python pdns.py add_records --zone dev.vagrant.local --name development --content test01.dev.vagrant.local --recordType CNAME
Create a examples/add_records.csv file similar to below:
name,zone,record_type,content,disabled,ttl,set_ptr,priority
development,test.vagrant.local,A,192.168.202.3,FALSE,3600,TRUE,0
mail,vagrant.local,CNAME,smtp.vagrant.local,FALSE,3600,TRUE,0
node0,test.vagrant.local,A,192.168.202.4,FALSE,3600,TRUE,0
node1,test.vagrant.local,A,192.168.202.5,FALSE,3600,TRUE,0
node100,test.vagrant.local,A,192.168.202.100,FALSE,3600,TRUE,0
node101,test.vagrant.local,A,192.168.202.101,FALSE,3600,TRUE,0
node102,test.vagrant.local,A,192.168.202.102,FALSE,3600,TRUE,0
node2,dev.vagrant.local,A,192.168.202.201,FALSE,3600,TRUE,0
node201,dev.vagrant.local,A,192.168.202.202,FALSE,3600,TRUE,0
node202,dev.vagrant.local,A,192.168.202.203,FALSE,3600,TRUE,0
node203,dev.vagrant.local,CNAME,node201.dev.vagrant.local,FALSE,3600,TRUE,0
smtp,vagrant.local,A,192.168.202.20,FALSE,3600,TRUE,0
The first row is the header...
Now read the csv file using CLI argument:
python pdns.py add_records --apihost 192.168.202.200 --readcsv examples/add_records.csv
- Zone: vagrant.local
- name: smtp.vagrant.local
- recordType: A
python pdns.py delete_records --apihost 192.168.202.200 --name smtp --zone vagrant.local --recordType A
Create a examples/delete_records.csv similar to below:
name,zone,record_type
node100,test.vagrant.local,A
node101,test.vagrant.local,A
node202,dev.vagrant.local,A
node203,dev.vagrant.local,CNAME
The first row is the header...
Now read the csv file using CLI argument:
python pdns.py delete_records --apihost 192.168.202.200 --readcsv examples/delete_records.csv
python pdns.py query_config --apihost 192.168.202.200
python pdns.py query_zones --apihost 192.168.202.200
MIT
Larry Smith Jr.