when adding host, deal with Timeout and NameServerNotAvailable exceptions

don't add the host, in case of dns exceptions
This commit is contained in:
Thomas Waldmann 2013-11-01 22:26:06 +01:00
parent 7436a8b578
commit 32d9f38837
2 changed files with 18 additions and 5 deletions

View File

@ -30,6 +30,9 @@ import dns.tsigkeyring
from django.utils.timezone import now from django.utils.timezone import now
Timeout = dns.resolver.Timeout
class SameIpError(ValueError): class SameIpError(ValueError):
""" """
raised if an IP address is already present in DNS and and update was raised if an IP address is already present in DNS and and update was

View File

@ -103,11 +103,21 @@ class OverviewView(CreateView):
def form_valid(self, form): def form_valid(self, form):
self.object = form.save(commit=False) self.object = form.save(commit=False)
try:
dnstools.add(self.object.get_fqdn(), self.request.META['REMOTE_ADDR'], origin=self.object.domain.domain)
except dnstools.Timeout:
# XXX should be ERROR, but ERROR is white on web ui!?
success, level, msg = False, messages.WARNING, 'Timeout - communicating to name server failed.'
except dnstools.NameServerNotAvailable:
# XXX should be ERROR, but ERROR is white on web ui!?
success, level, msg = False, messages.WARNING, 'Name server unavailable.'
else:
self.object.created_by = self.request.user self.object.created_by = self.request.user
self.object.save() self.object.save()
dnstools.add(self.object.get_fqdn(), self.request.META['REMOTE_ADDR'], origin=self.object.domain.domain) success, level, msg = True, messages.SUCCESS, 'Host added.'
messages.add_message(self.request, messages.SUCCESS, 'Host added.') messages.add_message(self.request, level, msg)
return HttpResponseRedirect(self.get_success_url()) url = self.get_success_url() if success else reverse('overview')
return HttpResponseRedirect(url)
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(OverviewView, self).get_context_data(*args, **kwargs) context = super(OverviewView, self).get_context_data(*args, **kwargs)