From 885b1068fece578a24d03da03613baf25e786bf7 Mon Sep 17 00:00:00 2001 From: Jeffrey Forman Date: Sun, 17 Apr 2011 07:35:02 -0400 Subject: [PATCH] Handle errors when trying to retrieve zone list from NS server --- binder/bcommon/views.py | 10 +++++++++- binder/templates/base.htm | 22 ++++++++++++++++++++++ binder/templates/bcommon/list_servers.htm | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/binder/bcommon/views.py b/binder/bcommon/views.py index 8b7388e..b677027 100644 --- a/binder/bcommon/views.py +++ b/binder/bcommon/views.py @@ -25,7 +25,15 @@ def list_server_zones(request, dns_hostname): # I should take the dns_hostname here, get the object from the DB, # and use the status port attribute for the urllib2 query. myreq = urllib2.Request("http://%s:853" % dns_hostname) - http_request = urllib2.urlopen(myreq) + try: + http_request = urllib2.urlopen(myreq) + except urllib2.URLError, err_reason: # Error retrieving zone list. + server_list = BindServer.objects.all().order_by('hostname') + return render_to_response('bcommon/list_servers.htm', + { 'server_list' : server_list, + 'errors' : err_reason, + 'error_context' : "Trying to retrieve zone list from %s" % dns_hostname}) + xmloutput = http_request.read() mysoup = BS(xmloutput) zones = mysoup.findAll('zone') diff --git a/binder/templates/base.htm b/binder/templates/base.htm index 8518e63..9a1df8f 100644 --- a/binder/templates/base.htm +++ b/binder/templates/base.htm @@ -8,6 +8,28 @@ {% endblock header %} +{% block errors %} + +{% if errors %} +
+ Errors were encountered: +
+ + {{ errors }} + + {% if error_context %} +
+ {{ error_context }} + {% endif %} + +
+{% endif %} + + + +{% endblock errors %} + +
{% block body %} {% endblock body %} diff --git a/binder/templates/bcommon/list_servers.htm b/binder/templates/bcommon/list_servers.htm index d04d85b..b779c87 100644 --- a/binder/templates/bcommon/list_servers.htm +++ b/binder/templates/bcommon/list_servers.htm @@ -2,6 +2,7 @@ {% block body %} DNS Server List: +