Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved record deletion performance #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions binder/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def add_cname_record(dns_server, zone_name, cname, originating_record, ttl, key_
return [{ "description" : "CNAME %s.%s points to %s" % (cname, zone_name, originating_record),
"output" : output}]

def delete_record(dns_server, rr_list, key_name):
def delete_record(dns_server, zone_name, rr_list, key_name):
"""Delete a list of DNS records passed as strings in rr_items."""

try:
Expand All @@ -92,17 +92,16 @@ def delete_record(dns_server, rr_list, key_name):
keyring = transfer_key.create_keyring()
algorithm = transfer_key.algorithm

delete_response = []
for current_rr in rr_list:
record_list = current_rr.split(".")
record = record_list[0]
domain = ".".join(record_list[1:])
dns_update = dns.update.Update(domain, keyring=keyring, keyalgorithm=algorithm)
dns_update.delete(record)
output = send_dns_update(dns_update, dns_server, key_name)

delete_response.append({ "description" : "Delete Record: %s" % current_rr,
"output" : output })
dns_update = dns.update.Update(zone_name, keyring=keyring, keyalgorithm=algorithm)
records = []
for resource_record in rr_list:
dns_update.delete(resource_record)
records.append("%s.%s" % (resource_record, zone_name))

output = send_dns_update(dns_update, dns_server, key_name)
delete_response = [{"description": "Deleted Records:<br/>%s" %
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refuse to put any sort of formatting of the data in the Python itself. Leave the output formatting for the templates.

'<br />'.join(records),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really fond of having output-formatting in the Python itself. Let the templates handle that.

This way also loses the ability to see a record-by-record accounting of failures and successes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree on the output formatting. It's just been a quick solution working with the current implementation of error handling in binder in general. I believe the error handling will need a complete overhaul anyway to be more precise and flexible. I intend to address that in future with another pull request.

Regarding the loss of the record-by-record accounting I'm not sure if that's worse than before, because all records which will be deleted belong to the same zone. So we know that if the key works for one of them, it works for the others too. And as the deletion of records even returns successfully if they are not existing, we don't loose information in such a case.

"output": output}]

return delete_response

Expand Down
2 changes: 1 addition & 1 deletion binder/templates/bcommon/list_zone.htm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<input type="hidden" name="zone_name" value="{{ zone_name }}">
{% for current_record in zone_array %}
<tr>
<td><input type="checkbox" name="rr_list" value="{{ current_record.rr_name }}.{{ zone_name }}"></td>
<td><input type="checkbox" name="rr_list" value="{{ current_record.rr_name }}"></td>
<td>{{ current_record.rr_name }}</td>
<td>{{ current_record.rr_ttl }}</td>
<td>{{ current_record.rr_class }}</td>
Expand Down
2 changes: 1 addition & 1 deletion binder/templates/bcommon/response_result.htm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<th>Output</th>
</tr>
<tr>
<td>{{ current_response.description }}</td>
<td>{{ current_response.description|safe }}</td>
<td><pre>{{ current_response.output }}</pre></td>
</tr>
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions binder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def view_delete_result(request):
print "in view_delete_result, form errors: %r" % form.errors

delete_result = helpers.delete_record(clean_form["dns_server"],
clean_form["zone_name"],
clean_form["rr_list"],
clean_form["key_name"])

Expand Down