1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

finishing up address mocks

This commit is contained in:
Wesley Beary 2009-08-14 11:28:57 -07:00
parent 7dffa3db46
commit 7d70746c23
4 changed files with 62 additions and 27 deletions

View file

@ -175,7 +175,7 @@ module Fog
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
if Fog.mocking?
@data = { :addresses => [] }
@data = { 'addressesSet' => [] }
end
end

View file

@ -31,9 +31,10 @@ else
response = Fog::Response.new
response.status = 200
data ={
'publicIp' => Fog::AWS::Mock.ip_address
'instanceId' => '',
'publicIp' => Fog::AWS::Mock.ip_address
}
@data[:addresses] << data
@data['addressesSet'] << data
response.body = {
'publicIp' => data['publicIp'],
'requestId' => Fog::AWS::Mock.request_id

View file

@ -1,26 +1,60 @@
module Fog
module AWS
class EC2
unless Fog.mocking?
module Fog
module AWS
class EC2
# Describe all or specified IP addresses.
#
# ==== Parameters
# * public_ip<~Array> - List of ips to describe, defaults to all
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'addressesSet'<~Array>:
# * 'instanceId'<~String> - instance for ip address
# * 'publicIp'<~String> - ip address for instance
def describe_addresses(public_ip = [])
params = indexed_params('PublicIp', public_ip)
request({
'Action' => 'DescribeAddresses'
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
end
# Describe all or specified IP addresses.
#
# ==== Parameters
# * public_ip<~Array> - List of ips to describe, defaults to all
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'addressesSet'<~Array>:
# * 'instanceId'<~String> - instance for ip address
# * 'publicIp'<~String> - ip address for instance
def describe_addresses(public_ip = [])
params = indexed_params('PublicIp', public_ip)
request({
'Action' => 'DescribeAddresses'
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
end
end
end
else
module Fog
module AWS
class EC2
def describe_addresses(public_ip = [])
public_ip = [*public_ip]
response = Fog::Response.new
if public_ip != []
addresses_set = @data['addressesSet'].select {|address| public_ip.include?(address['publicIp'])}
else
addresses_set = @data['addressesSet']
end
if public_ip.length == 0 || public_ip.length == addresses_set.length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'addressesSet' => addresses_set
}
else
response.status = 400
end
response
end
end
end
end
end

View file

@ -30,9 +30,9 @@ else
def release_address(public_ip)
response = Fog::Response.new
initial_addresses_count = @data[:addresses].length
@data[:addresses].delete_if {|address| address['publicIp'] == public_ip}
if initial_addresses_count > @data[:addresses].length
initial_addresses_count = @data['addressesSet'].length
@data['addressesSet'].delete_if {|address| address['publicIp'] == public_ip}
if initial_addresses_count > @data['addressesSet'].length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,