Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Created February 2, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithrandi/704248041ff1c37b8c28 to your computer and use it in GitHub Desktop.
Save mithrandi/704248041ff1c37b8c28 to your computer and use it in GitHub Desktop.
route53 update script for ip-up.d
#!/usr/bin/python
from os import environ
from socket import gethostname
from boto import connect_route53
from boto.route53.record import ResourceRecordSets
IF_NAME = 'ppp4'
AWS_ACCESS_KEY = '...'
AWS_SECRET_KEY = '...'
ZONE_ID = '...'
def main():
currentInterface = environ.get('PPP_IFACE')
if currentInterface:
if currentInterface != IF_NAME:
return
address = environ.get('PPP_LOCAL')
if not address:
return
hostname = gethostname()
conn = connect_route53(AWS_ACCESS_KEY, AWS_SECRET_KEY)
rrset = conn.get_all_rrsets(ZONE_ID, 'A', hostname, maxitems=1)[0]
if address not in rrset.resource_records:
changes = ResourceRecordSets(conn, ZONE_ID)
change1 = changes.add_change('DELETE', hostname, 'A', rrset.ttl)
for rr in rrset.resource_records:
change1.add_value(rr)
change2 = changes.add_change('CREATE', hostname, 'A', rrset.ttl)
change2.add_value(address)
changes.commit()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment