Skip to content

Instantly share code, notes, and snippets.

@ddollar
Created September 22, 2009 23:12
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 ddollar/191528 to your computer and use it in GitHub Desktop.
Save ddollar/191528 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# requires the rick-linode gem
require 'rubygems'
require 'activeresource'
require 'linode'
SLICEHOST_KEY = ''
LINODE_KEY = ''
SOA_EMAIL = ''
module Slicehost
class Zone < ActiveResource::Base
self.site = "https://#{SLICEHOST_KEY}@api.slicehost.com/"
end
class Record < ActiveResource::Base
self.site = "https://#{SLICEHOST_KEY}@api.slicehost.com/"
end
end
def linode
@linode ||= Linode.new(:api_key => LINODE_KEY)
end
def linode_domains
linode.domain.list
end
def slicehost_domains
Slicehost::Zone.find(:all)
end
def clear_linode_domains
linode.domain.list.each do |linode_domain|
linode.domain.delete(:DomainID => linode_domain.domainid)
end
end
def migrate_domain(slicehost_domain)
domain = slicehost_domain.origin.gsub(/\.$/, '')
linode_domain = linode.domain.create({
:Type => 'master',
:Domain => domain,
:SOA_Email => SOA_EMAIL,
:TTL_sec => slicehost_domain.ttl,
:status => (slicehost_domain.active == 'Y' ? '1' : '3')
})
slicehost_records = Slicehost::Record.find(:all, :params => { :zone_id => slicehost_domain.id })
slicehost_records.each do |slicehost_record|
next if slicehost_record.record_type == 'NS'
name = slicehost_record.name.gsub(/\.$/, '')
name = '*' if slicehost_record.record_type == 'CNAME' && name == domain
linode.domain.resource.create({
:DomainID => linode_domain.domainid,
:Type => slicehost_record.record_type,
:Name => name,
:Target => slicehost_record.data.gsub(/\.$/, ''),
:Priority => slicehost_record.aux,
:TTL_sec => slicehost_record.ttl
})
end
puts slicehost_records.inspect
puts linode_domain.inspect
end
clear_linode_domains
slicehost_domains.each do |slicehost_domain|
migrate_domain slicehost_domain
end
puts linode_domains.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment