Permalink
Browse files

FIXED: Elastic IP binding on startup (GH-40)

  • Loading branch information...
delano committed Dec 2, 2009
1 parent b49e742 commit 3893a5fe8d63af9a4d3dfc2e2d70e751c26cded5
Showing with 49 additions and 25 deletions.
  1. +1 −0 CHANGES.txt
  2. +4 −4 lib/rudy.rb
  3. +0 −15 lib/rudy/metadata/machine.rb
  4. +43 −6 lib/rudy/routines/handlers/host.rb
  5. +1 −0 lib/rudy/routines/startup.rb
View
@@ -4,6 +4,7 @@ RUDY, CHANGES
#### 0.9.6 (2009-10-??) ###########################
* FIXED: Include Gibbler for REXML
* FIXED: Elastic IP binding on startup (GH-40)
* CHANGE: Increased max instances from 5 to 20.
View
@@ -13,19 +13,19 @@
require 'digest/md5'
require 'stringio'
require 'ostruct'
autoload :YAML, 'yaml'
require 'yaml'
require 'logger'
require 'socket'
require 'resolv'
require 'timeout'
autoload :Gibbler, 'gibbler/aliases'
require 'gibbler/aliases'
require 'tempfile'
require 'rudy/mixins'
require 'storable'
autoload :SysInfo, 'sysinfo'
require 'sysinfo'
require 'attic'
require 'annoy'
autoload :Rye, 'rye'
require 'rye'
# = Rudy
#
@@ -158,21 +158,6 @@ def create
@state = inst.state
# We need to be safe when creating machines because if an exception is
# raised, instances will have been created but the calling class won't know.
begin
# Assign IP address only if we have one for that position
if @address
# Make sure the address is associated to the current account
if Rudy::AWS::EC2::Addresses.exists?(@address)
li "Associating #{@address} to #{@instid}"
Rudy::AWS::EC2::Addresses.associate(@address, @instid)
else
le "Unknown address: #{@address}"
end
end
rescue => ex
le "Error: #{ex.message}"
le ex.backtrace if Rudy.debug?
end
end
self.save
@@ -24,26 +24,63 @@ def is_running?(rset)
# it's also important to call here because if a routine was executed
# and an unexpected exception occurs before this update is executed
# the machine metadata won't contain the DNS information. Calling it
# here ensure that the metadata is always up-to-date.
# here ensures that the metadata is always up-to-date.
#
# If a machine has an associated elastic IP address, it will also be
# assigned in this step.
#
# Each Rye:Box instance has a Rudy::Machine instance in its stash so
# rbox.stash.refresh! == machine.refresh!
def update_dns(rset)
raise NoMachines if rset.boxes.empty?
rset.boxes.each do |rbox|
rbox.stash.refresh!
rbox.host = rbox.stash.dns_public
mach = rbox.stash
# Assign IP address only if we have one for that position
if mach.address
begin
# Make sure the address is associated to the current account
if Rudy::AWS::EC2::Addresses.exists?(mach.address)
li "Associating #{mach.address} to #{mach.instid}"
Rudy::AWS::EC2::Addresses.associate(mach.address, mach.instid)
else
le "Unknown address: #{mach.address}"
end
rescue => ex
le "Error associating address: #{ex.message}"
ld ex.backtrace
end
end
# Give EC2 some time to update their metadata
msg = "Waiting for public DNS on #{rbox.nickname} ..."
multi = rbox.stash.windows? ? 3 : 2
interval, max = 2*multi, 60*multi
Rudy::Utils.waiter(interval, max, STDOUT, msg, 0) {
mach.refresh!
if mach.address
mach.dns_public.to_s =~ /#{mach.address.to_s.gsub('.', '-')}/
else
!mach.dns_public.nil? && !mach.dns_public.empty?
end
}
rbox.host = mach.dns_public
end
end
def is_available?(rset, port=22)
raise NoMachines if rset.boxes.empty?
rset.boxes.each do |rbox|
mach = rbox.stash
# This updates the DNS. It's important this happens
# before and after the address is updated otherwise
# certain errors will causes it to not be updated.
mach.refresh!
msg = "Waiting for port #{port} on #{rbox.nickname} ..."
port = 3389 if rbox.stash.windows?
multi = rbox.stash.windows? ? 3 : 2
port = 3389 if mach.windows?
multi = mach.windows? ? 3 : 2
interval, max = 1*multi, 30*multi
Rudy::Utils.waiter(interval, max, STDOUT, msg, 0) {
Rudy::Utils.service_available?(rbox.stash.dns_public, port)
Rudy::Utils.service_available?(mach.dns_public, port)
}
end
end
@@ -72,6 +72,7 @@ def execute
# This is important b/c the machines will not
# have DNS info until after they are running.
# This will also assigns elastic IP addresses.
Rudy::Routines.rescue { Rudy::Routines::Handlers::Host.update_dns @@rset }
Rudy::Routines.rescue {

0 comments on commit 3893a5f

Please sign in to comment.