Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

196_elastic_ips #219

Merged
merged 20 commits into from
Dec 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e4c13fa
pushing minor changes from before start of feature code session
JerryWJackson Nov 7, 2012
8255f6f
Adding code to activate Elastic IPs to lib/ironfan/dsl/ec2.rb
JerryWJackson Nov 9, 2012
a15daae
Merge branch 'master' of https://github.com/infochimps-labs/ironfan
JerryWJackson Nov 9, 2012
1710c8d
Merge branch 'master' of https://github.com/infochimps-labs/ironfan
JerryWJackson Nov 14, 2012
414e149
added some more bits to recognize elastic ips; Ironfan still ignoring…
JerryWJackson Nov 15, 2012
714f53c
pushed still non-working state to repo for coop testing
JerryWJackson Nov 15, 2012
951b9dc
recent changes added to the mix; todo: fix missing method
JerryWJackson Nov 19, 2012
e6418e6
Elastic IP now attaches at launch time; still working on knife cluste…
JerryWJackson Nov 20, 2012
bfe0b9f
Merge pull request #1 from schade/feature/196_elastic_ips
Nov 20, 2012
f4e8485
added changes to various ec2 files for setting up basic elastic ip fu…
JerryWJackson Nov 27, 2012
5f269ba
Merge branch 'master' of https://github.com/infochimps-labs/ironfan i…
JerryWJackson Nov 28, 2012
2f6c7c4
We fixed the rather odd, broken adaptee problem; now working on actua…
JerryWJackson Nov 29, 2012
ce3dd0a
Merge branch 'master' of https://github.com/infochimps-labs/ironfan i…
JerryWJackson Dec 4, 2012
76448df
pushing changes that put us back in a state which completes the run w…
JerryWJackson Dec 6, 2012
8603763
push yesterday's changes to personal repo so that work can be done on…
JerryWJackson Dec 8, 2012
00aad33
Elastic IPs now properly attach at save/sync and are used when availa…
JerryWJackson Dec 10, 2012
94287ef
Elastic IPs now properly attach at save/sync and are used when availa…
JerryWJackson Dec 10, 2012
13e68a6
Merge pull request #2 from schade/feature/196_elastic_ips
Dec 10, 2012
cefc539
Continuing removal of miscellaneous bits used for testing during bug …
JerryWJackson Dec 10, 2012
468b81f
Merge branch 'develop' of https://github.com/schade/ironfan into develop
JerryWJackson Dec 10, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/knife.bash
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ _knife() {
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0 return 0
;; ;;
*knife_cluster_launch|*knife_cluster_show|*knife_cluster_edit)
_chef_completion_cache -c ${words[0]}_cluster "${words[0]} cluster list|awk '{ print $1 }'"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
*knife_environment_show|*knife_environment_edit|*knife_environment_delete) *knife_environment_show|*knife_environment_edit|*knife_environment_delete)
_chef_completion_cache -c ${words[0]}_environments "${words[0]} environment list|${SED} -r -e 's/[\"\ ,]//g' -e '/[^0-9A-Za-z._-]+/d'" _chef_completion_cache -c ${words[0]}_environments "${words[0]} environment list|${SED} -r -e 's/[\"\ ,]//g' -e '/[^0-9A-Za-z._-]+/d'"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
Expand Down
5 changes: 2 additions & 3 deletions lib/chef/knife/cluster_launch.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def run
section("Launching computers", :green) section("Launching computers", :green)
display(target) display(target)
launched = target.launch launched = target.launch

# As each server finishes, configure it # As each server finishes, configure it
Ironfan.parallel(launched) do |computer| Ironfan.parallel(launched) do |computer|
if (computer.is_a?(Exception)) then ui.warn "Error launching #{computer.inspect}; skipping after-launch tasks."; next; end if (computer.is_a?(Exception)) then ui.warn "Error launching #{computer.inspect}; skipping after-launch tasks."; next; end
Expand All @@ -107,7 +106,7 @@ def perform_after_launch_tasks(computer)
Ironfan.step(computer.name, 'waiting for ready', :white) Ironfan.step(computer.name, 'waiting for ready', :white)
# Wait for machine creation on amazon side # Wait for machine creation on amazon side
computer.machine.wait_for{ ready? } computer.machine.wait_for{ ready? }

# Try SSH # Try SSH
unless config[:dry_run] unless config[:dry_run]
Ironfan.step(computer.name, 'trying ssh', :white) Ironfan.step(computer.name, 'trying ssh', :white)
Expand All @@ -116,7 +115,7 @@ def perform_after_launch_tasks(computer)


Ironfan.step(computer.name, 'final provisioning', :white) Ironfan.step(computer.name, 'final provisioning', :white)
computer.save computer.save

# Run Bootstrap # Run Bootstrap
if config[:bootstrap] if config[:bootstrap]
Chef::Log.warn "UNTESTED --bootstrap" Chef::Log.warn "UNTESTED --bootstrap"
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/ironfan_knife_common.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'chef/knife' require 'chef/knife'


