mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2699 from infochimps-labs/master
[openstack] Include auto-assigned IPs in floating_ip_addresses
This commit is contained in:
commit
7242293c25
3 changed files with 44 additions and 1 deletions
|
@ -103,6 +103,7 @@ module Fog
|
|||
def all_addresses
|
||||
# currently openstack API does not tell us what is a floating ip vs a fixed ip for the vm listing,
|
||||
# we fall back to get all addresses and filter sadly.
|
||||
# Only includes manually-assigned addresses, not auto-assigned
|
||||
@all_addresses ||= service.list_all_addresses.body["floating_ips"].select{|data| data['instance_id'] == id}
|
||||
end
|
||||
|
||||
|
@ -118,7 +119,22 @@ module Fog
|
|||
end
|
||||
|
||||
def floating_ip_addresses
|
||||
all_addresses.map{|addr| addr["ip"]}
|
||||
all_floating=addresses.values.flatten.select{ |data| data["OS-EXT-IPS:type"]=="floating" }.map{|addr| addr["addr"] }
|
||||
|
||||
# Return them all, leading with manually assigned addresses
|
||||
manual = all_addresses.map{|addr| addr["ip"]}
|
||||
|
||||
all_floating.sort{ |a,b|
|
||||
a_manual = manual.include? a
|
||||
b_manual = manual.include? b
|
||||
|
||||
if a_manual and !b_manual
|
||||
-1
|
||||
elsif !a_manual and b_manual
|
||||
1
|
||||
else 0 end
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
alias_method :public_ip_addresses, :floating_ip_addresses
|
||||
|
|
|
@ -12,6 +12,12 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def associate_address(server_id, ip_address)
|
||||
|
||||
server = data[:servers][server_id]
|
||||
server["addresses"]['mocknet'] ||= []
|
||||
ip_hash = {"OS-EXT-IPS-MAC:mac_addr"=>"fa:16:3e:85:47:40", "version"=>4, "addr"=>ip_address, "OS-EXT-IPS:type"=>"floating"}
|
||||
server["addresses"]['mocknet'] << ip_hash
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.headers = {
|
||||
|
|
|
@ -2,6 +2,27 @@ Shindo.tests("Fog::Compute[:openstack] | server", ['openstack']) do
|
|||
|
||||
tests('success') do
|
||||
|
||||
tests('#floating_ips').succeeds do
|
||||
fog = Fog::Compute[:openstack]
|
||||
net = Fog::Network[:openstack]
|
||||
flavor = fog.flavors.first.id
|
||||
image = fog.images.first.id
|
||||
|
||||
server = fog.servers.new(:name => 'test server',
|
||||
:flavor_ref => flavor,
|
||||
:image_ref => image)
|
||||
server.save
|
||||
|
||||
ip1 = net.floating_ips.create(:floating_network_id => 'f0000000-0000-0000-0000\
|
||||
-000000000000',
|
||||
:fixed_ip_address => '192.168.11.3')
|
||||
|
||||
server.associate_address(ip1.fixed_ip_address)
|
||||
server.reload
|
||||
|
||||
returns( ["192.168.11.3"] ) { server.floating_ip_addresses }
|
||||
end
|
||||
|
||||
tests('#security_groups').succeeds do
|
||||
fog = Fog::Compute[:openstack]
|
||||
|
||||
|
|
Loading…
Reference in a new issue