Enumerate vms according to definiton order.
This commit is contained in:
parent
beb6c7d265
commit
e1ed00f14c
|
@ -17,7 +17,7 @@ module Vagrant
|
|||
|
||||
@target_vms ||= begin
|
||||
if env.multivm?
|
||||
return env.vms.values if !name
|
||||
return env.vms_ordered if !name
|
||||
vm = env.vms[name.to_sym]
|
||||
raise Errors::VMNotFoundError.new(:name => name) if !vm
|
||||
else
|
||||
|
|
|
@ -88,8 +88,15 @@ module Vagrant
|
|||
@defined_vms ||= {}
|
||||
end
|
||||
|
||||
# This returns the keys of the sub-vms in the order they were
|
||||
# defined.
|
||||
def defined_vm_keys
|
||||
@defined_vm_keys ||= []
|
||||
end
|
||||
|
||||
def define(name, options=nil, &block)
|
||||
options ||= {}
|
||||
defined_vm_keys << name
|
||||
defined_vms[name.to_sym] ||= SubVM.new
|
||||
defined_vms[name.to_sym].options.merge!(options)
|
||||
defined_vms[name.to_sym].push_proc(&block)
|
||||
|
|
|
@ -126,13 +126,21 @@ module Vagrant
|
|||
|
||||
# Returns the VMs associated with this environment.
|
||||
#
|
||||
# @return [Array<VM>]
|
||||
# @return [Hash<Symbol,VM>]
|
||||
def vms
|
||||
return parent.vms if parent
|
||||
load! if !loaded?
|
||||
@vms ||= load_vms!
|
||||
end
|
||||
|
||||
# Returns the VMs associated with this environment, in the order
|
||||
# that they were defined.
|
||||
#
|
||||
# @return [Array<VM>]
|
||||
def vms_ordered
|
||||
@vms_enum ||= config.vm.defined_vm_keys.map {|name| @vms[name]}
|
||||
end
|
||||
|
||||
# Returns the primary VM associated with this environment. This
|
||||
# method is only applicable for multi-VM environments. This can
|
||||
# potentially be nil if no primary VM is specified.
|
||||
|
@ -352,7 +360,7 @@ module Vagrant
|
|||
|
||||
# For any VMs which aren't created, create a blank VM instance for
|
||||
# them
|
||||
all_keys = config.vm.defined_vms.keys
|
||||
all_keys = config.vm.defined_vm_keys
|
||||
all_keys = [DEFAULT_VM] if all_keys.empty?
|
||||
all_keys.each do |name|
|
||||
result[name] = Vagrant::VM.new(:name => name, :env => self) if !result.has_key?(name)
|
||||
|
|
|
@ -39,7 +39,7 @@ class CommandHelpersTest < Test::Unit::TestCase
|
|||
|
||||
context "without multivm" do
|
||||
setup do
|
||||
@env.stubs(:vms).returns({ :one => 1, :two => 2 })
|
||||
@env.stubs(:vms_ordered => [1, 2], :vms => {:one => 1, :two => 2})
|
||||
end
|
||||
|
||||
should "raise an exception if a name is specified" do
|
||||
|
@ -59,7 +59,7 @@ class CommandHelpersTest < Test::Unit::TestCase
|
|||
|
||||
context "with multivm" do
|
||||
setup do
|
||||
@env.stubs(:vms).returns(:one => 1, :two => 2)
|
||||
@env.stubs(:vms_ordered => [1, 2], :vms => {:one => 1, :two => 2})
|
||||
end
|
||||
|
||||
should "return all the VMs if no name is specified" do
|
||||
|
|
|
@ -32,6 +32,14 @@ class ConfigVMTest < Test::Unit::TestCase
|
|||
@config.define(:foo) {}
|
||||
assert @config.has_multi_vms?
|
||||
end
|
||||
|
||||
should "retain vm definition order" do
|
||||
@config.define(:a) {}
|
||||
@config.define(:b) {}
|
||||
@config.define(:c) {}
|
||||
|
||||
assert_equal [:a, :b, :c], @config.defined_vm_keys
|
||||
end
|
||||
end
|
||||
|
||||
context "customizing" do
|
||||
|
|
Loading…
Reference in New Issue