mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
more ec2 in progress
This commit is contained in:
parent
f0876c31f7
commit
fcd28d3214
5 changed files with 99 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
20
spec/aws/ec2/describe_addresses.rb
Normal file
20
spec/aws/ec2/describe_addresses.rb
Normal file
|
@ -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
|
15
spec/aws/ec2/release_address_spec.rb
Normal file
15
spec/aws/ec2/release_address_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue