Skip to content

Instantly share code, notes, and snippets.

@lox
Created April 28, 2011 18:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lox/947028 to your computer and use it in GitHub Desktop.
Save lox/947028 to your computer and use it in GitHub Desktop.
Creating easy domain references to EC2 instances
#!/usr/bin/env ruby
require 'rubygems'
require 'fog'
ACCESS_KEY_ID='BLARGH'
SECRET_ACCESS_KEY='BLARGH'
ZERIGO_EMAIL='BLARGH'
ZERIGO_TOKEN='BLARGH'
ZERIGO_ZONE='BLARGH'
compute = Fog::Compute.new(
:provider => 'AWS',
:aws_access_key_id => ACCESS_KEY_ID,
:aws_secret_access_key => SECRET_ACCESS_KEY
)
dns = Fog::DNS.new(
:provider => 'Zerigo',
:zerigo_email => ZERIGO_EMAIL,
:zerigo_token => ZERIGO_TOKEN
)
zone = dns.zones.get ZERIGO_ZONE
compute.servers.each do |server|
if server.state == 'running' and server.tags.key? 'Name'
puts "mapping %s.%s to %s" % [server.tags['Name'], zone.domain, server.dns_name]
zone.records.create(
:ip => server.dns_name,
:name => '%s.%s' % [ server.tags['Name'], 'zone.domain' ],
:type => 'CNAME'
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment