Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaning up elastic_ip code

  • Loading branch information...
commit 906c243aa16acf54579ffc3c0dd30d8d6ab0e04c 1 parent 8fe3b04
Nathaniel Eliot temujin9 authored
2  lib/chef/knife/ironfan_knife_common.rb
View
@@ -1,4 +1,4 @@
- require 'chef/knife'
+require 'chef/knife'
module Ironfan
module KnifeCommon
3  lib/ironfan/dsl/ec2.rb
View
@@ -14,7 +14,6 @@ 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
@@ -35,6 +34,8 @@ class Ec2 < Cloud
magic :validation_key, String, :default => ->{ IO.read(Chef::Config.validation_key) rescue '' }
magic :vpc, String
+ def domain; vpc.nil? ? 'standard' : 'vpc'; end
+
def image_info
bit_str = "#{self.bits.to_i}-bit" # correct for legacy image info.
keys = [region, bit_str, backing, image_name]
54 lib/ironfan/provider/ec2/elastic_ip.rb
View
@@ -14,50 +14,35 @@ class ElasticIp < Ironfan::Provider::Resource
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 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)
+ def self.load!(cluster=nil)
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
+
+ # The rest of this definition shows relevant information when -VV
+ # 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}" )
+ Chef::Log.debug( "----------------------" )
+ end
+
+ cluster.servers.each do |s|
+ 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
end
+
end
#
@@ -65,9 +50,8 @@ def self.load!(cluster=nil, machine)
#
def self.save!(computer)
- return unless computer.machine?
- elastic_ip = computer.server.cloud(:ec2).elastic_ip
return unless computer.created?
+ elastic_ip = computer.server.ec2.elastic_ip
Ironfan.step(computer.name, "associating Elastic IP #{elastic_ip}", :blue)
Ironfan.unless_dry_run do
Ironfan.safely do
Please sign in to comment.
Something went wrong with that request. Please try again.