Skip to content

Commit

Permalink
Merge pull request #189 from mangelajo/enhancement/multiple-setting-v…
Browse files Browse the repository at this point in the history
…alues

Allow list for flavors in config
  • Loading branch information
ggiamarchi committed Jan 2, 2015
2 parents 22d80de + f6eb055 commit 60b8b85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 13 additions & 9 deletions source/lib/vagrant-openstack-provider/config_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,21 @@ def resolve_volume_from_hash(volume, volume_list, volume_ids)
{ id: volume_id, device: device }
end

# This method finds a matching _thing_ in a collection of
# _things_. This works matching if the ID or NAME equals to
# `name`. Or, if `name` is a regexp, a partial match is chosen
# This method finds any matching _thing_ from a list of names
# in a collection of _things_. The first to match is the returned
# one. Names in list can be a regexp, a partial match is chosen
# as well.
def find_matching(collection, name)
collection.each do |single|
return single if single.id == name
return single if single.name == name
return single if name.is_a?(Regexp) && name =~ single.name

def find_matching(collection, name_or_names)
name_or_names = [name_or_names] if name_or_names.class != Array
name_or_names.each do |name|
collection.each do |single|
return single if single.id == name
return single if single.name == name
return single if name.is_a?(Regexp) && name =~ single.name
end
end
@logger.error "Element '#{name}' not found in collection #{collection}"
@logger.error "No element of '#{name_or_names}' found in collection #{collection}"
nil
end
end
Expand Down
10 changes: 10 additions & 0 deletions source/spec/vagrant-openstack-provider/config_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
@action.resolve_flavor(env).should eq(Flavor.new('fl-002', 'flavor-02', 4, 2048, 50))
end
end
context 'with list' do
it 'returns the first matching flavor' do
config.stub(:flavor) { %w(not-existing flavor-02 flavor-01) }
nova.stub(:get_all_flavors).with(anything) do
[Flavor.new('fl-001', 'flavor-01', 2, 1024, 10),
Flavor.new('fl-002', 'flavor-02', 4, 2048, 50)]
end
@action.resolve_flavor(env).should eq(Flavor.new('fl-002', 'flavor-02', 4, 2048, 50))
end
end
context 'with invalid identifier' do
it 'raise an error' do
config.stub(:flavor) { 'not-existing' }
Expand Down

0 comments on commit 60b8b85

Please sign in to comment.