when adding host, deal with Timeout and NameServerNotAvailable exceptions
don't add the host, in case of dns exceptions
This commit is contained in:
parent
7436a8b578
commit
32d9f38837
@ -30,6 +30,9 @@ import dns.tsigkeyring
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
Timeout = dns.resolver.Timeout
|
||||
|
||||
|
||||
class SameIpError(ValueError):
|
||||
"""
|
||||
raised if an IP address is already present in DNS and and update was
|
||||
|
@ -103,11 +103,21 @@ class OverviewView(CreateView):
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save(commit=False)
|
||||
self.object.created_by = self.request.user
|
||||
self.object.save()
|
||||
dnstools.add(self.object.get_fqdn(), self.request.META['REMOTE_ADDR'], origin=self.object.domain.domain)
|
||||
messages.add_message(self.request, messages.SUCCESS, 'Host added.')
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
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.save()
|
||||
success, level, msg = True, messages.SUCCESS, 'Host added.'
|
||||
messages.add_message(self.request, level, msg)
|
||||
url = self.get_success_url() if success else reverse('overview')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
context = super(OverviewView, self).get_context_data(*args, **kwargs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user