Instantly share code, notes, and snippets.

Embed
What would you like to do?
Zerigo's recent rate increase will raise my yearly cost 5000% so I created this lovely little script to help you leave Zerigo behind. It relies on the excellent fog library http://fog.io/dns/ It is currently targeting DNSimple but fog supports many other providers. Using it is very satisfying. After setting the correct connection settings just t…
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({ :name => "" }) { |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
@kazpsp

This comment has been minimized.

kazpsp commented Jan 29, 2014

Nice !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment