Remove all environment `parent` references

This commit is contained in:
Mitchell Hashimoto 2011-12-04 11:16:55 -08:00
parent e2977e8948
commit f8d628148c
1 changed files with 7 additions and 40 deletions

View File

@ -12,9 +12,6 @@ module Vagrant
DEFAULT_VM = :default DEFAULT_VM = :default
DEFAULT_HOME = "~/.vagrant.d" DEFAULT_HOME = "~/.vagrant.d"
# Parent environment (in the case of multi-VMs)
attr_reader :parent
# The `cwd` that this environment represents # The `cwd` that this environment represents
attr_reader :cwd attr_reader :cwd
@ -26,7 +23,7 @@ module Vagrant
attr_accessor :vm attr_accessor :vm
# The {UI} object to communicate with the outside world. # The {UI} object to communicate with the outside world.
attr_writer :ui attr_reader :ui
#--------------------------------------------------------------- #---------------------------------------------------------------
# Class Methods # Class Methods
@ -56,7 +53,6 @@ module Vagrant
# to the `Dir.pwd` (which is the cwd of the executing process). # to the `Dir.pwd` (which is the cwd of the executing process).
def initialize(opts=nil) def initialize(opts=nil)
opts = { opts = {
:parent => nil,
:vm => nil, :vm => nil,
:cwd => nil, :cwd => nil,
:vagrantfile_name => nil, :vagrantfile_name => nil,
@ -75,21 +71,21 @@ module Vagrant
opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if !opts[:vagrantfile_name].is_a?(Array) opts[:vagrantfile_name] = [opts[:vagrantfile_name]] if !opts[:vagrantfile_name].is_a?(Array)
# Set instance variables for all the configuration parameters. # Set instance variables for all the configuration parameters.
@parent = opts[:parent]
@vm = opts[:vm] @vm = opts[:vm]
@cwd = opts[:cwd] @cwd = opts[:cwd]
@vagrantfile_name = opts[:vagrantfile_name] @vagrantfile_name = opts[:vagrantfile_name]
@lock_path = opts[:lock_path] @lock_path = opts[:lock_path]
@ui_class = opts[:ui_class]
@home_path = opts[:home_path] @home_path = opts[:home_path]
ui_class = opts[:ui_class] || UI::Silent
@ui = ui_class.new(self)
@loaded = false @loaded = false
@lock_acquired = false @lock_acquired = false
@logger = Log4r::Logger.new("vagrant::environment") @logger = Log4r::Logger.new("vagrant::environment")
@logger.info("Environment initialized (#{self})") @logger.info("Environment initialized (#{self})")
@logger.info(" - cwd: #{cwd}") @logger.info(" - cwd: #{cwd}")
@logger.info(" - parent: #{parent}")
@logger.info(" - vm: #{vm}") @logger.info(" - vm: #{vm}")
end end
@ -109,7 +105,6 @@ module Vagrant
# #
# @return [Pathname] # @return [Pathname]
def home_path def home_path
return parent.home_path if parent
return @_home_path if defined?(@_home_path) return @_home_path if defined?(@_home_path)
@_home_path ||= Pathname.new(File.expand_path(@home_path || @_home_path ||= Pathname.new(File.expand_path(@home_path ||
@ -158,7 +153,6 @@ module Vagrant
# #
# @return [BoxCollection] # @return [BoxCollection]
def boxes def boxes
return parent.boxes if parent
@_boxes ||= BoxCollection.new(self) @_boxes ||= BoxCollection.new(self)
end end
@ -166,7 +160,6 @@ module Vagrant
# #
# @return [Hash<Symbol,VM>] # @return [Hash<Symbol,VM>]
def vms def vms
return parent.vms if parent
load! if !loaded? load! if !loaded?
@vms ||= load_vms! @vms ||= load_vms!
end end
@ -186,7 +179,6 @@ module Vagrant
# @return [VM] # @return [VM]
def primary_vm def primary_vm
return vms.values.first if !multivm? return vms.values.first if !multivm?
return parent.primary_vm if parent
config.vm.defined_vms.each do |name, subvm| config.vm.defined_vms.each do |name, subvm|
return vms[name] if subvm.options[:primary] return vms[name] if subvm.options[:primary]
@ -201,11 +193,7 @@ module Vagrant
# #
# @return [Bool] # @return [Bool]
def multivm? def multivm?
if parent vms.length > 1 || vms.keys.first != DEFAULT_VM
parent.multivm?
else
vms.length > 1 || vms.keys.first != DEFAULT_VM
end
end end
# Makes a call to the CLI with the given arguments as if they # Makes a call to the CLI with the given arguments as if they
@ -217,21 +205,6 @@ module Vagrant
CLI.start(args.flatten, :env => self) CLI.start(args.flatten, :env => self)
end end
# Returns the {UI} for the environment, which is responsible
# for talking with the outside world.
#
# @return [UI]
def ui
@ui ||= if parent
result = parent.ui.clone
result.env = self
result
else
ui_class = @ui_class || UI::Silent
ui_class.new(self)
end
end
# Returns the host object associated with this environment. # Returns the host object associated with this environment.
# #
# @return [Hosts::Base] # @return [Hosts::Base]
@ -255,7 +228,6 @@ module Vagrant
# #
# @return [DataStore] # @return [DataStore]
def global_data def global_data
return parent.global_data if parent
@global_data ||= DataStore.new(File.expand_path("global_data.json", home_path)) @global_data ||= DataStore.new(File.expand_path("global_data.json", home_path))
end end
@ -266,7 +238,6 @@ module Vagrant
# #
# @return [DataStore] # @return [DataStore]
def local_data def local_data
return parent.local_data if parent
@local_data ||= DataStore.new(dotfile_path) @local_data ||= DataStore.new(dotfile_path)
end end
@ -359,12 +330,8 @@ module Vagrant
if !loaded? if !loaded?
@loaded = true @loaded = true
if !parent @logger.info("Environment not loaded. Checking virtual box version...")
# We only need to check the virtualbox version once, so do it on self.class.check_virtualbox!
# the parent most environment and then forget about it
@logger.info("Environment not loaded. Checking virtual box version...")
self.class.check_virtualbox!
end
@logger.info("Loading configuration...") @logger.info("Loading configuration...")
load_config! load_config!