VM definition blocks are now stackable. [closes GH-94]

This commit is contained in:
Mitchell Hashimoto 2010-06-03 19:20:15 -07:00
parent 1e01514c4f
commit 7a093340bf
3 changed files with 22 additions and 7 deletions

View File

@ -98,6 +98,16 @@ module Vagrant
attr_accessor :shared_folder_gid
attr_accessor :system
# Represents a SubVM. This class is only used here in the VMs
# hash.
class SubVM
include Util::StackedProcRunner
def options
@options ||= {}
end
end
def initialize
@forwarded_ports = {}
@shared_folders = {}
@ -170,7 +180,9 @@ module Vagrant
def define(name, options=nil, &block)
options ||= {}
defined_vms[name.to_sym] = options.merge({:config_proc => block})
defined_vms[name.to_sym] ||= SubVM.new
defined_vms[name.to_sym].options.merge!(options)
defined_vms[name.to_sym].push_proc(&block)
end
def shift(orig, rsync)

View File

@ -106,8 +106,8 @@ module Vagrant
return vms.values.first if !multivm?
return parent.primary_vm if parent
config.vm.defined_vms.each do |name, options|
return vms[name] if options[:primary]
config.vm.defined_vms.each do |name, subvm|
return vms[name] if subvm.options[:primary]
end
nil
@ -178,10 +178,13 @@ module Vagrant
# If this environment represents some VM in a multi-VM environment,
# we push that VM's configuration onto the config_queue.
if vm_name
vm_data = parent.config.vm.defined_vms[vm_name] || {}
config_queue << vm_data[:config_proc]
subvm = parent.config.vm.defined_vms[vm_name]
config_queue << subvm.proc_stack if subvm
end
# Flatten the config queue so any nested procs are flattened
config_queue.flatten!
# Clear out the old data
Config.reset!(self)

View File

@ -232,12 +232,12 @@ class ConfigTest < Test::Unit::TestCase
proc = Proc.new { foo.call }
@config.define(:name, &proc)
assert_equal proc, @config.defined_vms[:name][:config_proc]
assert @config.defined_vms[:name].proc_stack.include?(proc)
end
should "store the options" do
@config.define(:name, :set => true)
assert @config.defined_vms[:name][:set]
assert @config.defined_vms[:name].options[:set]
end
should "not have multi-VMs by default" do