core: Use the MachineIndex#vagrant_env method
This commit is contained in:
parent
a4addd0e25
commit
2b07dec059
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue