Permalink
Browse files

Merge pull request #219 from schade/develop

196_elastic_ips
  • Loading branch information...
2 parents b4efd4e + 468b81f commit 21dd0d506d26932789205f1ea3dd68def4449368 @temujin9 temujin9 committed Dec 10, 2012
View
@@ -129,6 +129,11 @@ _knife() {
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
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)
_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}) )
@@ -87,7 +87,6 @@ def run
section("Launching computers", :green)
display(target)
launched = target.launch
-
# 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
@@ -107,7 +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? }
-
+
# Try SSH
unless config[:dry_run]
Ironfan.step(computer.name, 'trying ssh', :white)
@@ -116,7 +115,7 @@ def perform_after_launch_tasks(computer)
Ironfan.step(computer.name, 'final provisioning', :white)
computer.save
-
+
# Run Bootstrap
if config[:bootstrap]
Chef::Log.warn "UNTESTED --bootstrap"
@@ -1,4 +1,4 @@
-require 'chef/knife'
+ require 'chef/knife'
module Ironfan
module KnifeCommon
@@ -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["Elastic IP"] = public_ip if public_ip
+ values["Public IP"] = elastic_ip if elastic_ip
values
end
@@ -5,7 +5,7 @@ class Ec2 < Ironfan::IaasProvider
self.handle = :ec2
def self.resources
- [ Machine, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ]
+ [ Machine, ElasticIp, EbsVolume, Keypair, SecurityGroup, IamServerCertificate, ElasticLoadBalancer ]
end
#
@@ -3,6 +3,79 @@ class Provider
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=,
+ :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
@@ -71,8 +71,8 @@ def stop
def to_display(style,values={})
# style == :minimal
values["State"] = state.to_sym
- values["MachineID"] = id
- values["Public IP"] = public_ip_address
+ values["MachineID"] = id
+ values["Public IP"] = public_ip_address
values["Private IP"] = private_ip_address
values["Created On"] = created_at.to_date
return values if style == :minimal
@@ -163,7 +163,7 @@ def self.create!(computer)
fog_server.wait_for { ready? }
end
-
+
# tag the computer correctly
tags = {
'cluster' => computer.server.cluster_name,
@@ -224,7 +224,6 @@ def self.launch_description(computer)
:client_key => computer.private_key
}
-
# Fog does not actually create tags when it creates a server;
# they and permanence are applied during sync
description = {
@@ -236,7 +235,7 @@ def self.launch_description(computer)
:user_data => JSON.pretty_generate(user_data_hsh),
:block_device_mapping => block_device_mapping(computer),
:availability_zone => cloud.default_availability_zone,
- :monitoring => cloud.monitoring,
+ :monitoring => cloud.monitoring
}
# VPC security_groups can only be addressed by id (not name)
@@ -35,6 +35,7 @@
require 'ironfan/provider/ec2/keypair'
require 'ironfan/provider/ec2/placement_group'
require 'ironfan/provider/ec2/security_group'
+require 'ironfan/provider/ec2/elastic_ip'
require 'ironfan/provider/ec2/elastic_load_balancer'
require 'ironfan/provider/ec2/iam_server_certificate'

0 comments on commit 21dd0d5

Please sign in to comment.