Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:boto/boto

  • Loading branch information...
commit a6e0c6e18d0a8218e3b1e69fbdd72b837702999d 2 parents 49fc662 + 89a69e6
Mitch Garnaat authored
Showing with 68 additions and 7 deletions.
  1. +37 −3 bin/route53
  2. +2 −2 boto/route53/connection.py
  3. +29 −2 boto/route53/record.py
View
40 bin/route53
@@ -15,8 +15,16 @@ def _print_zone_info(zoneinfo):
def create(conn, hostname, caller_reference=None, comment=''):
+ """Create a hosted zone, returning the nameservers"""
response = conn.create_hosted_zone(hostname, caller_reference, comment)
- _print_zone_info(response['CreateHostedZoneResponse'])
+ print "Pending, please add the following Name Servers:"
+ for ns in response.NameServers:
+ print "\t", ns
+
+def delete_zone(conn, hosted_zone_id):
+ """Delete a hosted zone by ID"""
+ response = conn.delete_hosted_zone(hosted_zone_id)
+ print response
def ls(conn):
"""List all hosted zones"""
@@ -25,20 +33,46 @@ def ls(conn):
_print_zone_info(zoneinfo)
def get(conn, hosted_zone_id, type=None, name=None, maxitems=None):
- response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems)
+ """Get all the records for a single zone"""
+ response = conn.get_all_rrsets(hosted_zone_id, type, name, maxitems=maxitems)
print '%-20s %-20s %-20s %s' % ("Name", "Type", "TTL", "Value(s)")
for record in response:
print '%-20s %-20s %-20s %s' % (record.name, record.type, record.ttl, ",".join(record.resource_records))
def add_record(conn, hosted_zone_id, name, type, value, ttl=600, comment=""):
- """Add a new record"""
+ """Add a new record to a zone"""
from boto.route53.record import ResourceRecordSets
changes = ResourceRecordSets(conn, hosted_zone_id, comment)
change = changes.add_change("CREATE", name, type, ttl)
change.add_value(value)
print changes.commit()
+def help(conn, fnc=None):
+ """Prints this help message"""
+ import inspect
+ self = sys.modules['__main__']
+ if fnc:
+ try:
+ cmd = getattr(self, fnc)
+ except:
+ cmd = None
+ if not inspect.isfunction(cmd):
+ print "No function named: %s found" % fnc
+ sys.exit(2)
+ (args, varargs, varkw, defaults) = inspect.getargspec(cmd)
+ print cmd.__doc__
+ print "Usage: %s %s" % (fnc, " ".join([ "[%s]" % a for a in args[1:]]))
+ else:
+ print "Usage: route53 [command]"
+ for cname in dir(self):
+ if not cname.startswith("_"):
+ cmd = getattr(self, cname)
+ if inspect.isfunction(cmd):
+ doc = cmd.__doc__
+ print "\t%s - %s" % (cname, doc)
+ sys.exit(1)
+
if __name__ == "__main__":
import boto
View
4 boto/route53/connection.py
@@ -213,7 +213,7 @@ def get_all_rrsets(self, hosted_zone_id, type=None,
:param maxitems: The maximum number of records
"""
- from boto.route53.record import Record
+ from boto.route53.record import ResourceRecordSets
params = {'type': type, 'name': name, 'maxitems': maxitems}
uri = '/%s/hostedzone/%s/rrset' % (self.Version, hosted_zone_id)
response = self.make_request('GET', uri, params=params)
@@ -223,7 +223,7 @@ def get_all_rrsets(self, hosted_zone_id, type=None,
raise exception.DNSServerError(response.status,
response.reason,
body)
- rs = ResultSet([('ResourceRecordSet', Record)])
+ rs = ResourceRecordSets(connection=self, hosted_zone_id=hosted_zone_id)
h = handler.XmlHandler(rs, self)
xml.sax.parseString(body, h)
return rs
View
31 boto/route53/record.py
@@ -22,7 +22,8 @@
RECORD_TYPES = ['A', 'AAAA', 'TXT', 'CNAME', 'MX', 'PTR', 'SRV', 'SPF']
-class ResourceRecordSets(object):
+from boto.resultset import ResultSet
+class ResourceRecordSets(ResultSet):
ChangeResourceRecordSetsBody = """<?xml version="1.0" encoding="UTF-8"?>
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/">
@@ -42,8 +43,10 @@ def __init__(self, connection=None, hosted_zone_id=None, comment=None):
self.connection = connection
self.hosted_zone_id = hosted_zone_id
self.comment = comment
- self.records = []
self.changes = []
+ self.next_record_name = None
+ self.next_record_type = None
+ ResultSet.__init__(self, [('ResourceRecordSet', Record)])
def __repr__(self):
return '<ResourceRecordSets: %s>' % self.hosted_zone_id
@@ -71,6 +74,30 @@ def commit(self):
self.connection = boto.connect_route53()
return self.connection.change_rrsets(self.hosted_zone_id, self.to_xml())
+ def endElement(self, name, value, connection):
+ """Overwritten to also add the NextRecordName and
+ NextRecordType to the base object"""
+ if name == 'NextRecordName':
+ self.next_record_name = value
+ elif name == 'NextRecordType':
+ self.next_record_type = value
+ else:
+ return ResultSet.endElement(self, name, value, connection)
+
+ def __iter__(self):
+ """Override the next function to support paging"""
+ results = ResultSet.__iter__(self)
+ while results:
+ for obj in results:
+ yield obj
+ if self.is_truncated:
+ self.is_truncated = False
+ results = self.connection.get_all_rrsets(self.hosted_zone_id, name=self.next_record_name, type=self.next_record_type)
+ else:
+ results = None
+
+
+
class Record(object):
"""An individual ResourceRecordSet"""
Please sign in to comment.
Something went wrong with that request. Please try again.