Environment#default_provider
This commit is contained in:
parent
1ee470a551
commit
128c06e78d
|
@ -122,6 +122,16 @@ module Vagrant
|
|||
# Helpers
|
||||
#---------------------------------------------------------------
|
||||
|
||||
# This returns the provider name for the default provider for this
|
||||
# environment. The provider returned is currently hardcoded to "virtualbox"
|
||||
# but one day should be a detected valid, best-case provider for this
|
||||
# environment.
|
||||
#
|
||||
# @return [Symbol] Name of the default provider.
|
||||
def default_provider
|
||||
:virtualbox
|
||||
end
|
||||
|
||||
# The path to the `dotfile`, which contains the persisted UUID of
|
||||
# the VM if it exists.
|
||||
#
|
||||
|
|
|
@ -61,8 +61,9 @@ module Vagrant
|
|||
# specific VM name is specified.
|
||||
#
|
||||
# @param [String] name The name of the VM. Nil if every VM.
|
||||
# @param [Boolean] single_target If true, then an exception will be
|
||||
# raised if more than one target is found.
|
||||
# @param [Hash] options Additional tweakable settings.
|
||||
# @option options [Boolean] :single_target If true, then an
|
||||
# exception will be raised if more than one target is found.
|
||||
def with_target_vms(names=nil, options=nil)
|
||||
# Using VMs requires a Vagrant environment to be properly setup
|
||||
raise Errors::NoEnvironmentError if !@env.root_path
|
||||
|
@ -74,6 +75,9 @@ module Vagrant
|
|||
names ||= []
|
||||
names = [names] if !names.is_a?(Array)
|
||||
|
||||
# The provider that we'll be loading up.
|
||||
provider = @env.default_provider
|
||||
|
||||
# First determine the proper array of VMs.
|
||||
machines = []
|
||||
if names.length > 0
|
||||
|
@ -85,14 +89,14 @@ module Vagrant
|
|||
|
||||
@env.machine_names.each do |machine_name|
|
||||
if machine_name =~ regex
|
||||
machines << @env.machine(machine_name, :virtualbox)
|
||||
machines << @env.machine(machine_name, provider)
|
||||
end
|
||||
end
|
||||
|
||||
raise Errors::VMNoMatchError if machines.empty?
|
||||
else
|
||||
# String name, just look for a specific VM
|
||||
machines << @env.machine(name.to_sym, :virtualbox)
|
||||
machines << @env.machine(name.to_sym, provider)
|
||||
raise Errors::VMNotFoundError, :name => name if !machines[0]
|
||||
end
|
||||
end
|
||||
|
@ -100,7 +104,7 @@ module Vagrant
|
|||
# No name was given, so we return every VM in the order
|
||||
# configured.
|
||||
machines = @env.machine_names.map do |machine_name|
|
||||
@env.machine(machine_name, :virtualbox)
|
||||
@env.machine(machine_name, provider)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -72,6 +72,12 @@ describe Vagrant::Environment do
|
|||
end
|
||||
end
|
||||
|
||||
describe "default provider" do
|
||||
it "should return virtualbox" do
|
||||
instance.default_provider.should == :virtualbox
|
||||
end
|
||||
end
|
||||
|
||||
describe "copying the private SSH key" do
|
||||
it "copies the SSH key into the home directory" do
|
||||
env = isolated_environment
|
||||
|
|
|
@ -53,8 +53,11 @@ describe Vagrant::Plugin::V2::Command do
|
|||
end
|
||||
end
|
||||
|
||||
let(:default_provider) { :virtualbox }
|
||||
|
||||
let(:environment) do
|
||||
env = double("environment")
|
||||
env.stub(:default_provider => default_provider)
|
||||
env.stub(:root_path => "foo")
|
||||
env
|
||||
end
|
||||
|
@ -76,8 +79,8 @@ describe Vagrant::Plugin::V2::Command do
|
|||
bar_vm.stub(:name).and_return("bar")
|
||||
|
||||
environment.stub(:machine_names => [:foo, :bar])
|
||||
environment.stub(:machine).with(:foo, :virtualbox).and_return(foo_vm)
|
||||
environment.stub(:machine).with(:bar, :virtualbox).and_return(bar_vm)
|
||||
environment.stub(:machine).with(:foo, default_provider).and_return(foo_vm)
|
||||
environment.stub(:machine).with(:bar, default_provider).and_return(bar_vm)
|
||||
|
||||
vms = []
|
||||
instance.with_target_vms do |vm|
|
||||
|
@ -98,7 +101,7 @@ describe Vagrant::Plugin::V2::Command do
|
|||
it "yields the given VM if a name is given" do
|
||||
foo_vm = double("foo")
|
||||
|
||||
environment.stub(:machine).with(:foo, :virtualbox).and_return(foo_vm)
|
||||
environment.stub(:machine).with(:foo, default_provider).and_return(foo_vm)
|
||||
|
||||
vms = []
|
||||
instance.with_target_vms("foo") { |vm| vms << vm }
|
||||
|
|
Loading…
Reference in New Issue