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

[openstack|compute] Update fetching of addresses and added fetching for address pools

This commit is contained in:
Alvin Garcia 2012-03-14 14:53:47 +08:00 committed by Nelvin Driz
parent 8d084194b4
commit 685eb85c1b
5 changed files with 17 additions and 10 deletions

View file

@ -96,6 +96,7 @@ module Fog
# Address
request :list_addresses
request :list_address_pools
request :list_all_addresses
request :list_private_addresses
request :list_public_addresses

View file

@ -35,7 +35,7 @@ module Fog
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
data = connection.allocate_address.body['floating_ip']
data = connection.allocate_address(pool).body['floating_ip']
new_attributes = data.reject {|key,value| !['id', 'instance_id', 'ip', 'fixed_ip'].include?(key)}
merge_attributes(new_attributes)
if @server

View file

@ -9,8 +9,8 @@ module Fog
model Fog::Compute::OpenStack::Address
def all(server_id)
load(connection.list_all_addresses(server_id).body['floating_ips'])
def all
load(connection.list_all_addresses.body['floating_ips'])
end
def get(address_id)
@ -21,6 +21,10 @@ module Fog
nil
end
def get_address_pools
connection.list_address_pools.body['floating_ip_pools']
end
end
end

View file

@ -3,7 +3,7 @@ module Fog
class OpenStack
class Real
def list_all_addresses(server_id)
def list_all_addresses
request(
:expects => [200, 203],
:method => 'GET',
@ -15,7 +15,7 @@ module Fog
end
class Mock
def list_all_addresses(server_id)
def list_all_addresses
response = Excon::Response.new
response.status = 200
response.headers = {

View file

@ -25,22 +25,24 @@ Shindo.tests('Fog::Compute[:openstack] | address requests', ['openstack']) do
Fog::Compute[:openstack].allocate_address.body
end
tests('#list_all_addresses(server_id)').formats({"floating_ips" => [@address_format]}) do
Fog::Compute[:openstack].list_all_addresses(@server.body['server']['id']).body
tests('#list_all_addresses').formats({"floating_ips" => [@address_format]}) do
Fog::Compute[:openstack].list_all_addresses.body
end
tests('#get_address(address_id)').formats({"floating_ip" => @address_format}) do
address_id = Fog::Compute[:openstack].addresses.all(Fog::Compute[:openstack].servers.last.id).first.id
address_id = Fog::Compute[:openstack].addresses.all.first.id
Fog::Compute[:openstack].get_address(address_id).body
end
Fog::Compute[:openstack].servers.get(@server.body['server']['id']).wait_for { ready? }
tests('#associate_address(server_id, ip_address)').succeeds do
address_ip = Fog::Compute[:openstack].addresses.all(Fog::Compute[:openstack].servers.last.id).first.ip
address_ip = Fog::Compute[:openstack].addresses.all.first.ip
Fog::Compute[:openstack].associate_address(@server.body['server']['id'], address_ip).body
end
tests('#disassociate_address(server_id, ip_address)').succeeds do
address_ip = Fog::Compute[:openstack].addresses.all(Fog::Compute[:openstack].servers.last.id).first.ip
address_ip = Fog::Compute[:openstack].addresses.all.first.ip
Fog::Compute[:openstack].disassociate_address(@server.body['server']['id'], address_ip).body
end
end