CommonThread - Our Blog

Recent Articles

Slicehost API Saves The Day

Slicehost API Saves The Day

Written By: Ben Wyrosdick

May 20th, 2008

Thanks to slicehost for giving me an API for managing my DNS zones and records via ActiveResource becauase it saved me lots of time and tedious work. I needed to update my TTL settings in all my domains and rather than having to edit all 61 entries I simply made a ruby script to do it for me:

require 'rubygems'
require 'activeresource'

API_PASSWORD = "MY_SECRET_PASSWORD" 
DEFAULT_TTL = 86400

class Record < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

records = Record.find(:all)

for record in records
  record.ttl = DEFAULT_TTL
  record.save
end

and while we are at it lets output all of our info:

require 'rubygems'
require 'activeresource'

API_PASSWORD = "MY_SECRET_PASSWORD" 

class Zone < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

class Record < ActiveResource::Base
  self.site = "https://#{API_PASSWORD}@api.slicehost.com/" 
end

zones = Zone.find(:all)
records = Record.find(:all)

for zone in zones
  puts "zone: #{zone.origin}" 

  for record in records.find_all{|record| record.zone_id == zone.id}
    puts "  #{record.record_type}: #{record.name} - #{record.data}" 
  end
end

There, that was easy.

1 Response to “Slicehost API Saves The Day”

  1. Matt Newcombe Says:
    Thanks for the ruby code. I need to get my records out of Slicehost's DNS servers and this will help.

Leave a Reply