Skip to content

Commit

Permalink
Merge pull request #1 from schade/feature/196_elastic_ips
Browse files Browse the repository at this point in the history
Feature/196 elastic ips; non-final
  • Loading branch information
Jerry Jackson committed Nov 20, 2012
2 parents 1710c8d + e6418e6 commit bfe0b9f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/chef/knife/ironfan_knife_common.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'chef/knife'
require 'chef/knife'

module Ironfan
module KnifeCommon
Expand Down Expand Up @@ -140,6 +140,7 @@ def bootstrapper(computer)
bootstrap.name_args = [ hostname ]
bootstrap.config[:computer] = computer
bootstrap.config[:server] = server
bootstrap.config[:elastic_ip] = server.associate_address(elastic_ip)
bootstrap.config[:run_list] = server.run_list
bootstrap.config[:ssh_user] = config[:ssh_user] || computer.ssh_user
bootstrap.config[:attribute] = config[:attribute]
Expand Down
7 changes: 1 addition & 6 deletions lib/ironfan/dsl/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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 :elastic_ip String
magic :elastic_ip, String
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
Expand Down Expand Up @@ -47,11 +47,6 @@ def image_id
result = read_attribute(:image_id) || image_info[:image_id]
end

def elastic_ip(address)
Ironfan.safely do
Ironfan.fog_connection.associate_address(self.fog_server.id, address)
end

def ssh_key_name(computer)
keypair ? keypair.to_s : computer.server.cluster_name
end
Expand Down
7 changes: 7 additions & 0 deletions lib/ironfan/provider/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def self.connection
@@connection ||= Fog::Compute.new(self.aws_credentials.merge({ :provider => 'AWS' }))
end

def self.eip
c ||= Fog::Compute.new(self.aws_credentials.merge({ :provider => 'AWS' }))
address = c.addresses.create
address.server = server
server.reload
end

def self.elb
@@elb ||= Fog::AWS::ELB.new(self.aws_credentials)
end
Expand Down
19 changes: 19 additions & 0 deletions lib/ironfan/provider/ec2/elastic_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@ class Provider
class Ec2

class ElasticIp < Ironfan::Provider::Resource
delegate :allocate, :associate, :describe, :to => :adaptee
field :domain, String, :default => 'standard'

:associate

def address(ip)

end

def attach(ip, timeout)

end

def detach(ip, timeout)

end
end
end
end
end

# 'publicIp', 'domain'
# vpc use only = 'allocationId', 'associationId', 'instanceId', 'requestId'
5 changes: 4 additions & 1 deletion lib/ironfan/provider/ec2/machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def to_display(style,values={})
values["Volumes"] = volumes.map(&:id).join(', ')
values["SSH Key"] = key_name
values
pp(public_ip_address)
end

def ssh_key
Expand Down Expand Up @@ -159,6 +160,8 @@ 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?
# machine.ip = elastic_ip if elastic_ip
remember machine, :id => computer.name

fog_server.wait_for { ready? }
Expand Down Expand Up @@ -236,7 +239,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)
Expand Down
1 change: 1 addition & 0 deletions lib/ironfan/requirements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit bfe0b9f

Please sign in to comment.