core: generalize the autostart stuff so we don't have a bunch of specials

This commit is contained in:
Mitchell Hashimoto 2014-04-10 10:43:46 -07:00
parent d7a009f447
commit 1c29c39f1b
5 changed files with 26 additions and 49 deletions

View File

@ -434,16 +434,6 @@ module Vagrant
vagrantfile.machine_names
end
# This returns a list of the configured machines for this environment
# that do not have "autostart" set to false.
# Each of the names returned by this method is valid to be used with
# the {#machine} method.
#
# @return [Array<Symbol>] Configured autostart machine names.
def autostart_machine_names
vagrantfile.autostart_machine_names
end
# This returns the name of the machine that is the "primary." In the
# case of a single-machine environment, this is just the single machine
# name. In the case of a multi-machine environment, then this can

View File

@ -207,18 +207,16 @@ module Vagrant
@config.vm.defined_vm_keys.dup
end
# Returns a list of the machines that are defined within this
# Vagrantfile that do not have "autostart" set to false.
# Returns a list of the machine names as well as the options that
# were specified for that machine.
#
# @return [Array<Symbol>]
def autostart_machine_names
machines = []
# Remove any machines that have autostart set to false from machine_names
@config.vm.defined_vms.each do |name, subvm|
machines << name if subvm.options[:autostart] == nil or subvm.options[:autostart] == true
# @return [Hash<Symbol, Hash>]
def machine_names_and_options
{}.tap do |r|
@config.vm.defined_vms.each do |name, subvm|
r[name] = subvm.options || {}
end
end
return machines
end
# Returns the name of the machine that is designated as the

View File

@ -57,7 +57,12 @@ module VagrantPlugins
machines = []
@env.batch(options[:parallel]) do |batch|
names = argv
names = @env.autostart_machine_names if names.empty?
if names.empty?
@env.vagrantfile.machine_names_and_options.each do |n, o|
o[:autostart] = true if !o.has_key?(:autostart)
names << n if o[:autostart]
end
end
with_target_vms(names, :provider => options[:provider]) do |machine|
@env.ui.info(I18n.t(

View File

@ -979,22 +979,5 @@ VF
env = isolated_env.create_vagrant_env
expect(env.machine_names).to eq([:foo, :bar])
end
it "should return only the machine names configured to autostart" do
# Create the config
isolated_env = isolated_environment do |e|
e.vagrantfile(<<-VF)
Vagrant.configure("2") do |config|
config.vm.define "foo"
config.vm.define "bar", autostart: false
config.vm.define "baz", autostart: true
end
VF
end
env = isolated_env.create_vagrant_env
env.autostart_machine_names.should == [:foo, :baz]
end
end
end

View File

@ -332,26 +332,27 @@ describe Vagrant::Vagrantfile do
end
end
describe "#autostart_machine_names" do
it "returns machine_names if no autostart values where set" do
configure do |config|
config.vm.define "foo"
config.vm.define "bar"
end
describe "#machine_names_and_options" do
it "returns the default name" do
configure { |config| }
expect(subject.autostart_machine_names).to eq(
subject.machine_names)
expect(subject.machine_names_and_options).to eq({
default: { config_version: "2" },
})
end
it "returns only machine_names without autostart or autostart true" do
it "returns all the machines" do
configure do |config|
config.vm.define "foo"
config.vm.define "bar", autostart: false
config.vm.define "baz", autostart: true
end
expect(subject.autostart_machine_names).to eq(
[:foo, :baz])
expect(subject.machine_names_and_options).to eq({
foo: { config_version: "2" },
bar: { config_version: "2", autostart: false },
baz: { config_version: "2", autostart: true },
})
end
end