Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More work on deletion logic.

  • Loading branch information...
commit 2e7e6fa534faad7b52dff117f5d25d62fd6ff2db 1 parent 2034b84
Greg Taylor authored
34 route53/hosted_zone.py
View
@@ -35,6 +35,8 @@ def __init__(self, connection, id, name, caller_reference,
# Don't access this directly, we use it for lazy loading.
self._nameservers = []
+ # This is set to True when this HostedZone has been deleted in Route53.
+ self._is_deleted = False
def __str__(self):
return '<HostedZone: %s -- %s>' % (self.name, self.id)
@@ -74,16 +76,42 @@ def record_sets(self):
for rrset in self.connection.list_resource_record_sets_by_zone_id(self.id):
yield rrset
- def delete(self):
+ def delete(self, force=False):
"""
- Deletes this hosted zone.
+ Deletes this hosted zone. After this method is ran, you won't be able
+ to add records, or do anything else with the zone. You'd need to
+ re-create it, as zones are read-only after creation.
+ :keyword bool force: If ``True``, delete the HostedZone, even if it
+ means nuking all associated record sets. If ``False``, an
+ exception is raised if this HostedZone has record sets.
:rtype: dict
:returns: A dict of change info, which contains some details about
the request.
"""
- return self.connection.delete_hosted_zone_by_id(self.id)
+ if force:
+ # Forcing deletion by cleaning up all record sets first. We'll
+ # do it all in one change set.
+ cset = ChangeSet(connection=self.connection, hosted_zone_id=self.id)
+
+ for rrset in self.record_sets:
+ # You can delete a HostedZone if there are only SOA and NS
+ # entries left. So delete everything but SOA/NS entries.
+ if rrset.rrset_type not in ['SOA', 'NS']:
+ cset.add_change('DELETE', rrset)
+
+ if cset.deletions or cset.creations:
+ # Bombs away.
+ self.connection._change_resource_record_sets(cset)
+
+ # Now delete the HostedZone.
+ retval = self.connection.delete_hosted_zone_by_id(self.id)
+
+ # TODO: Eventually protect against adding records to a deleted instance.
+ self._is_deleted = True
+
+ return retval
def add_a_record(self, name, values, ttl=60):
"""
14 route53/resource_record_set.py
View
@@ -88,8 +88,18 @@ def save(self):
Saves any changes to this record set.
"""
- # TODO: Copy changes to self._initial_vals.
- pass
+ cset = ChangeSet(connection=self.connection, hosted_zone_id=self.zone_id)
+ cset.add_change('DELETE', self)
+ cset.add_change('CREATE', self)
+
+ retval = self.connection._change_resource_record_sets(cset)
+
+ # Now copy the current attribute values on this instance to
+ # the initial_vals dict. This will re-set the modification tracking.
+ for key, val in self._initial_vals.items():
+ self._initial_vals[key] = getattr(self, key)
+
+ return retval
def is_alias_record_set(self):
"""
1  route53/xml_generators/change_resource_record_set.py
View
@@ -68,7 +68,6 @@ def write_change(change):
e_resource_records = etree.SubElement(e_rrset, "ResourceRecords")
for value in change_vals['records']:
-
e_resource_record = etree.SubElement(e_resource_records, "ResourceRecord")
e_value = etree.SubElement(e_resource_record, "Value")
e_value.text = value
Please sign in to comment.
Something went wrong with that request. Please try again.