Skip to content

Commit

Permalink
Version 1.5.4 of the AWS SDK for Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Jun 15, 2012
1 parent 1d15b8b commit d42dbe3
Show file tree
Hide file tree
Showing 9 changed files with 622 additions and 66 deletions.
498 changes: 444 additions & 54 deletions ca-bundle.crt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions features/ec2/elastic_ips.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ Feature: EC2 Elastic IPs
When I disassociate the elastic ip address
And I release the elastic ip address
Then the elastic ip should not exits

Scenario: Associating an elastic ip with a network interface
Given I create a vpc
And I create a subnet
And I create an internet gateway
And I attach the internet gateway to the vpc
And I create a network interface
And I allocate a VPC elastic ip
When I associate the network interface to the elastic ip
Then the elastic ip should be assigned to the network interface
# cleanup some (the normal test cleanup can get the rest)
When I disassociate the elastic ip address
And I release the elastic ip address
9 changes: 9 additions & 0 deletions features/ec2/step_definitions/elasic_ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@
@elastic_ip.exists?.should == false
end
end

When /^I associate the network interface to the elastic ip$/ do
@elastic_ip.associate :network_interface => @network_interface
end

Then /^the elastic ip should be assigned to the network interface$/ do
@elastic_ip.network_interface.should == @network_interface
end

1 change: 0 additions & 1 deletion lib/aws/api_config/EC2-2012-06-01.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
:inputs:
InstanceId:
- :string
- :required
PublicIp:
- :string
AllocationId:
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
module AWS

# Current version of the AWS SDK for Ruby
VERSION = "1.5.3"
VERSION = "1.5.4"

register_autoloads(self) do
autoload :Errors, 'errors'
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/ec2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Client < Core::Client
#
# === Options:
#
# * +:instance_id+ - *required* - (String) The instance to associate with
# * +:instance_id+ - (String) The instance to associate with
# the IP address.
# * +:public_ip+ - (String) IP address that you are assigning to the
# instance.
Expand Down
67 changes: 59 additions & 8 deletions lib/aws/ec2/elastic_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class EC2
# The ID representing the allocation of the address for use with Amazon
# VPC.
#
# @attr_reader [String] Indicates whether this elastic ip address is for
# EC2 instances ('standard') or VPC instances ('vpc').
# @attr_reader [String] domain Indicates whether this elastic ip address
# is for EC2 instances ('standard') or VPC instances ('vpc').
#
# @attr_reader [String,nil] The ID of the association between this elastic
# ip address and an EC2 VPC instance (VPC only).
# @attr_reader [String,nil] association_id The ID of the association
# between this elastic ip address and an EC2 VPC instance (VPC only).
#
# @attr_reader [String,nil] The ID of the network interface (VPC only).
# @attr_reader [String,nil] network_interface_id The ID of the network
# interface (VPC only).
#
# @attr_reader [String,nil] network_interface_owner_id
# The ID of the AWS account that owns the network interface (VPC only).
Expand Down Expand Up @@ -67,10 +68,10 @@ def vpc?
domain == 'vpc'
end

# @return [Boolean] Returns true if this IP address is attached to
# an EC2 instance.
# @return [Boolean] Returns true if this IP address is associated
# with an EC2 instance or a network interface.
def associated?
!!instance_id
!!(instance_id || association_id)
end

alias_method :attached?, :associated?
Expand All @@ -83,6 +84,15 @@ def instance
end
end

# @return [NetworkInterface,nil] Returns the network interface this
# elastic ip is associated with. Returns +nil+ if this is not
# associated with an elastic ip address.
def network_interface
if nid = network_interface_id
NetworkInterface.new(nid, :config => config)
end
end

# Releases the elastic IP address.
#
# (For non-VPC elastic ips) Releasing an IP address automatically
Expand All @@ -99,6 +109,47 @@ def delete
end
alias_method :release, :delete

# Associates this elastic IP address with an instance or a network
# interface. You may provide +:instance+ or +:network_interface+
# but not both options.
#
# # associate with an instance
# eip.associate :instance => 'i-12345678'
#
# # associate with a network interface
# eip.associate :network_interface => 'ni-12345678'
#
# @param [Hash] options
#
# @option options [String,Instance] :instance The id of an instance
# or an {Instance} object.
#
# @option options [String,NetworkInterface] :network_interface The id
# of a network interface or a {NetworkInterface} object.
#
# @return [String] Returns the resulting association id.
#
def associate options

client_opts = {}

[:instance,:network_interface].each do |opt|
if value = options[opt]
client_opts[:"#{opt}_id"] = value.is_a?(Resource) ? value.id : value
end
end

if vpc?
client_opts[:allocation_id] = allocation_id
else
client_opts[:public_ip] = public_ip
end

resp = client.associate_address(client_opts)
resp.data[:association_id]

end

# Disassociates this elastic IP address from an EC2 instance.
# Raises an exception if this elastic IP is not currently
# associated with an instance.
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/ec2/instance_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EC2
#
# To run an instance:
#
# ec2.instances.create(:image_id => "ami-8c1fece5")
# ec2.instances.create(:image_id => "ami-1b814f72")
#
# To get an instance by ID:
#
Expand Down
94 changes: 94 additions & 0 deletions spec/aws/ec2/elastic_ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,100 @@ def stub_member(resp, member)

end

context '#associate' do

let(:resp) { client.stub_for(:associate_address) }

before(:each) do
resp.data[:association_id] = 'assoc-id'
client.stub(:associate_address).and_return(resp)
end

context 'vpc elastic ips' do

let(:ip) {
ElasticIp.new('1.1.1.1',
:domain => 'vpc',
:allocation_id => 'alloc-id',
:config => config)
}

it 'accpets :instance with an instance object' do

client.should_receive(:associate_address).with(
:allocation_id => 'alloc-id',
:instance_id => 'i-12345678')

ip.associate :instance => Instance.new('i-12345678')

end

it 'accpets :instance with an instance id' do

client.should_receive(:associate_address).with(
:allocation_id => 'alloc-id',
:instance_id => 'i-12345678')

ip.associate :instance => 'i-12345678'

end

it 'accpets :network_interface with an id' do

client.should_receive(:associate_address).with(
:allocation_id => 'alloc-id',
:network_interface_id => 'ni-12345678')

ip.associate :network_interface => 'ni-12345678'

end

it 'accpets :network_interface with an object' do

client.should_receive(:associate_address).with(
:allocation_id => 'alloc-id',
:network_interface_id => 'ni-12345678')

ip.associate :network_interface => NetworkInterface.new('ni-12345678')

end

end

context 'regular elastic ips' do

let(:ip) {
ElasticIp.new('1.1.1.1', :domain => 'standard', :config => config)
}

it 'accpets :instance with an instance object' do

client.should_receive(:associate_address).with(
:public_ip => '1.1.1.1',
:instance_id => 'i-12345678')

ip.associate :instance => Instance.new('i-12345678')

end

it 'accpets :instance with an instance id' do

client.should_receive(:associate_address).with(
:public_ip => '1.1.1.1',
:instance_id => 'i-12345678')

ip.associate :instance => 'i-12345678'

end

it 'returns the association id' do
ip.associate(:instance => 'i-12345678').should == 'assoc-id'
end

end

end

context '#disassociate' do

it 'calls disassociate_address on the client' do
Expand Down

0 comments on commit d42dbe3

Please sign in to comment.