Permalink
Browse files

Merge branch 'feature/Elastic_IP_enhanced' of github.com:schade/ironfan

  • Loading branch information...
2 parents 4ced39f + 3de1652 commit 419aceba593f4054fcae5b989293da0e207ab6ce @temujin9 temujin9 committed Jan 14, 2013
Showing with 40 additions and 6 deletions.
  1. +2 −0 lib/ironfan/dsl/ec2.rb
  2. +38 −6 lib/ironfan/provider/ec2/elastic_ip.rb
@@ -26,6 +26,8 @@ class Ec2 < Cloud
magic :placement_group, String
magic :provider, Whatever, :default => Ironfan::Provider::Ec2
magic :elastic_ip, String
+ magic :auto_elastic_ip, String
+ magic :allocation_id, String
magic :region, String, :default => ->{ default_region }
collection :security_groups, Ironfan::Dsl::Ec2::SecurityGroup, :key_method => :name
magic :ssh_user, String, :default => ->{ image_info[:ssh_user] }
@@ -4,11 +4,11 @@ class Ec2
class ElasticIp < Ironfan::Provider::Resource
delegate :addresses, :associate_address, :allocation_id,
- :allocation_id=, :destroy, :domain, :domain=,
- :describe_addresses, :disassociate_address, :domain, :id,
- :network_interface_id, :network_interface_id=, :public_ip,
- :public_ip=, :public_ip_address, :save, :server=, :server, :server_id,
- :server_id=,
+ :allocation_id=, :allocate_address, :auto_elastic_ip, :destroy,
+ :domain, :domain=, :describe_addresses, :disassociate_address,
+ :domain, :id, :network_interface_id, :network_interface_id=,
+ :public_ip, :public_ip=, :public_ip_address, :save, :server=,
+ :server, :server_id, :server_id=,
:to => :adaptee
def self.shared?() true; end
@@ -30,7 +30,12 @@ def self.load!(cluster=nil)
# is passed to knife and aids in troubleshooting any refusal to
# attach Elastic IPs
Chef::Log.debug( "AWS domain: #{eip.domain}" )
- Chef::Log.debug( "available ip match: #{eip.public_ip}" )
+ if eip.public_ip.nil?
+ Chef::Log.debug( "no Elastic IPs currently allocated" )
+ else
+ Chef::Log.debug( "available ip match: #{eip.public_ip}" )
+ Chef::Log.debug( "available allocation_id match: #{eip.allocation_id}" )
+ end
Chef::Log.debug( "----------------------" )
end
@@ -53,6 +58,33 @@ def self.save!(computer)
return unless computer.created?
return unless elastic_ip = computer.server.ec2.elastic_ip
return unless recall? elastic_ip
+ # also, in the case of VPC Elastic IPs, can discover and use allocation_id to attach a VPC Elastic IP.
+ 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?
+ Ec2.connection.allocate_address
+ load!
+ elastic_ip = computer.server.addresses.first.public_ip
+ Chef::Log.debug( "allocating new Elastic IP address" )
+ else
+ # 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" )
+ end
+ elsif ( !computer.server.ec2.elastic_ip.nil? or cloud.vpc.nil? )
+ # Third, :elastic_ip is set, has an address available to use, has a set value in facet definition and is not VPC.
+ elastic_ip = computer.server.ec2.elastic_ip
+ Chef::Log.debug( "using requested Elastic IP address" )
+ elsif ( 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.fatal("You have set both :elastic_ip and :auto_elastic_ip in your facet definition; which are mutually exclusive.")
+ end
+ end
Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
Ironfan.unless_dry_run do
Ironfan.safely do

0 comments on commit 419aceb

Please sign in to comment.