def main(): usage = "usage: %prog <fqdn> [domain] <-c [cname] | -a [a record] | -A [Route 53 Alias]>" options, args = get_args(usage) if len(args) < 1 or len(args) > 2: print usage sys.exit(1) host = args[0] #host is fqdn if len(args) == 2: domain = args[1] #domain is zone else: subdomain_level = host.count('.') if subdomain_level > 1: domain = host.split('.', subdomain_level-1)[-1] else: #must be the domain root domain = host if not ( os.environ.has_key('AWS_ACCESS_ID') and os.environ.has_key('AWS_SECRET_KEY') ): log.error("Please set environment variables AWS_ACCESS_ID and AWS_SECRET_KEY") sys.exit(1) access_id = os.environ['AWS_ACCESS_ID'] secret_key = os.environ['AWS_SECRET_KEY'] if options.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.WARN) if options.cname is not None: rtype = 'CNAME' value = options.cname elif options.arecord is not None: rtype = 'A' value = options.arecord elif options.alias is not None: rtype = 'A' value = 'Alias ' + options.alias else: print usage sys.exit(1) #Get the connection conn = boto.connect_route53(access_id, secret_key) r53zone = Zone(conn, domain) if not r53zone.exists(): log.error('Zone ' + domain + " doesn't exist!") sys.exit(2) existing = r53zone.get_host(host) if existing is None: r53zone.create_host(host, rtype, options.ttl, value) else: r53zone.update_host(host, rtype, options.ttl, existing, value)
def main(): options, args = get_args() if options.debug: log.setLevel(logging.DEBUG) elif options.verbose: log.setLevel(logging.INFO) elif options.quite: log.setLevel(logging.ERROR) else: log.setLevel(logging.WARN) #Pull from the yaml file def_file = open(args[0], 'r') dns_def = yaml.load(def_file) zones = dns_def['zones'] #Get the connection conn = boto.connect_route53(dns_def['access_id'], dns_def['secret_key']) if options.dry_run: log.warn("Doing a dry-run, only reporting actions.") for name, zone_file in zones.iteritems(): r53zone = Zone(conn, name) if r53zone.exists(): if options.terminate: r53zone.remove(options.dry_run) elif options.show: print str(r53zone) else: r53zone.update(zone_file, options.dry_run) elif options.show or options.terminate: log.warn('Zone %s does not exist' % (name)) else: r53zone.create(zone_file, options.dry_run)