diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 7e9d0cd0a..76f73ae93 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -46,6 +46,27 @@ module Fog }, Fog::Parsers::AWS::EC2::AllocateAddress.new) end + def describe_addresses(public_ips) + params, index = {}, 1 + for public_ip in [*public_ips] + params["PublicIp.#{index}"] = public_ip + index += 1 + end + request){ + 'Action' => 'DescribeAddresses' + }.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new + end + + # Release an elastic IP address. + # + # ==== Returns + # Hash:: :return success boolean + def release_address(public_ip) + request({ + 'Action' => 'ReleaseAddress', + 'PublicIp' => public_ip + }, Fog::Parsers::AWS::EC2::ReleaseAddress.new) + private def request(params, parser) diff --git a/lib/fog/aws/ec2/parsers.rb b/lib/fog/aws/ec2/parsers.rb index e39df7c5f..55a57698b 100644 --- a/lib/fog/aws/ec2/parsers.rb +++ b/lib/fog/aws/ec2/parsers.rb @@ -16,6 +16,42 @@ module Fog end + class DescribeAddresses < Fog::Parsers::Base + + def reset + @address = {} + @response = { :addresses => [] } + end + + def end_element(name) + case name + when 'instanceId' + @address[:instance_id] = @value + when 'item' + @response[:addresses] << @address + @address = [] + when 'publicIp' + @address[:public_ip] = @value + end + end + + end + + class ReleaseAddress < Fog::Parsers::Base + + def end_element(name) + case name + when 'return' + if @value == 'true' + @response[:return] = true + else + @response[:return] = false + end + end + end + + end + end end end diff --git a/spec/aws/ec2/allocate_address_spec.rb b/spec/aws/ec2/allocate_address_spec.rb index 0f00c0c41..db88b4651 100644 --- a/spec/aws/ec2/allocate_address_spec.rb +++ b/spec/aws/ec2/allocate_address_spec.rb @@ -1,10 +1,15 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe 'EC2.batch_put_attributes' do +describe 'EC2.allocate_address' do + + after(:all) do + ec2.release_address(@public_ip) + end it "should return proper attributes" do actual = ec2.allocate_address - actual.body[:public_ip].should be_a(String) + @public_ip = actual.body[:public_ip] + @public_ip.should be_a(String) p actual end diff --git a/spec/aws/ec2/describe_addresses.rb b/spec/aws/ec2/describe_addresses.rb new file mode 100644 index 000000000..0678ce9ef --- /dev/null +++ b/spec/aws/ec2/describe_addresses.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.describe_addresses' do + + before(:all) do + @public_ip = ec2.allocate_address + end + + after(:all) do + ec2.release_address(@public_ip) + end + + it "should return proper attributes" do + actual = ec2.describe_addresses(@public_ip) + item = actual.body[:addresses].select {|address| address[:public_ip] == @public_ip} + item.should_not be_nil + p actual + end + +end diff --git a/spec/aws/ec2/release_address_spec.rb b/spec/aws/ec2/release_address_spec.rb new file mode 100644 index 000000000..d16641513 --- /dev/null +++ b/spec/aws/ec2/release_address_spec.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.release' do + + before(:all) do + @public_ip = ec2.allocate_address + end + + it "should return proper attributes" do + actual = ec2.release_address(@public_ip.body[:public_ip]) + actual.body[:return].should == true + p actual + end + +end