work on issue 1, handle errors when querying server for list of zones
handles errors such as connection refused, no host found, etc.
This commit is contained in:
parent
a69baae308
commit
27a121ca0a
|
@ -0,0 +1,26 @@
|
||||||
|
import urllib2
|
||||||
|
from BeautifulSoup import BeautifulStoneSoup as BS
|
||||||
|
import re
|
||||||
|
|
||||||
|
def list_server_zones(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)
|
||||||
|
try:
|
||||||
|
http_request = urllib2.urlopen(myreq)
|
||||||
|
except urllib2.URLError, err_reason: # Error retrieving zone list.
|
||||||
|
return { 'errors' : err_reason, 'error_context' : "Trying to retrieve zone list from %s" % dns_hostname }
|
||||||
|
|
||||||
|
return_array = []
|
||||||
|
xmloutput = http_request.read()
|
||||||
|
mysoup = BS(xmloutput)
|
||||||
|
zones = mysoup.findAll('zone')
|
||||||
|
for current_zone in zones: # Interate over found zones
|
||||||
|
zone_name = current_zone.find('name').contents[0]
|
||||||
|
try: # Is this zone of 'IN' type?
|
||||||
|
in_zone = re.search(r"(.*)\/IN", zone_name).group(1)
|
||||||
|
return_array.append(in_zone)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return return_array
|
|
@ -3,10 +3,8 @@
|
||||||
from bcommon.models import BindServer
|
from bcommon.models import BindServer
|
||||||
from django.template import Context
|
from django.template import Context
|
||||||
from django.shortcuts import render_to_response, redirect
|
from django.shortcuts import render_to_response, redirect
|
||||||
|
from bcommon.helpers import list_server_zones
|
||||||
|
|
||||||
import urllib2
|
|
||||||
from BeautifulSoup import BeautifulStoneSoup as BS
|
|
||||||
import re
|
|
||||||
|
|
||||||
import dns.query
|
import dns.query
|
||||||
import dns.zone
|
import dns.zone
|
||||||
|
@ -21,30 +19,12 @@ def list_servers(request):
|
||||||
{ 'server_list' : server_list })
|
{ 'server_list' : server_list })
|
||||||
|
|
||||||
|
|
||||||
def list_server_zones(request, dns_hostname):
|
def view_server_zones(request, dns_hostname):
|
||||||
# I should take the dns_hostname here, get the object from the DB,
|
zone_array = list_server_zones(dns_hostname)
|
||||||
# and use the status port attribute for the urllib2 query.
|
if 'errors' in zone_array:
|
||||||
myreq = urllib2.Request("http://%s:853" % dns_hostname)
|
return render_to_response('bcommon/list_server_zones.htm',
|
||||||
try:
|
{ 'errors' : zone_array['errors'],
|
||||||
http_request = urllib2.urlopen(myreq)
|
'error_context' : zone_array['error_context'] })
|
||||||
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')
|
|
||||||
zone_array = []
|
|
||||||
for current_zone in zones: # Interate over found zones
|
|
||||||
zone_name = current_zone.find('name').contents[0]
|
|
||||||
try: # Is this zone of 'IN' type?
|
|
||||||
in_zone = re.search(r"(.*)\/IN", zone_name).group(1)
|
|
||||||
zone_array.append(in_zone)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return render_to_response('bcommon/list_server_zones.htm',
|
return render_to_response('bcommon/list_server_zones.htm',
|
||||||
{ 'zone_array' : zone_array,
|
{ 'zone_array' : zone_array,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "base.htm" %}
|
{% extends "base.htm" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
{% if not errors %}
|
||||||
DNS Server Zone List:
|
DNS Server Zone List:
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -8,5 +9,6 @@ DNS Server Zone List:
|
||||||
<li> <a href="/info/{{ dns_hostname }}/{{ current_zone }}/"> {{ current_zone }} </li>
|
<li> <a href="/info/{{ dns_hostname }}/{{ current_zone }}/"> {{ current_zone }} </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
{% extends "base.htm" %}
|
{% extends "base.htm" %}
|
||||||
|
|
||||||
|
|
||||||
{% block pageheader %}
|
{% block pageheader %}
|
||||||
Server List:
|
Server List:
|
||||||
{% endblock pageheader %}
|
{% endblock pageheader %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for current_server in server_list %}
|
{% for current_server in server_list %}
|
||||||
<li> <a href="/info/{{ current_server }}/"> {{ current_server }} </li>
|
<li> <a href="/info/{{ current_server }}/"> {{ current_server }} </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<a href="/info/">Server List</a>
|
<li><a href="/info/">Server List</a></li>
|
||||||
|
<li><a href="/modify/add_record">Add Resource Record</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% endblock body %}
|
{% endblock body %}
|
||||||
|
|
|
@ -9,7 +9,7 @@ urlpatterns = patterns('',
|
||||||
(r'^admin/', include(admin.site.urls)),
|
(r'^admin/', include(admin.site.urls)),
|
||||||
(r'^$', 'bcommon.views.home_index'),
|
(r'^$', 'bcommon.views.home_index'),
|
||||||
(r'^info/$', 'bcommon.views.list_servers'),
|
(r'^info/$', 'bcommon.views.list_servers'),
|
||||||
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/$', 'bcommon.views.list_server_zones'),
|
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/$', 'bcommon.views.view_server_zones'),
|
||||||
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/(?P<zone_name>[a-zA-Z0-9.-]+)/$', 'bcommon.views.list_zone'),
|
(r'^info/(?P<dns_hostname>[a-zA-Z0-9.-]+)/(?P<zone_name>[a-zA-Z0-9.-]+)/$', 'bcommon.views.list_zone'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue