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:
parent
7dffa3db46
commit
7d70746c23
4 changed files with 62 additions and 27 deletions
|
@ -175,7 +175,7 @@ module Fog
|
||||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||||
|
|
||||||
if Fog.mocking?
|
if Fog.mocking?
|
||||||
@data = { :addresses => [] }
|
@data = { 'addressesSet' => [] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,10 @@ else
|
||||||
response = Fog::Response.new
|
response = Fog::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
data ={
|
data ={
|
||||||
'publicIp' => Fog::AWS::Mock.ip_address
|
'instanceId' => '',
|
||||||
|
'publicIp' => Fog::AWS::Mock.ip_address
|
||||||
}
|
}
|
||||||
@data[:addresses] << data
|
@data['addressesSet'] << data
|
||||||
response.body = {
|
response.body = {
|
||||||
'publicIp' => data['publicIp'],
|
'publicIp' => data['publicIp'],
|
||||||
'requestId' => Fog::AWS::Mock.request_id
|
'requestId' => Fog::AWS::Mock.request_id
|
||||||
|
|
|
@ -1,26 +1,60 @@
|
||||||
module Fog
|
unless Fog.mocking?
|
||||||
module AWS
|
|
||||||
class EC2
|
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
|
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
|
end
|
||||||
|
|
|
@ -30,9 +30,9 @@ else
|
||||||
|
|
||||||
def release_address(public_ip)
|
def release_address(public_ip)
|
||||||
response = Fog::Response.new
|
response = Fog::Response.new
|
||||||
initial_addresses_count = @data[:addresses].length
|
initial_addresses_count = @data['addressesSet'].length
|
||||||
@data[:addresses].delete_if {|address| address['publicIp'] == public_ip}
|
@data['addressesSet'].delete_if {|address| address['publicIp'] == public_ip}
|
||||||
if initial_addresses_count > @data[:addresses].length
|
if initial_addresses_count > @data['addressesSet'].length
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = {
|
response.body = {
|
||||||
'requestId' => Fog::AWS::Mock.request_id,
|
'requestId' => Fog::AWS::Mock.request_id,
|
||||||
|
|
Loading…
Reference in a new issue