core: generalize the autostart stuff so we don't have a bunch of specials
This commit is contained in:
parent
d7a009f447
commit
1c29c39f1b
|
@ -434,16 +434,6 @@ module Vagrant
|
||||||
vagrantfile.machine_names
|
vagrantfile.machine_names
|
||||||
end
|
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
|
# 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
|
# case of a single-machine environment, this is just the single machine
|
||||||
# name. In the case of a multi-machine environment, then this can
|
# name. In the case of a multi-machine environment, then this can
|
||||||
|
|
|
@ -207,18 +207,16 @@ module Vagrant
|
||||||
@config.vm.defined_vm_keys.dup
|
@config.vm.defined_vm_keys.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a list of the machines that are defined within this
|
# Returns a list of the machine names as well as the options that
|
||||||
# Vagrantfile that do not have "autostart" set to false.
|
# were specified for that machine.
|
||||||
#
|
#
|
||||||
# @return [Array<Symbol>]
|
# @return [Hash<Symbol, Hash>]
|
||||||
def autostart_machine_names
|
def machine_names_and_options
|
||||||
machines = []
|
{}.tap do |r|
|
||||||
# Remove any machines that have autostart set to false from machine_names
|
@config.vm.defined_vms.each do |name, subvm|
|
||||||
@config.vm.defined_vms.each do |name, subvm|
|
r[name] = subvm.options || {}
|
||||||
machines << name if subvm.options[:autostart] == nil or subvm.options[:autostart] == true
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return machines
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the name of the machine that is designated as the
|
# Returns the name of the machine that is designated as the
|
||||||
|
|
|
@ -57,7 +57,12 @@ module VagrantPlugins
|
||||||
machines = []
|
machines = []
|
||||||
@env.batch(options[:parallel]) do |batch|
|
@env.batch(options[:parallel]) do |batch|
|
||||||
names = argv
|
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|
|
with_target_vms(names, :provider => options[:provider]) do |machine|
|
||||||
@env.ui.info(I18n.t(
|
@env.ui.info(I18n.t(
|
||||||
|
|
|
@ -979,22 +979,5 @@ VF
|
||||||
env = isolated_env.create_vagrant_env
|
env = isolated_env.create_vagrant_env
|
||||||
expect(env.machine_names).to eq([:foo, :bar])
|
expect(env.machine_names).to eq([:foo, :bar])
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -332,26 +332,27 @@ describe Vagrant::Vagrantfile do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#autostart_machine_names" do
|
describe "#machine_names_and_options" do
|
||||||
it "returns machine_names if no autostart values where set" do
|
it "returns the default name" do
|
||||||
configure do |config|
|
configure { |config| }
|
||||||
config.vm.define "foo"
|
|
||||||
config.vm.define "bar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(subject.autostart_machine_names).to eq(
|
expect(subject.machine_names_and_options).to eq({
|
||||||
subject.machine_names)
|
default: { config_version: "2" },
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns only machine_names without autostart or autostart true" do
|
it "returns all the machines" do
|
||||||
configure do |config|
|
configure do |config|
|
||||||
config.vm.define "foo"
|
config.vm.define "foo"
|
||||||
config.vm.define "bar", autostart: false
|
config.vm.define "bar", autostart: false
|
||||||
config.vm.define "baz", autostart: true
|
config.vm.define "baz", autostart: true
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(subject.autostart_machine_names).to eq(
|
expect(subject.machine_names_and_options).to eq({
|
||||||
[:foo, :baz])
|
foo: { config_version: "2" },
|
||||||
|
bar: { config_version: "2", autostart: false },
|
||||||
|
baz: { config_version: "2", autostart: true },
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue