core: Use the MachineIndex#vagrant_env method

This commit is contained in:
Mitchell Hashimoto 2014-04-14 20:15:46 -07:00
parent a4addd0e25
commit 2b07dec059
4 changed files with 17 additions and 13 deletions

View File

@ -379,6 +379,17 @@ module Vagrant
@extra_data = raw["extra_data"] || {}
end
# Creates a {Vagrant::Environment} for this entry.
#
# @return [Vagrant::Environment]
def vagrant_env(home_path, **opts)
Environment.new({
cwd: @vagrantfile_path,
home_path: home_path,
vagrantfile_name: @vagrantfile_name,
}.merge(opts))
end
# Converts to the structure used by the JSON
def to_json_struct
{

View File

@ -135,11 +135,8 @@ module Vagrant
# Vagrantfiles often have constants, so people would otherwise
# constantly (heh) get "already initialized constant" warnings.
machine = Vagrant::Util::SilenceWarnings.silence! do
env = Vagrant::Environment.new(
cwd: entry.vagrantfile_path,
home_path: @env.home_path,
ui_class: @env.ui_class,
)
env = entry.vagrant_env(
@env.home_path, ui_class: @env.ui_class)
env.machine(entry.name.to_sym, entry.provider.to_sym)
end

View File

@ -100,15 +100,11 @@ module VagrantPlugins
# Tests if a entry is invalid and should be pruned
def invalid?(entry)
return true if !entry.vagrantfile_path.file?
return true if !entry.vagrantfile_path.directory?
# Create an environment so we can determine the active
# machines...
env = Vagrant::Environment.new(
cwd: entry.vagrantfile_path.dirname,
home_path: @env.home_path,
)
env = entry.vagrant_env(@env.home_path)
env.active_machines.each do |name, provider|
return false if name.to_s == entry.name.to_s &&
provider.to_s == entry.provider.to_s

View File

@ -51,7 +51,7 @@ describe VagrantPlugins::CommandGlobalStatus::Command do
entryB_env = isolated_environment
entryB_env.vagrantfile("")
entryB = new_entry("B")
entryB.vagrantfile_path = entryB_env.workdir.join("Vagrantfile")
entryB.vagrantfile_path = entryB_env.workdir
locked = iso_env.machine_index.set(entryB)
iso_env.machine_index.release(locked)
@ -63,7 +63,7 @@ describe VagrantPlugins::CommandGlobalStatus::Command do
entryC_machine.id = "foo"
entryC = new_entry(entryC_machine.name)
entryC.provider = "dummy"
entryC.vagrantfile_path = entryC_env.workdir.join("Vagrantfile")
entryC.vagrantfile_path = entryC_env.workdir
locked = iso_env.machine_index.set(entryC)
iso_env.machine_index.release(locked)