From 26a911824d37668f861fd650f8ef67ba4ea7ee39 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 29 Sep 2013 01:28:49 +0200 Subject: [PATCH 1/3] pep8 fixes --- nsupdate/api/views.py | 2 +- nsupdate/main/urls.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 97c8962..416ca28 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -24,7 +24,7 @@ def UpdateIpView(request): af = dns.inet.af_for_address(ipaddr) key = 'ipv4' if af == dns.inet.AF_INET else 'ipv6' request.session[key] = ipaddr - image_data = open(settings.STATIC_ROOT+"/1px.gif", "rb").read() + image_data = open(os.path.join(settings.STATIC_ROOT, "1px.gif"), "rb").read() return HttpResponse(image_data, mimetype="image/png") diff --git a/nsupdate/main/urls.py b/nsupdate/main/urls.py index c5fd914..2e2f3b3 100644 --- a/nsupdate/main/urls.py +++ b/nsupdate/main/urls.py @@ -1,12 +1,10 @@ from django.conf.urls import patterns, include, url -from main.views import ( - HomeView, OverviewView, HostView, DeleteHostView, -) -from api.views import ( - MyIpView, UpdateIpView, NicUpdateView -) +from main.views import HomeView, OverviewView, HostView, DeleteHostView +from api.views import MyIpView, UpdateIpView, NicUpdateView -urlpatterns = patterns('', + +urlpatterns = patterns( + '', url(r'^$', HomeView.as_view(), name="home"), url(r'^overview/$', OverviewView.as_view(), name='overview'), url(r'^host/(?P\d+)/$', HostView.as_view(), name='host_view'), From 0a297b04ee649c797460adddfc034f51de8296e3 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 29 Sep 2013 01:59:47 +0200 Subject: [PATCH 2/3] style fix: use with with open, os.path.join for pathes --- nsupdate/api/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 416ca28..ffac467 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -24,7 +24,8 @@ def UpdateIpView(request): af = dns.inet.af_for_address(ipaddr) key = 'ipv4' if af == dns.inet.AF_INET else 'ipv6' request.session[key] = ipaddr - image_data = open(os.path.join(settings.STATIC_ROOT, "1px.gif"), "rb").read() + with open(os.path.join(settings.STATIC_ROOT, "1px.gif"), "rb") as f: + image_data = f.read() return HttpResponse(image_data, mimetype="image/png") From 726a5696bd4d5cb20d21709a4045b27005dd5306 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 29 Sep 2013 02:00:15 +0200 Subject: [PATCH 3/3] added docstring --- nsupdate/main/dnstools.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nsupdate/main/dnstools.py b/nsupdate/main/dnstools.py index c7aeaac..eb11198 100644 --- a/nsupdate/main/dnstools.py +++ b/nsupdate/main/dnstools.py @@ -21,6 +21,15 @@ class SameIpError(ValueError): def update(fqdn, ipaddr, ttl=60): + """ + intelligent dns updater - first does a lookup on the master server to find + the current ip and only sends a dynamic update if we have a different ip. + + :param fqdn: fully qualified domain name (str) + :param ipaddr: new ip address + :param ttl: time to live, default 60s (int) + :raises: SameIpError if new and old IP is the same + """ af = dns.inet.af_for_address(ipaddr) rdtype = 'A' if af == dns.inet.AF_INET else 'AAAA' try: