Permalink
Browse files

Finalizing Enhanced Elastic IPs.

  • Loading branch information...
schade committed Jan 9, 2013
1 parent d80a85a commit fafd019f9146bd6174f6907551382d47ffb2a326
Showing with 11 additions and 25 deletions.
  1. +11 −25 lib/ironfan/provider/ec2/elastic_ip.rb
@@ -23,7 +23,6 @@ def name() adaptee.public_ip ; end
def self.load!(cluster=nil)
Ec2.connection.addresses.each do |eip|
- pp eip
register eip
Chef::Log.debug("Loaded #{eip}")
@@ -34,42 +33,34 @@ def self.load!(cluster=nil)
if eip.public_ip.nil?
Chef::Log.debug( "no Elastic IPs currently allocated" )
else
- Chef::Log.debug( "#{eip}" )
- # Chef::Log.debug( "available ip match: #{eip.public_ip}" )
+ Chef::Log.debug( "available ip match: #{eip.public_ip}" )
+ Chef::Log.debug( "available allocation_id match: #{eip.allocation_id}" )
end
Chef::Log.debug( "----------------------" )
end
cluster.servers.each do |s|
- next if not s.ec2.include?(:elastic_ip)
+ next if s.ec2.elastic_ip.nil?
if recall? s.ec2.elastic_ip
Chef::Log.debug( "Cluster elastic_ip matches #{s.ec2.elastic_ip}" )
else
Chef::Log.debug( "No matching Elastic IP for #{s.ec2.elastic_ip}" )
end
- next if not s.ec2.include?(:allocation_id)
- if recall? s.ec2.allocation_id
- Chef::Log.debug( "Cluster Allocation ID matches #{s.ec2.allocation_id}" )
- else
- Chef::Log.debug( "No matching Allocation ID for #{s.ec2.allocation_id}" )
- end
end
end
#
# Manipulation
#
-Ec2.connection.associate_address( computer.machine.id, elastic_ip )
+
def self.save!(computer)
return unless computer.created?
# instead of just returning if the elastic_ip is blank we first test if the symbol exists and whether an actual
# address exists in the collection; All three require the presence of elastic_ip in the facet definition. We
# also, in the absence of an elastic_ip value, can use allocation_id to attach a VPC Elastic IP.
- return unless ( computer.server.ec2.include?(:elastic_ip) or computer.server.ec2.include?(:allocation_id) )
- ui.warn("can only specify one of either Elastic IP or Allocation ID; not both.") if info.blank?
- end
- if ( computer.server.ec2.elastic_ip.nil? and !computer.server.ec2.include?(:allocation_id) )
+ return unless computer.server.ec2.include?(:elastic_ip)
+ if ( computer.server.ec2.elastic_ip.nil? and cloud.vpc.nil? )
# First, :elastic_ip is set, no address is currently allocated for this connection's owner
# NOTE: We cannot specifiy an address to create, but after a reload we can then load the first available.
if computer.server.addresses.nil?
@@ -81,25 +72,20 @@ def self.save!(computer)
# Second, :elastic_ip is set, has an address available to use but has no set value available in facet definition.
elastic_ip = computer.server.addresses.first.public_ip
Chef::Log.debug( "using first available Elastic IP address" )
- elsif ( computer.server.ec2.include?(:elastic_ip) and !computer.server.ec2.include?(:allocation_id) )
+ end
+ elsif ( !computer.server.ec2.elastic_ip.nil? and cloud.vpc.nil? )
# Third, :elastic_ip is set, has an address available to use and has a set value available in facet definition.
elastic_ip = computer.server.ec2.elastic_ip
Chef::Log.debug( "using requested Elastic IP address" )
- elsif ( !computer.server.ec2.include?(:elastic_ip) and computer.server.ec2.include?(:allocation_id) )
- #Fourth, :elastic_ip is unset but :allocation_id is given in facet definition. (this is functionaility for attaching VPC Elastic IPS)
+ else ( computer.server.ec2.elastic_ip.nil? and !cloud.vpc.nil? )
+ # Fourth, is exactly like Third but on a VPC domain. (this is functionaility for attaching VPC Elastic IPS)
allocation_id = computer.server.ec2.allocation_id
Chef::Log.debug( "using Elastic IP address matched to given Allocation ID" )
- else
- ui.warn("can only specify one of either Elastic IP or Allocation ID; not both.")
end
- end
- return unless ( computer.server.ec2.include?(:allocation_id) and !computer.server.ec2.include(:elastic_ip)? )
- if computer.server.ec2.include?(:allocation_id)
- end
Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
Ironfan.unless_dry_run do
Ironfan.safely do
- if !computer.server.ec2.include?(:allocation_id)
+ if !cloud.vpc.nil?
Ec2.connection.associate_address( computer.machine.id, public_ip = elastic_ip )
else
Ec2.connection.associate_address( computer.machine.id, allocation_id = allocation_id )

0 comments on commit fafd019

Please sign in to comment.