Remove environment "vm_name" property since it was redundant

This commit is contained in:
Mitchell Hashimoto 2010-09-05 23:11:27 -07:00
parent 1be3f972ae
commit ed48170b24
5 changed files with 27 additions and 26 deletions

View File

@ -11,7 +11,6 @@ module Vagrant
DEFAULT_VM = :default
attr_reader :parent # Parent environment (in the case of multi-VMs)
attr_reader :vm_name # The name of the VM (internal name) which this environment represents
attr_reader :cwd
attr_reader :box
@ -35,7 +34,6 @@ module Vagrant
def initialize(opts=nil)
opts = {
:parent => nil,
:vm_name => nil,
:vm => nil,
:cwd => nil,
}.merge(opts || {})
@ -78,7 +76,7 @@ module Vagrant
# The resource is the VM name if there is a VM it represents, otherwise
# it defaults to "vagrant"
def resource
vm_name || "vagrant"
vm.name rescue "vagrant"
end
# Returns the VMs associated with this environment.
@ -158,14 +156,6 @@ module Vagrant
@local_data ||= DataStore.new(dotfile_path)
end
# The configuration object represented by this environment. This
# will trigger the environment to load if it hasn't loaded yet (see
# {#load!}).
def config
load! if !loaded?
@config
end
# Accesses the logger for Vagrant. This logger is a _detailed_
# logger which should be used to log internals only. For outward
# facing information, use {#ui}.
@ -189,6 +179,18 @@ module Vagrant
@root_path = root_finder.call(Pathname.new(cwd))
end
#---------------------------------------------------------------
# Config Methods
#---------------------------------------------------------------
# The configuration object represented by this environment. This
# will trigger the environment to load if it hasn't loaded yet (see
# {#load!}).
def config
load! if !loaded?
@config
end
#---------------------------------------------------------------
# Load Methods
#---------------------------------------------------------------
@ -226,8 +228,8 @@ module Vagrant
# If this environment is representing a sub-VM, then we push that
# proc on as the last configuration.
if !first_run && vm_name
subvm = parent.config.vm.defined_vms[vm_name]
if !first_run && vm
subvm = parent.config.vm.defined_vms[vm.name]
loader.queue << subvm.proc_stack if subvm
end
@ -273,7 +275,7 @@ module Vagrant
# This environment represents a single sub VM. The VM is then
# probably (read: should be) set on the VM attribute, so we do
# nothing.
return if vm_name
return if vm
# First load the defaults (blank, noncreated VMs)
load_blank_vms!
@ -294,7 +296,7 @@ module Vagrant
defined_vms = [DEFAULT_VM] if defined_vms.empty?
defined_vms.each do |name|
vms[name] = Vagrant::VM.new(:vm_name => name, :env => self)
vms[name] = Vagrant::VM.new(:name => name, :env => self)
end
end
end

View File

@ -10,9 +10,9 @@ module Vagrant
class << self
# Finds a virtual machine by a given UUID and either returns
# a Vagrant::VM object or returns nil.
def find(uuid, env=nil, vm_name=nil)
def find(uuid, env=nil, name=nil)
vm = VirtualBox::VM.find(uuid)
new(:vm => vm, :env => env, :vm_name => vm_name)
new(:vm => vm, :env => env, :name => name)
end
end
@ -20,13 +20,13 @@ module Vagrant
defaults = {
:vm => nil,
:env => nil,
:vm_name => nil
:name => nil
}
opts = defaults.merge(opts || {})
@vm = opts[:vm]
@name = opts[:vm_name]
@name = opts[:name]
if !opts[:env].nil?
# We have an environment, so we create a new child environment
@ -35,7 +35,6 @@ module Vagrant
@env = Vagrant::Environment.new({
:cwd => opts[:env].cwd,
:parent => opts[:env],
:vm_name => opts[:vm_name],
:vm => self
}).load!

View File

@ -12,7 +12,7 @@ class ImportVMActionTest < Test::Unit::TestCase
@box.stubs(:ovf_file).returns(ovf_file)
@env.env.stubs(:box).returns(@box)
@env.env.vm = Vagrant::VM.new(:env => @env.env, :vm_name => "foobar")
@env.env.vm = Vagrant::VM.new(:env => @env.env, :name => "foobar")
VirtualBox::VM.stubs(:import)

View File

@ -91,7 +91,7 @@ class EnvironmentTest < Test::Unit::TestCase
end
should "return the VM name if it is specified" do
@env.stubs(:vm_name).returns("foo")
@env.stubs(:vm).returns(mock("vm", :name => "foo"))
assert_equal "foo", @env.resource
end
end
@ -381,7 +381,7 @@ class EnvironmentTest < Test::Unit::TestCase
parent_env = mock_environment
parent_env.config.vm.define(vm_name, &proc)
@env.stubs(:parent).returns(parent_env)
@env.stubs(:vm_name).returns(vm_name)
@env.stubs(:vm).returns(mock("vm", :name => vm_name))
@env.load_config!
assert @loader.queue.flatten.include?(proc)
@ -484,8 +484,8 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
should "do nothing if the vm_name is set" do
@env.stubs(:vm_name).returns(:foo)
should "do nothing if the vm is set" do
@env.stubs(:vm).returns(mock("vm"))
File.expects(:open).never
@env.load_vm!
end

View File

@ -27,7 +27,7 @@ class VMTest < Test::Unit::TestCase
setup do
@vm_name = "foo"
@mock_vm = mock("vm")
@vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :vm_name => @vm_name)
@vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :name => @vm_name)
@mock_vm.stubs(:uuid).returns("foo")
end