core: Environment#default_provider can look into machines
This commit is contained in:
parent
4d85e0e145
commit
768d453739
|
@ -308,10 +308,19 @@ module Vagrant
|
||||||
# that (the default behavior)
|
# that (the default behavior)
|
||||||
return default if default && opts[:force_default]
|
return default if default && opts[:force_default]
|
||||||
|
|
||||||
|
# Determine the config to use to look for provider definitions. By
|
||||||
|
# default it is the global but if we're targeting a specific machine,
|
||||||
|
# then look there.
|
||||||
|
root_config = vagrantfile.config
|
||||||
|
if opts[:machine]
|
||||||
|
machine_info = vagrantfile.machine_config(opts[:machine], nil, nil)
|
||||||
|
root_config = machine_info[:config]
|
||||||
|
end
|
||||||
|
|
||||||
# Get the list of providers within our configuration and assign
|
# Get the list of providers within our configuration and assign
|
||||||
# a priority to each in the order they exist so that we try these first.
|
# a priority to each in the order they exist so that we try these first.
|
||||||
config = {}
|
config = {}
|
||||||
vagrantfile.config.vm.__providers.each_with_index do |key, idx|
|
root_config.vm.__providers.each_with_index do |key, idx|
|
||||||
config[key] = idx
|
config[key] = idx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -114,24 +114,30 @@ module Vagrant
|
||||||
name: name, provider: provider
|
name: name, provider: provider
|
||||||
end
|
end
|
||||||
|
|
||||||
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
provider_plugin = nil
|
||||||
if !provider_plugin
|
provider_cls = nil
|
||||||
raise Errors::ProviderNotFound,
|
provider_options = {}
|
||||||
machine: name, provider: provider
|
box_formats = nil
|
||||||
end
|
if provider != nil
|
||||||
|
provider_plugin = Vagrant.plugin("2").manager.providers[provider]
|
||||||
|
if !provider_plugin
|
||||||
|
raise Errors::ProviderNotFound,
|
||||||
|
machine: name, provider: provider
|
||||||
|
end
|
||||||
|
|
||||||
provider_cls = provider_plugin[0]
|
provider_cls = provider_plugin[0]
|
||||||
provider_options = provider_plugin[1]
|
provider_options = provider_plugin[1]
|
||||||
box_formats = provider_options[:box_format] || provider
|
box_formats = provider_options[:box_format] || provider
|
||||||
|
|
||||||
# Test if the provider is usable or not
|
# Test if the provider is usable or not
|
||||||
begin
|
begin
|
||||||
provider_cls.usable?(true)
|
provider_cls.usable?(true)
|
||||||
rescue Errors::VagrantError => e
|
rescue Errors::VagrantError => e
|
||||||
raise Errors::ProviderNotUsable,
|
raise Errors::ProviderNotUsable,
|
||||||
machine: name.to_s,
|
machine: name.to_s,
|
||||||
provider: provider.to_s,
|
provider: provider.to_s,
|
||||||
message: e.to_s
|
message: e.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add the sub-machine configuration to the loader and keys
|
# Add the sub-machine configuration to the loader and keys
|
||||||
|
@ -153,7 +159,7 @@ module Vagrant
|
||||||
local_keys = keys.dup
|
local_keys = keys.dup
|
||||||
|
|
||||||
# Load the box Vagrantfile, if there is one
|
# Load the box Vagrantfile, if there is one
|
||||||
if config.vm.box
|
if config.vm.box && boxes
|
||||||
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
box = boxes.find(config.vm.box, box_formats, config.vm.box_version)
|
||||||
if box
|
if box
|
||||||
box_vagrantfile = find_vagrantfile(box.directory)
|
box_vagrantfile = find_vagrantfile(box.directory)
|
||||||
|
|
|
@ -822,7 +822,7 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is the provider in the Vagrantfile that is usable" do
|
it "is the highest usable provider outside the Vagrantfile" do
|
||||||
subject.vagrantfile.config.vm.provider "foo"
|
subject.vagrantfile.config.vm.provider "foo"
|
||||||
subject.vagrantfile.config.vm.finalize!
|
subject.vagrantfile.config.vm.finalize!
|
||||||
|
|
||||||
|
@ -835,6 +835,23 @@ VF
|
||||||
expect(subject.default_provider).to eq(:bar)
|
expect(subject.default_provider).to eq(:bar)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is the provider in the Vagrantfile that is usable for a machine" do
|
||||||
|
subject.vagrantfile.config.vm.provider "foo"
|
||||||
|
subject.vagrantfile.config.vm.define "sub" do |v|
|
||||||
|
v.vm.provider "bar"
|
||||||
|
end
|
||||||
|
subject.vagrantfile.config.vm.finalize!
|
||||||
|
|
||||||
|
plugin_providers[:foo] = [provider_usable_class(true), { priority: 5 }]
|
||||||
|
plugin_providers[:bar] = [provider_usable_class(true), { priority: 7 }]
|
||||||
|
plugin_providers[:baz] = [provider_usable_class(true), { priority: 2 }]
|
||||||
|
plugin_providers[:boom] = [provider_usable_class(true), { priority: 3 }]
|
||||||
|
|
||||||
|
with_temp_env("VAGRANT_DEFAULT_PROVIDER" => nil) do
|
||||||
|
expect(subject.default_provider(machine: :sub)).to eq(:bar)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "local data path" do
|
describe "local data path" do
|
||||||
|
|
|
@ -149,6 +149,21 @@ describe Vagrant::Vagrantfile do
|
||||||
expect(results[:provider_cls]).to equal(provider_cls)
|
expect(results[:provider_cls]).to equal(provider_cls)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "configures without a provider or boxes" do
|
||||||
|
register_provider("foo")
|
||||||
|
|
||||||
|
configure do |config|
|
||||||
|
config.vm.box = "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
results = subject.machine_config(:default, nil, nil)
|
||||||
|
box = results[:box]
|
||||||
|
config = results[:config]
|
||||||
|
expect(config.vm.box).to eq("foo")
|
||||||
|
expect(box).to be_nil
|
||||||
|
expect(results[:provider_cls]).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it "configures with sub-machine config" do
|
it "configures with sub-machine config" do
|
||||||
register_provider("foo")
|
register_provider("foo")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue