11-Dec-09 00:26 Filed in:
GeekeryA couple of days ago Linode, the rather super VPS hosting chaps, announced the launch of their new London datacentre. Rather surprisingly the announcement also declared that it was available for immediate use. Now I’ve never really had a problem with the latency of my Linode hosted in the Newark datacentre, the datacentre generally recommended for us Euro types, as I was typically getting around 80ms response times, but I thought I’d check it out anyway. A quick ping to london1.linode.com and holy crap - 9ms response! After a brief scan of the small print (there’s no beta backup service in London yet btw) my mind was made up.
I fired off a request to Linode support to request a migration at 0:44am yesterday. Rather impressively I got a response from Danny, the newest member of the support team, at 0:45am - yes, ONE minute later OMG WTF? Even more amazingly the response wasn’t to say thanks for contacting us, we’ll look into it blah bah blah, it was to say that the migration was configured and ready to go as soon I logged in and hit the go button. Seriously impressive support.
I logged into Linode’s rather spiffy control panel and hit the go buttton. The migration started and the job status monitor told me it’d take around 50 mins for the virtual disk images to be sent down the tubes to London. It was getting late, it was a school night, and I had my annual appraisal in the morning (which went splendidly btw) - I snuck off to bed, desperately trying not to wake my wife up, to dream of electro clouds over London.
A rather hectic day at work meant no time to play until this evening. I logged into the control panel, hit the boot button, and voila, everything sprang back to life 3500 miles to the East of where I’d shut it down the night before. I logged onto the console, preparing to fiddle around with IP address changes, then realised that I’d configured the OS with DHCP so everything was already done and all services were already listening on the new IP address - woo! The only problem was that the 20 odd domains that I’ve got pointing at that box still had DNS entries pointing at the old IP address. Now as good as the Linode DNS control panel is, it doesn’t cater for mass cross domain IP address changes. Arse! OK perhaps support can whack the zone files through sed and save me a lot of clicking. I raised a ticket. Eight minutes later (slackers) I got a response from James telling me that unfortunately there was no way to do a batch change through the DNS manager, but that there is an API that should allow the process to be automated.
Oooh! APIs. I like APIs. I like them even more when someone else has already produced fairly comprehensive Perl bindings for them. A quick peruse of the docs and a batch DNS change looked relatively painless. Not much in the way of example code, but I’m a Perl genius, can’t be that hard to figure out. So I fired up CPAN to install WebService::Linode. Bugger, no Crypt::SSLeay installed. Install Crypt::SSLeay. Arse! No OpenSSL header files installed. sudo apt-get install libcrypt-ssleay-perl
Ah, that’s better. Back to CPAN, install WebService::Linode and there they were - lovely Perl bindings with that freshly installed module aroma. Time to fire up vim.
And lo, 15 minutes later (apologies for the layout, I just grabbed the syntax highlighter off the net and used default settings - I’ll fix it tomorrow): -
#!/usr/bin/perl
use warnings;
use strict;
use WebService::Linode;
$\="\n";
my $apiKey=''; # <<---- Insert your API Key here
my $oldIP='97.107.1.1'; # The old IP address that you wish to replace
my $newIP='109.74.2.2'; # The new IP address that you wish to replace it with
my $api = new WebService::Linode( apikey => $apiKey);
foreach my $domain (@{$api->domain_list}) {
print "$domain->{'domain'} $domain->{'domainid'}";
foreach my $domainResource (@{$api->domain_resource_list(domainid=>$domain->{'domainid'})}) {
if (($domainResource->{'type'} eq "A") && ($domainResource->{'target'} eq $oldIP)) {
print "Found an outdated entry : '$domainResource->{'name'}' $domainResource->{'resourceid'}";
$api->domain_resource_update(domainid=>$domain->{'domainid'},resourceid=>$domainResource->{'resourceid'},target=>$newIP);
}
}
}
Obviously the version I ran had a valid API key and my Linode’s actual old and new IP addresses, but that’s essentially it. I ran the script, fixed a couple of mis-matched brackets, ran the script again, and ooh blimey - it worked. A quick check in the DNS control panel and woohoo! Job done. A few minutes later and Linode’s name servers seem to have picked up the changes - super.
That was two hours ago. Now I sit, typing away at this blog entry, intermittently checking to see if the DNS changes have propagated to the rest of the world, wondering if I should have made the DNS changes manually. At least I’d have had something to do while the DNS TTL’s expired.
Tags: Linode, DNS, Perl