Add use of custom exceptions in zone transfers
This commit is contained in:
parent
5154dd4298
commit
ec1c07c191
|
@ -1,8 +1,11 @@
|
||||||
from BeautifulSoup import BeautifulStoneSoup as BS
|
from BeautifulSoup import BeautifulStoneSoup as BS
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from binder import exceptions
|
||||||
|
|
||||||
import dns.query
|
import dns.query
|
||||||
import dns.zone
|
import dns.zone
|
||||||
|
import dns.tsig
|
||||||
|
import keyutils
|
||||||
import re
|
import re
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
@ -51,10 +54,18 @@ class BindServer(models.Model):
|
||||||
def list_zone_records(self, zone):
|
def list_zone_records(self, zone):
|
||||||
"""Given a zone, produce an array of dicts containing
|
"""Given a zone, produce an array of dicts containing
|
||||||
each RR record and its attributes."""
|
each RR record and its attributes."""
|
||||||
|
if self.default_transfer_key:
|
||||||
|
keyring = keyutils.create_keyring(self.default_transfer_key.name,
|
||||||
|
self.default_transfer_key.data)
|
||||||
|
else:
|
||||||
|
keyring = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
zone = dns.zone.from_xfr(dns.query.xfr(self.hostname, zone))
|
zone = dns.zone.from_xfr(dns.query.xfr(self.hostname, zone, keyring=keyring))
|
||||||
except dns.exception.FormError:
|
except dns.exception.FormError, err:
|
||||||
raise Exception("There was an error attempting to retrieve zone %s on %s." % (zone, self.hostname))
|
raise exceptions.TransferException("There was an error attempting to list zone records.")
|
||||||
|
except dns.tsig.PeerBadKey:
|
||||||
|
raise exceptions.TransferException("Unable to list zone records because of a TSIG key mismatch.")
|
||||||
|
|
||||||
names = zone.nodes.keys()
|
names = zone.nodes.keys()
|
||||||
names.sort()
|
names.sort()
|
||||||
|
|
Loading…
Reference in New Issue