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 # Address
request :list_addresses request :list_addresses
request :list_address_pools
request :list_all_addresses request :list_all_addresses
request :list_private_addresses request :list_private_addresses
request :list_public_addresses request :list_public_addresses

View file

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

View file

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

View file

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

View file

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