Internet Performance Delivered right to your inbox

How To Script Your Time-To-Live (TTL)

An interesting scenario was raised here the other day, something a few of our clients may be interested in:

“I have a segment of my site setup for a certain (time-to-live) TTL. It’s a little over 100 records spanning a number of fully qualified domains. What I would like to do is change the TTL on only these records as currently the time is a little too short for our needs since these records don’t change too often. The web UI is fine and dandy, but switching node-to-node and updating each record and then publishing it is getting pretty old. Is there a way I can do this quickly or in a batch?”

Well, for those of you who follow my blog posts (thanks Mom and Dad), you probably guessed that the first thing that springs to mind is to leverage the API for this. The way this was accomplished was by using Python to read a configuration file which would control what gets changed and how, then using the Python httplib to make the correct calls out to the robust DynECT API.

A Python “snake handler” of ours, Nguyen Tran, did the honors of the down and dirty work on this and it came out great! She used some simple parsing of the file along with basic logic to determine which API calls were needed and which zones they would be applied to.

This post will feature some details about the use of the actual script but if you would like to spelunk the code behind it, by all means, please take it and tweak it however you like and use it to make your DynECT DNS management as straight-forward as you can. That’s why we have the API and keep open sourcing different uses for it!

Controlling the script is all done through the input text file. The input file is pretty straight forward — it’s a plain text file consisting of three parts.

1)  The first line are your log in credentials separated by the pipe ( | ) symbol, as in customer_name|user_name|password.

2) The second line is simply the zone you are running this on (something like myzone.com)

3) Every line beyond that is formatted as an fqdn within the zone piped with the new TTL, piped with a “y” or “n” based on if you want sub nodes of the fqdn to be updated piped with the old TTL to be updated just in case you only want certain times updated or if you want to update them all. Here is an example of the setup of that file (with the 4th parameter included):

customer_name|user_name|password

TestZone.com

SubZone.TestZone.com|60|y|30

To run the script, you run the UpdateTTL.py module and it will ask you for the location of this configuration file and then perform the appropriate actions on the TTLs based on your config. Voila!

The only prerequisite for this script is that you have Python installed along with the httplib and JSON Python libraries. The Ubuntu 10.04 image this was built and tested on in the Amazon cloud had these installed already.

If this sounds cool to you, then go out and give it a try on on both Dyn and Nguyen’s Github accounts!


Share Now

Whois: Kevin Gray

Kevin Gray is a employee at Oracle Dyn Global Business Unit, a pioneer in managed DNS and a leader in cloud-based infrastructure that connects users with digital content and experiences across a global internet.