New HandleBoxUrl built-in middleware to handlet the "box_url" config
This commit is contained in:
parent
3b75652256
commit
165dd63f78
|
@ -15,6 +15,7 @@ module Vagrant
|
||||||
autoload :ConfigValidate, "vagrant/action/builtin/config_validate"
|
autoload :ConfigValidate, "vagrant/action/builtin/config_validate"
|
||||||
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
||||||
autoload :GracefulHalt, "vagrant/action/builtin/graceful_halt"
|
autoload :GracefulHalt, "vagrant/action/builtin/graceful_halt"
|
||||||
|
autoload :HandleBoxUrl, "vagrant/action/builtin/handle_box_url"
|
||||||
autoload :Lock, "vagrant/action/builtin/lock"
|
autoload :Lock, "vagrant/action/builtin/lock"
|
||||||
autoload :Provision, "vagrant/action/builtin/provision"
|
autoload :Provision, "vagrant/action/builtin/provision"
|
||||||
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
module Vagrant
|
||||||
|
module Action
|
||||||
|
module Builtin
|
||||||
|
# This built-in middleware handles the `box_url` setting, downloading
|
||||||
|
# the box if necessary. You should place this early in your middleware
|
||||||
|
# sequence for a provider after configuration validation but before
|
||||||
|
# you attempt to use any box.
|
||||||
|
class HandleBoxUrl
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
if !env[:machine].box
|
||||||
|
# We can assume a box URL is set because the Vagrantfile
|
||||||
|
# validation should do this for us. If not, though, we do
|
||||||
|
# raise a terrible runtime error.
|
||||||
|
box_name = env[:machine].config.vm.box
|
||||||
|
box_url = env[:machine].config.vm.box_url
|
||||||
|
|
||||||
|
# Add the box then reload the box collection so that it becomes
|
||||||
|
# aware of it.
|
||||||
|
env[:ui].info I18n.t(
|
||||||
|
"vagrant.actions.vm.check_box.not_found",
|
||||||
|
:name => box_name,
|
||||||
|
:provider => env[:machine].provider_name)
|
||||||
|
env[:action_runner].run(Vagrant::Action.action_box_add, {
|
||||||
|
:box_name => box_name,
|
||||||
|
:box_provider => env[:machine].provider_name,
|
||||||
|
:box_url => box_url
|
||||||
|
})
|
||||||
|
|
||||||
|
# Reload the environment and set the VM to be the new loaded VM.
|
||||||
|
env[:machine] = env[:machine].env.machine(
|
||||||
|
env[:machine].name, env[:machine].provider_name, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -119,7 +119,7 @@ module Vagrant
|
||||||
next if data.empty?
|
next if data.empty?
|
||||||
|
|
||||||
io_name = r == stdout ? :stdout : :stderr
|
io_name = r == stdout ? :stdout : :stderr
|
||||||
@logger.debug("#{io_name}: #{data}")
|
@logger.debug("#{io_name}: #{data.chomp}")
|
||||||
|
|
||||||
io_data[io_name] += data
|
io_data[io_name] += data
|
||||||
yield io_name, data if block_given? && notify_table[io_name]
|
yield io_name, data if block_given? && notify_table[io_name]
|
||||||
|
@ -161,7 +161,7 @@ module Vagrant
|
||||||
# Log it out and accumulate
|
# Log it out and accumulate
|
||||||
io_name = io == stdout ? :stdout : :stderr
|
io_name = io == stdout ? :stdout : :stderr
|
||||||
io_data[io_name] += extra_data
|
io_data[io_name] += extra_data
|
||||||
@logger.debug("#{io_name}: #{extra_data}")
|
@logger.debug("#{io_name}: #{extra_data.chomp}")
|
||||||
|
|
||||||
# Yield to any listeners any remaining data
|
# Yield to any listeners any remaining data
|
||||||
yield io_name, extra_data if block_given?
|
yield io_name, extra_data if block_given?
|
||||||
|
|
|
@ -5,7 +5,6 @@ module VagrantPlugins
|
||||||
module Action
|
module Action
|
||||||
autoload :Boot, File.expand_path("../action/boot", __FILE__)
|
autoload :Boot, File.expand_path("../action/boot", __FILE__)
|
||||||
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
||||||
autoload :CheckBox, File.expand_path("../action/check_box", __FILE__)
|
|
||||||
autoload :CheckCreated, File.expand_path("../action/check_created", __FILE__)
|
autoload :CheckCreated, File.expand_path("../action/check_created", __FILE__)
|
||||||
autoload :CheckGuestAdditions, File.expand_path("../action/check_guest_additions", __FILE__)
|
autoload :CheckGuestAdditions, File.expand_path("../action/check_guest_additions", __FILE__)
|
||||||
autoload :CheckPortCollisions, File.expand_path("../action/check_port_collisions", __FILE__)
|
autoload :CheckPortCollisions, File.expand_path("../action/check_port_collisions", __FILE__)
|
||||||
|
@ -293,7 +292,7 @@ module VagrantPlugins
|
||||||
# If the VM is NOT created yet, then do the setup steps
|
# If the VM is NOT created yet, then do the setup steps
|
||||||
if !env[:result]
|
if !env[:result]
|
||||||
b2.use CheckAccessible
|
b2.use CheckAccessible
|
||||||
b2.use CheckBox
|
b2.use HandleBoxUrl
|
||||||
b2.use Import
|
b2.use Import
|
||||||
b2.use CheckGuestAdditions
|
b2.use CheckGuestAdditions
|
||||||
b2.use MatchMACAddress
|
b2.use MatchMACAddress
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module ProviderVirtualBox
|
|
||||||
module Action
|
|
||||||
class CheckBox
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
box_name = env[:machine].config.vm.box
|
|
||||||
raise Vagrant::Errors::BoxNotSpecified if !box_name
|
|
||||||
|
|
||||||
if !env[:box_collection].find(box_name, :virtualbox)
|
|
||||||
box_url = env[:machine].config.vm.box_url
|
|
||||||
raise Vagrant::Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url
|
|
||||||
|
|
||||||
# Add the box then reload the box collection so that it becomes
|
|
||||||
# aware of it.
|
|
||||||
env[:ui].info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
|
|
||||||
env[:action_runner].run(Vagrant::Action.action_box_add, {
|
|
||||||
:box_name => box_name,
|
|
||||||
:box_provider => env[:machine].provider_name,
|
|
||||||
:box_url => box_url
|
|
||||||
})
|
|
||||||
|
|
||||||
# Reload the environment and set the VM to be the new loaded VM.
|
|
||||||
env[:machine] = env[:machine].env.machine(
|
|
||||||
env[:machine].name, env[:machine].provider_name, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -500,7 +500,12 @@ en:
|
||||||
Specific bridge '%{bridge}' not found. You may be asked to specify
|
Specific bridge '%{bridge}' not found. You may be asked to specify
|
||||||
which network to bridge to.
|
which network to bridge to.
|
||||||
check_box:
|
check_box:
|
||||||
not_found: Box %{name} was not found. Fetching box from specified URL...
|
not_found: |-
|
||||||
|
Box '%{name}' was not found. Fetching box from specified URL for
|
||||||
|
the provider '%{provider}'. Note that if the URL does not have
|
||||||
|
a box for this provider, you should interrupt Vagrant now and add
|
||||||
|
the box yourself. Otherwise Vagrant will attempt to download the
|
||||||
|
full box prior to discovering this error.
|
||||||
not_specified: |-
|
not_specified: |-
|
||||||
No base box was specified! A base box is required as a staring point
|
No base box was specified! A base box is required as a staring point
|
||||||
for every vagrant virtual machine. Please specify one in your Vagrantfile
|
for every vagrant virtual machine. Please specify one in your Vagrantfile
|
||||||
|
|
Loading…
Reference in New Issue