Skip to content

Instantly share code, notes, and snippets.

@wkf
Forked from bhauman/screw_you_zerigo.rb
Created January 3, 2014 14:22
Show Gist options
  • Save wkf/8238583 to your computer and use it in GitHub Desktop.
Save wkf/8238583 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'fog'
require 'zerigo_dns'
# A simple script to help you leave zerigo behind
# it relies on the excellent fog library http://fog.io/dns/
# It copies all of your Zerigo zones to DNSimple
# It is currently targeting DNSimple but fog supports many other
# providers.
# Using it is very satisfying
# after setting the correct connection settings
# just type
# ScrewYouZerigo.im_fucking.outa_here
class ScrewYouZerigo
attr_accessor :source, :destination
def initialize(source, destination)
@source = source
@destination = destination
end
def create_zone_hash(zone)
{ :domain => zone.domain,
:ttl => zone.ttl }
end
def create_record_hash(record)
[:value, :domain, :name, :ttl, :type ].inject({ }) { |accum, value|
accum[value] = record.send(value)
accum
}
end
def zones_to_move
Zerigo::DNS::Zone.all(:params => {:per_page => 999}).collect do |zz|
source.zones.get zz.domain
end
end
def copy_zone(zone)
new_zone = destination.zones.create(create_zone_hash(zone))
zone.records.each do |record|
new_zone.records.create(create_record_hash(record))
end
end
def outa_here
zones_to_move.each do |zone|
copy_zone(zone)
end
end
def ___reset_destination!
# this will delete freaking everything in the destination account
destination.zones.each &:destroy
end
def self.im_fucking
zemail = Zerigo::DNS::Base.user = 'XXXXXXXXXXXX' # CHANGE THIS
# the following is the Zerigo API token
zpassword = Zerigo::DNS::Base.password = "XXXXXXXXXXXXXX" # CHANGE THIS
ScrewYouZerigo.new(Fog::DNS.new({
:provider => 'Zerigo',
:zerigo_email => zemail,
:zerigo_token => zpassword
}),
Fog::DNS.new({
:provider => 'DNSimple',
:dnsimple_email => "XXXXXXXXXXXXX", # CHANGE THIS
# the following is your actual login password
:dnsimple_password => "XXXXXXXXXXXXX" # CHANGE THIS
}))
end
end
# unccoment the next line if you want this to be executable
# ScrewYouZerigo.im_fucking.outa_here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment