Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 98 lines (86 sloc) 3.157 kb
#!/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=''):
"""Create a hosted zone, returning the nameservers"""
response = conn.create_hosted_zone(hostname, caller_reference, comment)
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"""
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):
"""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 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
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__)
Jump to Line
Something went wrong with that request. Please try again.