Skip to content

Commit

Permalink
FIXED: Elastic IP binding on startup (GH-40)
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Dec 2, 2009
1 parent b49e742 commit 3893a5f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ RUDY, CHANGES
#### 0.9.6 (2009-10-??) ########################### #### 0.9.6 (2009-10-??) ###########################


* FIXED: Include Gibbler for REXML * FIXED: Include Gibbler for REXML
* FIXED: Elastic IP binding on startup (GH-40)
* CHANGE: Increased max instances from 5 to 20. * CHANGE: Increased max instances from 5 to 20.




Expand Down
8 changes: 4 additions & 4 deletions lib/rudy.rb
Expand Up @@ -13,19 +13,19 @@
require 'digest/md5' require 'digest/md5'
require 'stringio' require 'stringio'
require 'ostruct' require 'ostruct'
autoload :YAML, 'yaml' require 'yaml'
require 'logger' require 'logger'
require 'socket' require 'socket'
require 'resolv' require 'resolv'
require 'timeout' require 'timeout'
autoload :Gibbler, 'gibbler/aliases' require 'gibbler/aliases'
require 'tempfile' require 'tempfile'
require 'rudy/mixins' require 'rudy/mixins'
require 'storable' require 'storable'
autoload :SysInfo, 'sysinfo' require 'sysinfo'
require 'attic' require 'attic'
require 'annoy' require 'annoy'
autoload :Rye, 'rye' require 'rye'


# = Rudy # = Rudy
# #
Expand Down
15 changes: 0 additions & 15 deletions lib/rudy/metadata/machine.rb
Expand Up @@ -158,21 +158,6 @@ def create
@state = inst.state @state = inst.state
# We need to be safe when creating machines because if an exception is # 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. # 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 end


self.save self.save
Expand Down
49 changes: 43 additions & 6 deletions lib/rudy/routines/handlers/host.rb
Expand Up @@ -24,26 +24,63 @@ def is_running?(rset)
# it's also important to call here because if a routine was executed # it's also important to call here because if a routine was executed
# and an unexpected exception occurs before this update is executed # and an unexpected exception occurs before this update is executed
# the machine metadata won't contain the DNS information. Calling it # 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 # Each Rye:Box instance has a Rudy::Machine instance in its stash so
# rbox.stash.refresh! == machine.refresh! # rbox.stash.refresh! == machine.refresh!
def update_dns(rset) def update_dns(rset)
raise NoMachines if rset.boxes.empty? raise NoMachines if rset.boxes.empty?
rset.boxes.each do |rbox| rset.boxes.each do |rbox|
rbox.stash.refresh! mach = rbox.stash
rbox.host = rbox.stash.dns_public # 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
end end


def is_available?(rset, port=22) def is_available?(rset, port=22)
raise NoMachines if rset.boxes.empty? raise NoMachines if rset.boxes.empty?
rset.boxes.each do |rbox| 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} ..." msg = "Waiting for port #{port} on #{rbox.nickname} ..."
port = 3389 if rbox.stash.windows? port = 3389 if mach.windows?
multi = rbox.stash.windows? ? 3 : 2 multi = mach.windows? ? 3 : 2
interval, max = 1*multi, 30*multi interval, max = 1*multi, 30*multi
Rudy::Utils.waiter(interval, max, STDOUT, msg, 0) { 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
end end
Expand Down
1 change: 1 addition & 0 deletions lib/rudy/routines/startup.rb
Expand Up @@ -72,6 +72,7 @@ def execute


# This is important b/c the machines will not # This is important b/c the machines will not
# have DNS info until after they are running. # 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 { Rudy::Routines::Handlers::Host.update_dns @@rset }


Rudy::Routines.rescue { Rudy::Routines.rescue {
Expand Down

0 comments on commit 3893a5f

Please sign in to comment.