Skip to content

Commit

Permalink
Floating IPs are now checked before assignment
Browse files Browse the repository at this point in the history
Fix issue #23
  • Loading branch information
julienvey committed May 25, 2014
1 parent c716d13 commit e056231
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/lib/vagrant-openstack-provider/openstack_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def get_server_details(env, server_id)
end

def add_floating_ip(env, server_id, floating_ip)
check_floating_ip(env, floating_ip)

This comment has been minimized.

Copy link
@ggiamarchi

ggiamarchi Jun 6, 2014

Owner

I think it would be better to not do orchestration here. I would prefer add_floating_ip not calling check_floating_ip and orchestration done in the upper layer.

config = env[:machine].provider_config
server_details = RestClient.post("#{config.openstack_compute_url}/#{@project_id}/servers/#{server_id}/action", {
:addFloatingIp => {
Expand All @@ -95,6 +96,23 @@ def add_floating_ip(env, server_id, floating_ip)
:accept => :json,
:content_type => :json)
end

def check_floating_ip(env, floating_ip)
config = env[:machine].provider_config
ip_details = RestClient.get("#{config.openstack_compute_url}/#{@projectId}/os-floating-ips",
"X-Auth-Token" => @token,
:accept => :json)
for ip in JSON.parse(ip_details)['floating_ips']
if ip['ip'] == floating_ip
if !ip['instance_id'].nil?
raise "Floating IP #{floating_ip} already assigned to another server"
else
return
end
end
end
raise "Floating IP #{floating_ip} not available for this tenant"
end
end

class Item
Expand Down

0 comments on commit e056231

Please sign in to comment.