Permalink
Browse files

Elastic IPs now properly attach at save/sync and are used when availa…

…ble by 'knife cluster ssh' as requested.
  • Loading branch information...
1 parent 8603763 commit 00aad33cacb3789a7d2e9f214d34d8ed0bba059e @schade schade committed Dec 10, 2012
@@ -87,11 +87,6 @@ def run
section("Launching computers", :green)
display(target)
launched = target.launch
- pp computer.machine.addresses
- pp computer.machine.public_ip_address
- pp computer.machine.id
- raise hell
-
# As each server finishes, configure it
Ironfan.parallel(launched) do |computer|
if (computer.is_a?(Exception)) then ui.warn "Error launching #{computer.inspect}; skipping after-launch tasks."; next; end
@@ -111,9 +106,7 @@ def perform_after_launch_tasks(computer)
Ironfan.step(computer.name, 'waiting for ready', :white)
# Wait for machine creation on amazon side
computer.machine.wait_for{ ready? }
- pp computer.machine.id
- raise hell
-
+
# Try SSH
unless config[:dry_run]
Ironfan.step(computer.name, 'trying ssh', :white)
@@ -122,8 +115,7 @@ def perform_after_launch_tasks(computer)
Ironfan.step(computer.name, 'final provisioning', :white)
computer.save
- pp computer.machine.id
-
+
# Run Bootstrap
if config[:bootstrap]
Chef::Log.warn "UNTESTED --bootstrap"
View
@@ -14,6 +14,7 @@ class Ec2 < Cloud
magic :bootstrap_distro, String, :default => ->{ image_info[:bootstrap_distro] }
magic :chef_client_script, String
magic :default_availability_zone, String, :default => ->{ availability_zones.first }
+ magic :domain, String, :default => 'standard'
collection :elastic_load_balancers, Ironfan::Dsl::Ec2::ElasticLoadBalancer, :key_method => :name
magic :flavor, String, :default => 't1.micro'
collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name
@@ -25,7 +26,7 @@ class Ec2 < Cloud
magic :permanent, :boolean, :default => false
magic :placement_group, String
magic :provider, Whatever, :default => Ironfan::Provider::Ec2
- magic :public_ip, String
+ magic :elastic_ip, 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] }
@@ -61,7 +62,7 @@ def to_display(style,values={})
values["AZ"] = default_availability_zone
return values if style == :default
- values["Public IP"] = public_ip if public_ip
+ values["Public IP"] = elastic_ip if elastic_ip
values
end
View
@@ -31,7 +31,6 @@ def self.resources
def self.load(cluster)
Ironfan.parallel (resources) do |r|
type = r.resource_type.to_s
- pp type
r.forget!
Ironfan.substep(cluster.name, "loading #{type}s")
r.load! cluster
@@ -7,13 +7,17 @@ class ElasticIp < Ironfan::Provider::Resource
:allocation_id=, :destroy, :domain, :domain=,
:describe_addresses, :disassociate_address, :domain, :id,
:network_interface_id, :network_interface_id=, :public_ip,
- :public_ip=, :save, :server=, :server, :server_id, :server_id=,
+ :public_ip=, :public_ip_address, :save, :server=, :server, :server_id,
+ :server_id=,
:to => :adaptee
def self.shared?() true; end
def self.multiple?() false; end
def self.resource_type() :elastic_ip; end
- def self.expected_ids(computer) [ computer.server.ec2.public_ip ]; end
+
+ def self.expected_ids(computer)
+ [ computer.server.ec2.elastic_ip ]
+ end
def name() adaptee.public_ip ; end
@@ -24,15 +28,54 @@ def self.new(*args)
x
end
- def self.load!(cluster=nil)
+ #
+ # Discovery
+ #
+
+ def self.load!(cluster=nil, machine)
Ec2.connection.addresses.each do |eip|
register eip
Chef::Log.debug("Loaded #{eip}")
+ # The rest of this definition shows relevant information when -VV is passed to knife and aids in troubleshooting any refusal to attach Elastic IPs
+ machine.facets.each do |f|
+ unless f.servers[0].clouds[:ec2].elastic_ip.nil? or eip.domain == "vpc"
+ if eip.domain == "standard" and eip.public_ip == f.servers[0].clouds[:ec2].elastic_ip
+ Chef::Log.debug( "AWS domain: #{eip.domain}" )
+ Chef::Log.debug( "available ip match: #{eip.public_ip}" )
+ Chef::Log.debug( "----------------------" )
+ end
+ end
+ unless eip.public_ip.nil?
+ if eip.domain == "standard"
+ if eip.public_ip == f.servers[0].clouds[:ec2].elastic_ip
+ unless f.servers[0].clouds[:ec2].elastic_ip.nil?
+ Chef::Log.debug( "ip given by cluster definition: #{f.servers[0].clouds[:ec2].elastic_ip}" )
+ else
+ Chef::Log.debug( "No matching Elastic IP available to your account." )
+ end
+ end
+ end
+ end
+ end
end
- pp adaptee
end
-
+
+ #
+ # Manipulation
+ #
+
+ def self.save!(computer)
+ return unless computer.machine?
+ elastic_ip = computer.server.cloud(:ec2).elastic_ip
+ return unless computer.created?
+ Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
+ Ironfan.unless_dry_run do
+ Ironfan.safely do
+ Ec2.connection.associate_address( computer.machine.id, elastic_ip )
+ end
+ end
end
+
end
end
end
@@ -71,7 +71,7 @@ def stop
def to_display(style,values={})
# style == :minimal
values["State"] = state.to_sym
- values["MachineID"] = id
+ values["MachineID"] = id
values["Public IP"] = public_ip_address
values["Private IP"] = private_ip_address
values["Created On"] = created_at.to_date
@@ -102,12 +102,12 @@ def to_s
# Discovery
#
def self.load!(cluster=nil)
- raise hell
Ec2.connection.servers.each do |fs|
machine = new(:adaptee => fs)
if (not machine.created?)
next unless Ironfan.chef_config[:include_terminated]
remember machine, :append_id => "terminated:#{machine.id}"
+ raise hell
elsif recall? machine.name
machine.bogus << :duplicate_machines
recall(machine.name).bogus << :duplicate_machines
@@ -117,10 +117,6 @@ def self.load!(cluster=nil)
end
Chef::Log.debug("Loaded #{machine}")
end
- pp computer.machine.addresses
- pp computer.machine.public_ip_address
- pp computer.machine.id
- raise hell
end
def receive_adaptee(obj)
@@ -164,17 +160,11 @@ def self.create!(computer)
fog_server = Ec2.connection.servers.create(launch_desc)
machine = Machine.new(:adaptee => fog_server)
computer.machine = machine
- # set elastic_ip here?
- # computer.machine.associate_address = computer.server.ec2.public_ip unless computer.server.ec2.public_ip.nil?
remember machine, :id => computer.name
fog_server.wait_for { ready? }
end
- pp computer.machine.addresses
- pp computer.machine.public_ip_address
- pp computer.machine.id
- raise hell
-
+
# tag the computer correctly
tags = {
'cluster' => computer.server.cluster_name,
@@ -259,9 +249,9 @@ def self.launch_description(computer)
IamServerCertificate.recall(IamServerCertificate.full_name(computer, cert))
end.compact.map(&:name)
- description[:elastic_ip] = cloud.addresses.values.map do |eip|
- ElasticIp.recall(ElasticIp.associate_address(computer, eip))
- end.compact.map(&:name)
+# description[:elastic_ip] = cloud.addresses.values.map do |eip|
+# ElasticIp.recall(ElasticIp.associate_address(computer, eip))
+# end.compact.map(&:name)
description[:elastic_load_balancers] = cloud.elastic_load_balancers.values.map do |elb|
ElasticLoadBalancer.recall(ElasticLoadBalancer.full_name(computer, elb))
@@ -308,12 +298,6 @@ def self.save!(computer)
return unless computer.machine?
# the EC2 API does not surface disable_api_termination as a value, so we
# have to set it every time.
-
- pp computer.machine.addresses
- pp computer.machine.public_ip_address
- pp computer.machine.id
- raise hell
-
permanent = computer.server.cloud(:ec2).permanent
return unless computer.created?
Ironfan.step(computer.name, "setting termination flag #{permanent}", :blue)

0 comments on commit 00aad33

Please sign in to comment.