module Ironfan module Ironfan
module KnifeCommon module KnifeCommon
Expand Down
5 changes: 3 additions & 2 deletions lib/ironfan/dsl/ec2.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Ec2 < Cloud
magic :bootstrap_distro, String, :default => ->{ image_info[:bootstrap_distro] } magic :bootstrap_distro, String, :default => ->{ image_info[:bootstrap_distro] }
magic :chef_client_script, String magic :chef_client_script, String
magic :default_availability_zone, String, :default => ->{ availability_zones.first } 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 collection :elastic_load_balancers, Ironfan::Dsl::Ec2::ElasticLoadBalancer, :key_method => :name
magic :flavor, String, :default => 't1.micro' magic :flavor, String, :default => 't1.micro'
collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name
Expand All @@ -25,7 +26,7 @@ class Ec2 < Cloud
magic :permanent, :boolean, :default => false magic :permanent, :boolean, :default => false
magic :placement_group, String magic :placement_group, String
magic :provider, Whatever, :default => Ironfan::Provider::Ec2 magic :provider, Whatever, :default => Ironfan::Provider::Ec2
magic :public_ip, String magic :elastic_ip, String
magic :region, String, :default => ->{ default_region } magic :region, String, :default => ->{ default_region }
collection :security_groups, Ironfan::Dsl::Ec2::SecurityGroup, :key_method => :name collection :security_groups, Ironfan::Dsl::Ec2::SecurityGroup, :key_method => :name
magic :ssh_user, String, :default => ->{ image_info[:ssh_user] } magic :ssh_user, String, :default => ->{ image_info[:ssh_user] }
Expand Down Expand Up @@ -61,7 +62,7 @@ def to_display(style,values={})
values["AZ"] = default_availability_zone values["AZ"] = default_availability_zone
return values if style == :default return values if style == :default


values["Elastic IP"] = public_ip if public_ip values["Public IP"] = elastic_ip if elastic_ip
values values
end end


Expand Down
2 changes: 1 addition & 1 deletion lib/ironfan/provider/ec2.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Ec2 < Ironfan::IaasProvider
self.handle = :ec2 self.handle = :ec2


def self.resources def self.resources
[ Machine, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ] [ Machine, ElasticIp, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ]
end end


# #
Expand Down
73 changes: 73 additions & 0 deletions lib/ironfan/provider/ec2/elastic_ip.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,79 @@ class Provider
class Ec2 class Ec2


class ElasticIp < Ironfan::Provider::Resource 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=,
: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.elastic_ip ]
end

def name() adaptee.public_ip ; end

# FIXME: This is very broken, but somehow works around the breakage
def self.new(*args)
x = super
x.adaptee = args[0][:adaptee]
x
end

#
# 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
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 end
end end
Expand Down
9 changes: 4 additions & 5 deletions lib/ironfan/provider/ec2/machine.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def stop
def to_display(style,values={}) def to_display(style,values={})
# style == :minimal # style == :minimal
values["State"] = state.to_sym values["State"] = state.to_sym
values["MachineID"] = id values["MachineID"] = id
values["Public IP"] = public_ip_address values["Public IP"] = public_ip_address
values["Private IP"] = private_ip_address values["Private IP"] = private_ip_address
values["Created On"] = created_at.to_date values["Created On"] = created_at.to_date
return values if style == :minimal return values if style == :minimal
Expand Down Expand Up @@ -163,7 +163,7 @@ def self.create!(computer)


fog_server.wait_for { ready? } fog_server.wait_for { ready? }
end end

# tag the computer correctly # tag the computer correctly
tags = { tags = {
'cluster' => computer.server.cluster_name, 'cluster' => computer.server.cluster_name,
Expand Down Expand Up @@ -224,7 +224,6 @@ def self.launch_description(computer)
:client_key => computer.private_key :client_key => computer.private_key
} }



# Fog does not actually create tags when it creates a server; # Fog does not actually create tags when it creates a server;
# they and permanence are applied during sync # they and permanence are applied during sync
description = { description = {
Expand All @@ -236,7 +235,7 @@ def self.launch_description(computer)
:user_data => JSON.pretty_generate(user_data_hsh), :user_data => JSON.pretty_generate(user_data_hsh),
:block_device_mapping => block_device_mapping(computer), :block_device_mapping => block_device_mapping(computer),
:availability_zone => cloud.default_availability_zone, :availability_zone => cloud.default_availability_zone,
:monitoring => cloud.monitoring, :monitoring => cloud.monitoring
} }


# VPC security_groups can only be addressed by id (not name) # VPC security_groups can only be addressed by id (not name)
Expand Down
1 change: 1 addition & 0 deletions lib/ironfan/requirements.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
require 'ironfan/provider/ec2/keypair' require 'ironfan/provider/ec2/keypair'
require 'ironfan/provider/ec2/placement_group' require 'ironfan/provider/ec2/placement_group'
require 'ironfan/provider/ec2/security_group' require 'ironfan/provider/ec2/security_group'
require 'ironfan/provider/ec2/elastic_ip'
require 'ironfan/provider/ec2/elastic_load_balancer' require 'ironfan/provider/ec2/elastic_load_balancer'
require 'ironfan/provider/ec2/iam_server_certificate' require 'ironfan/provider/ec2/iam_server_certificate'


Expand Down