core: Environment#machine_index
This commit is contained in:
parent
a29f5d7e01
commit
8a6bdbf710
|
@ -97,6 +97,7 @@ module Vagrant
|
||||||
autoload :Guest, 'vagrant/guest'
|
autoload :Guest, 'vagrant/guest'
|
||||||
autoload :Host, 'vagrant/host'
|
autoload :Host, 'vagrant/host'
|
||||||
autoload :Machine, 'vagrant/machine'
|
autoload :Machine, 'vagrant/machine'
|
||||||
|
autoload :MachineIndex, 'vagrant/machine_index'
|
||||||
autoload :MachineState, 'vagrant/machine_state'
|
autoload :MachineState, 'vagrant/machine_state'
|
||||||
autoload :Plugin, 'vagrant/plugin'
|
autoload :Plugin, 'vagrant/plugin'
|
||||||
autoload :UI, 'vagrant/ui'
|
autoload :UI, 'vagrant/ui'
|
||||||
|
|
|
@ -121,6 +121,7 @@ module Vagrant
|
||||||
@data_dir = @home_path.join("data")
|
@data_dir = @home_path.join("data")
|
||||||
@gems_path = @home_path.join("gems")
|
@gems_path = @home_path.join("gems")
|
||||||
@tmp_path = @home_path.join("tmp")
|
@tmp_path = @home_path.join("tmp")
|
||||||
|
@machine_index_dir = @data_dir.join("machine-index")
|
||||||
|
|
||||||
# Prepare the directories
|
# Prepare the directories
|
||||||
setup_home_path
|
setup_home_path
|
||||||
|
@ -417,6 +418,13 @@ module Vagrant
|
||||||
name, provider, boxes, machine_data_path, self)
|
name, provider, boxes, machine_data_path, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The {MachineIndex} to store information about the machines.
|
||||||
|
#
|
||||||
|
# @return [MachineIndex]
|
||||||
|
def machine_index
|
||||||
|
@machine_index ||= MachineIndex.new(@machine_index_dir)
|
||||||
|
end
|
||||||
|
|
||||||
# This returns a list of the configured machines for this environment.
|
# This returns a list of the configured machines for this environment.
|
||||||
# Each of the names returned by this method is valid to be used with
|
# Each of the names returned by this method is valid to be used with
|
||||||
# the {#machine} method.
|
# the {#machine} method.
|
||||||
|
@ -508,9 +516,15 @@ module Vagrant
|
||||||
|
|
||||||
# Setup the list of child directories that need to be created if they
|
# Setup the list of child directories that need to be created if they
|
||||||
# don't already exist.
|
# don't already exist.
|
||||||
dirs = [@home_path]
|
dirs = [
|
||||||
subdirs = ["boxes", "data", "gems", "rgloader", "tmp"]
|
@home_path,
|
||||||
dirs += subdirs.collect { |subdir| @home_path.join(subdir) }
|
@home_path.join("rgloader"),
|
||||||
|
@boxes_path,
|
||||||
|
@data_dir,
|
||||||
|
@gems_path,
|
||||||
|
@tmp_path,
|
||||||
|
@machine_index_dir,
|
||||||
|
]
|
||||||
|
|
||||||
# Go through each required directory, creating it if it doesn't exist
|
# Go through each required directory, creating it if it doesn't exist
|
||||||
dirs.each do |dir|
|
dirs.each do |dir|
|
||||||
|
|
|
@ -558,6 +558,29 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#machine_index" do
|
||||||
|
it "returns a machine index" do
|
||||||
|
expect(subject.machine_index).to be_kind_of(Vagrant::MachineIndex)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "caches the result" do
|
||||||
|
result = subject.machine_index
|
||||||
|
expect(subject.machine_index).to equal(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "uses a directory within the home directory by default" do
|
||||||
|
klass = double("machine_index")
|
||||||
|
stub_const("Vagrant::MachineIndex", klass)
|
||||||
|
|
||||||
|
klass.should_receive(:new).with do |path|
|
||||||
|
expect(path.to_s.start_with?(subject.home_path.to_s)).to be_true
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
subject.machine_index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "active machines" do
|
describe "active machines" do
|
||||||
it "should be empty if the machines folder doesn't exist" do
|
it "should be empty if the machines folder doesn't exist" do
|
||||||
folder = instance.local_data_path.join("machines")
|
folder = instance.local_data_path.join("machines")
|
||||||
|
|
Loading…
Reference in New Issue