Providers can support multiple box formats if they choose to.
Currently, providers must match a box format exactly the same as that provider's name. i.e. the virtuabox provider needs a "virtualbox" box and the "vmware_fusion" provider needs a "vmware_fusion" box. Now, the provider can specify what the box format is they want and support multiple if wanted. Other box formats are specified in the provider definition within a plugin: class Plugin < Vagrant.plugin("2", "provider") # ... other stuff provider("foo", box_format: ["virtualbox", "other_format"]) do # .. same end end Now when using the example "foo" provider above, boxes for both "virtualbox" or "other_format" are searched for. If both are found, the order in which the formats exist determines precedence.
This commit is contained in:
parent
868f8d4061
commit
96ebd3e8f7
|
@ -30,6 +30,8 @@ FEATURES:
|
|||
certain guest operating systems can implement. This allows greater
|
||||
flexibility in doing guest-specific behavior.
|
||||
- Ansible provisioner support. [GH-1465]
|
||||
- Providers can now support multiple box formats by specifying the
|
||||
`box_format:` option.
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
|
|
|
@ -328,13 +328,27 @@ module Vagrant
|
|||
|
||||
box = nil
|
||||
if config.vm.box
|
||||
begin
|
||||
box = boxes.find(config.vm.box, provider)
|
||||
rescue Errors::BoxUpgradeRequired
|
||||
# Upgrade the box if we must
|
||||
@logger.info("Upgrading box during config load: #{config.vm.box}")
|
||||
boxes.upgrade(config.vm.box)
|
||||
retry
|
||||
# Determine the box formats we support
|
||||
formats = provider_options[:box_format]
|
||||
formats ||= provider
|
||||
formats = [formats] if !formats.is_a?(Array)
|
||||
|
||||
@logger.info("Provider-supported box formats: #{formats.inspect}")
|
||||
formats.each do |format|
|
||||
begin
|
||||
box = boxes.find(config.vm.box, format.to_s)
|
||||
rescue Errors::BoxUpgradeRequired
|
||||
# Upgrade the box if we must
|
||||
@logger.info("Upgrading box during config load: #{config.vm.box}")
|
||||
boxes.upgrade(config.vm.box)
|
||||
retry
|
||||
end
|
||||
|
||||
# If a box was found, we exit
|
||||
if box
|
||||
@logger.info("Box found with format: #{format}")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -408,11 +408,11 @@ VF
|
|||
|
||||
describe "getting a machine" do
|
||||
# A helper to register a provider for use in tests.
|
||||
def register_provider(name, config_class=nil)
|
||||
def register_provider(name, config_class=nil, options=nil)
|
||||
provider_cls = Class.new(Vagrant.plugin("2", :provider))
|
||||
|
||||
register_plugin("2") do |p|
|
||||
p.provider(name) { provider_cls }
|
||||
p.provider(name, options) { provider_cls }
|
||||
|
||||
if config_class
|
||||
p.config(name, :provider) { config_class }
|
||||
|
@ -572,6 +572,56 @@ VF
|
|||
machine.config.ssh.port.should == 100
|
||||
end
|
||||
|
||||
it "should load the box configuration for other formats for a V2 box" do
|
||||
register_provider("foo", nil, box_format: "bar")
|
||||
|
||||
environment = isolated_environment do |env|
|
||||
env.vagrantfile(<<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "base"
|
||||
end
|
||||
VF
|
||||
|
||||
env.box2("base", :bar, :vagrantfile => <<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.ssh.port = 100
|
||||
end
|
||||
VF
|
||||
end
|
||||
|
||||
env = environment.create_vagrant_env
|
||||
machine = env.machine(:default, :foo)
|
||||
machine.config.ssh.port.should == 100
|
||||
end
|
||||
|
||||
it "prefer sooner formats when multiple box formats are available" do
|
||||
register_provider("foo", nil, box_format: ["fA", "fB"])
|
||||
|
||||
environment = isolated_environment do |env|
|
||||
env.vagrantfile(<<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "base"
|
||||
end
|
||||
VF
|
||||
|
||||
env.box2("base", :fA, :vagrantfile => <<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.ssh.port = 100
|
||||
end
|
||||
VF
|
||||
|
||||
env.box2("base", :fB, :vagrantfile => <<-VF)
|
||||
Vagrant.configure("2") do |config|
|
||||
config.ssh.port = 200
|
||||
end
|
||||
VF
|
||||
end
|
||||
|
||||
env = environment.create_vagrant_env
|
||||
machine = env.machine(:default, :foo)
|
||||
machine.config.ssh.port.should == 100
|
||||
end
|
||||
|
||||
it "should load the provider override if set" do
|
||||
register_provider("bar")
|
||||
register_provider("foo")
|
||||
|
|
Loading…
Reference in New Issue