Permalink
Browse files

Adding exceptions raised when manipulating an already deleted HostedZ…

…one.
  • Loading branch information...
1 parent 2e7e6fa commit f2a22d160d2d8de726ba189c89711285c77f9fea @gtaylor committed Nov 4, 2012
Showing with 18 additions and 2 deletions.
  1. +9 −0 route53/exceptions.py
  2. +9 −2 route53/hosted_zone.py
View
@@ -6,3 +6,12 @@ class Route53Error(Exception):
"""
pass
+
+
+class AlreadyDeletedError(Route53Error):
+ """
+ Raised when the user tries to modify something on a hosted zone that
+ has been deleted in Route53.
+ """
+
+ pass
View
@@ -1,4 +1,5 @@
from route53.change_set import ChangeSet
+from route53.exceptions import AlreadyDeletedError
from route53.resource_record_set import AResourceRecordSet
class HostedZone(object):
@@ -90,6 +91,9 @@ def delete(self, force=False):
the request.
"""
+ if self._is_deleted:
+ raise AlreadyDeletedError('HostedZone is already deleted.')
+
if force:
# Forcing deletion by cleaning up all record sets first. We'll
# do it all in one change set.
@@ -100,15 +104,15 @@ def delete(self, force=False):
# 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.
+ # Used to protect against modifying a deleted HostedZone.
self._is_deleted = True
return retval
@@ -125,6 +129,9 @@ def add_a_record(self, name, values, ttl=60):
``rrset`` is the newly created AResourceRecordSet instance.
"""
+ if self._is_deleted:
+ raise AlreadyDeletedError("Can't add records to a deleted HostedZone.")
+
rrset = AResourceRecordSet(
connection=self.connection,
zone_id=self.id,

0 comments on commit f2a22d1

Please sign in to comment.