Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(tests): add route53 utility for wildcard domains
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy authored and mboersma committed Mar 13, 2015
1 parent e68d1ae commit 669ab53
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/bin/route53-wildcard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
"""
The route53-wildcard utility is used to add and remove wildcard
DNS entries from an AWS Route53 zonefile.
Usage: route53-wildcard.py <action> <name> <value> [options]
Options:
--zone=<zone> name of zone to use [defaults to parsing name]
--region=<region> AWS region to use [default: us-west-2].
--ttl=<ttl> record TTL to use [default: 60].
Examples:
./route53-wildcard.py create mycluster.gabrtv.io deis-elb.blah.amazonaws.com
./route53-wildcard.py delete mycluster.gabrtv.io deis-elb.blah.amazonaws.com
"""
import boto.route53
import docopt
import json
import subprocess
import time


def parse_args():
return docopt.docopt(__doc__)

def create_cname(args):
conn = boto.route53.connect_to_region(args['--region'])
zone = conn.get_zone(args['<zone>'])
status = zone.add_cname(args['<name>'], args['<value>'], ttl=args['--ttl'])
print("waiting for record to sync: {}".format(status))
while status.update() != "INSYNC":
time.sleep(2)
print(status)

def delete_cname(args, block=False):
conn = boto.route53.connect_to_region(args['--region'])
zone = conn.get_zone(args['<zone>'])
status = zone.delete_cname(args['<name>'])
if block:
print("waiting for record to sync: {}".format(status))
while status.update() != "INSYNC":
time.sleep(2)
print(status)

if __name__ == '__main__':
args = parse_args()

# calculate zone from provided name
zone = '.'.join(args['<name>'].split('.')[-2:])
args['<zone>'] = zone

# add a * to the provided name
args['<name>'] = u'\\052.'+unicode(args['<name>'])

if args['<action>'] == 'create':
create_cname(args)
elif args['<action>'] == 'delete':
delete_cname(args)
else:
raise NotImplementedError

0 comments on commit 669ab53

Please sign in to comment.