diff options
author | Chris Moyer <kopertop@MacPro.local> | 2011-01-27 13:05:40 -0500 |
---|---|---|
committer | Chris Moyer <kopertop@MacPro.local> | 2011-01-27 13:05:40 -0500 |
commit | 8b65bfb68b581fdadd38efbae55420d8d407109d (patch) | |
tree | ef2769ed073e94fbc9009efa74972a1c6f7bcbc9 /bin/route53 | |
parent | 0ccfda5937e7e6fafb43c69981854aa5b9a7f6b7 (diff) | |
download | boto-8b65bfb68b581fdadd38efbae55420d8d407109d.tar.gz |
Updated Route53 connections to use the same XML parsing used elsewhere
in boto for RRsets. This is a backwards incompatible change to the
get_rrsets call in route53 connection, but it makes everything more
consistent with the other modules.
Also added a route53 command line client to make workging with Route53
a little easier.
Diffstat (limited to 'bin/route53')
-rwxr-xr-x | bin/route53 | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/bin/route53 b/bin/route53 new file mode 100755 index 00000000..7ca50978 --- /dev/null +++ b/bin/route53 @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# Author: Chris Moyer +# +# route53 is similar to sdbadmin for Route53, it's a simple +# console utility to perform the most frequent tasks with Route53 + +def _print_zone_info(zoneinfo): + print "="*80 + print "| ID: %s" % zoneinfo['Id'].split("/")[-1] + print "| Name: %s" % zoneinfo['Name'] + print "| Ref: %s" % zoneinfo['CallerReference'] + print "="*80 + print zoneinfo['Config'] + print + + +def create(conn, hostname, caller_reference=None, comment=''): + response = conn.create_hosted_zone(hostname, caller_reference, comment) + _print_zone_info(response['CreateHostedZoneResponse']) + +def ls(conn): + """List all hosted zones""" + response = conn.get_all_hosted_zones() + for zoneinfo in response['ListHostedZonesResponse']['HostedZones']: + _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) + 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""" + 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() + + +if __name__ == "__main__": + import boto + import sys + conn = boto.connect_route53() + self = sys.modules['__main__'] + if len(sys.argv) >= 2: + try: + cmd = getattr(self, sys.argv[1]) + except: + cmd = None + args = sys.argv[2:] + else: + cmd = help + args = [] + if not cmd: + cmd = help + try: + cmd(conn, *args) + except TypeError, e: + print e + help(conn, cmd.__name__) |