lib/vagrant/environment.rb in vagrant-0.7.0.beta vs lib/vagrant/environment.rb in vagrant-0.7.0.beta2
- old
+ new
@@ -7,10 +7,11 @@
# access to the VMs, CLI, etc. all in the scope of this environment.
class Environment
ROOTFILE_NAME = "Vagrantfile"
HOME_SUBDIRS = ["tmp", "boxes", "logs"]
DEFAULT_VM = :default
+ DEFAULT_HOME = "~/.vagrant"
# Parent environment (in the case of multi-VMs)
attr_reader :parent
# The `cwd` that this environment represents
@@ -21,21 +22,23 @@
attr_accessor :vm
# The {UI} object to communicate with the outside world.
attr_writer :ui
+ # The {Config} object representing the Vagrantfile loader
+ attr_reader :config_loader
+
#---------------------------------------------------------------
# Class Methods
#---------------------------------------------------------------
class << self
# Verifies that VirtualBox is installed and that the version of
# VirtualBox installed is high enough.
def check_virtualbox!
version = VirtualBox.version
raise Errors::VirtualBoxNotDetected if version.nil?
raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 4.0
- raise Errors::VirtualBoxInvalidOSE, :version => version.to_s if version.to_s.downcase.include?("ose")
rescue Errors::VirtualBoxNotDetected
# On 64-bit Windows, show a special error. This error is a subclass
# of VirtualBoxNotDetected, so libraries which use Vagrant can just
# rescue VirtualBoxNotDetected.
raise Errors::VirtualBoxNotDetected_Win64 if Util::Platform.windows? && Util::Platform.bit64?
@@ -77,16 +80,15 @@
# @return [Pathname]
def dotfile_path
root_path.join(config.vagrant.dotfile_name) rescue nil
end
- # The path to the home directory, expanded relative to the root path,
- # and converted into a Pathname object.
+ # The path to the home directory and converted into a Pathname object.
#
# @return [Pathname]
def home_path
- @_home_path ||= Pathname.new(File.expand_path(config.vagrant.home, root_path))
+ @_home_path ||= Pathname.new(File.expand_path(ENV["VAGRANT_HOME"] || DEFAULT_HOME))
end
# The path to the Vagrant tmp directory
#
# @return [Pathname]
@@ -112,11 +114,12 @@
# The resource is the VM name if there is a VM it represents, otherwise
# it defaults to "vagrant"
#
# @return [String]
def resource
- vm.name rescue "vagrant"
+ result = vm.name rescue nil
+ result || "vagrant"
end
# Returns the collection of boxes for the environment.
#
# @return [BoxCollection]
@@ -144,11 +147,11 @@
# 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]}
+ @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.
@@ -303,33 +306,42 @@
end
self
end
+ # Reloads the configuration of this environment.
+ def reload_config!
+ @config = nil
+ @config_loader = nil
+ load_config!
+ self
+ end
+
# Loads this environment's configuration and stores it in the {#config}
# variable. The configuration loaded by this method is specified to
# this environment, meaning that it will use the given root directory
# to load the Vagrantfile into that context.
def load_config!
first_run = @config.nil?
# First load the initial, non config-dependent Vagrantfiles
- loader = Config.new(self)
- loader.queue << File.expand_path("config/default.rb", Vagrant.source_root)
- loader.queue << File.join(box.directory, ROOTFILE_NAME) if !first_run && box
- loader.queue << File.join(home_path, ROOTFILE_NAME) if !first_run && home_path
- loader.queue << File.join(root_path, ROOTFILE_NAME) if root_path
+ @config_loader ||= Config.new(parent ? parent.config_loader : nil)
+ @config_loader.load_order = [:default, :box, :home, :root, :sub_vm]
+ @config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root))
+ @config_loader.set(:box, File.join(box.directory, ROOTFILE_NAME)) if !first_run && vm && box
+ @config_loader.set(:home, File.join(home_path, ROOTFILE_NAME)) if !first_run && home_path
+ @config_loader.set(:root, File.join(root_path, ROOTFILE_NAME)) if root_path
# If this environment is representing a sub-VM, then we push that
# proc on as the last configuration.
if vm
subvm = parent.config.vm.defined_vms[vm.name]
- loader.queue << subvm.proc_stack if subvm
+ @config_loader.set(:sub_vm, subvm.proc_stack) if subvm
end
# Execute the configuration stack and store the result as the final
# value in the config ivar.
- @config = loader.load!
+ @config = @config_loader.load(self)
# (re)load the logger
@logger = nil
if first_run