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

Fix autoincrement when creating a flavor if private flavors exist.

Before, only public flavors were considered when finding the next free ID. That could lead to the case where the calculated ID was already taken which lead to a conflict. This happened whenever the user tried to create a private flavor via fog and then another (private OR public) flavor afterwards. Now, we also take private flavors into account, so the conflict cannot happen anymore.

As a side effect, it is now also possible to just return all private flavors, using the :is_public => false filter on the list_flavors_detail API call or the flavors collection.
This commit is contained in:
Thomas Kadauke 2013-06-18 17:58:07 +02:00
parent 06deb8554f
commit b00761705a
3 changed files with 7 additions and 6 deletions

View file

@ -9,8 +9,8 @@ module Fog
model Fog::Compute::OpenStack::Flavor model Fog::Compute::OpenStack::Flavor
def all def all(options = {})
data = service.list_flavors_detail.body['flavors'] data = service.list_flavors_detail(options).body['flavors']
load(data) load(data)
end end

View file

@ -12,7 +12,7 @@ module Fog
def create_flavor(attributes) def create_flavor(attributes)
# Get last flavor id # Get last flavor id
flavor_ids = Array.new flavor_ids = Array.new
flavors = list_flavors_detail.body['flavors'] flavors = list_flavors_detail.body['flavors'] + list_flavors_detail(:is_public => false).body['flavors']
flavors.each do |flavor| flavors.each do |flavor|
flavor_ids << flavor['id'].to_i flavor_ids << flavor['id'].to_i
end end

View file

@ -3,11 +3,12 @@ module Fog
class OpenStack class OpenStack
class Real class Real
def list_flavors_detail def list_flavors_detail(options = {})
request( request(
:expects => [200, 203], :expects => [200, 203],
:method => 'GET', :method => 'GET',
:path => 'flavors/detail.json' :path => 'flavors/detail.json',
:query => options
) )
end end
@ -15,7 +16,7 @@ module Fog
class Mock class Mock
def list_flavors_detail def list_flavors_detail(options = {})
response = Excon::Response.new response = Excon::Response.new
response.status = 200 response.status = 200
response.body = { response.body = {