Make Provision a built-in action.
This allows other providers to just use it.
This commit is contained in:
parent
22571bf05b
commit
212e634c3b
|
@ -13,6 +13,7 @@ module Vagrant
|
|||
autoload :Call, "vagrant/action/builtin/call"
|
||||
autoload :Confirm, "vagrant/action/builtin/confirm"
|
||||
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
||||
autoload :Provision, "vagrant/action/builtin/provision"
|
||||
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
||||
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
require "log4r"
|
||||
|
||||
module Vagrant
|
||||
module Action
|
||||
module Builtin
|
||||
# This class will run the configured provisioners against the
|
||||
# machine.
|
||||
#
|
||||
# This action should be placed BEFORE the machine is booted so it
|
||||
# can do some setup, and then run again (on the return path) against
|
||||
# a running machine.
|
||||
class Provision
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@logger = Log4r::Logger.new("vagrant::action::builtin::provision")
|
||||
end
|
||||
|
||||
def call(env)
|
||||
# Get all the configured provisioners
|
||||
provisioners = env[:machine].config.vm.provisioners.map do |provisioner|
|
||||
provisioner.provisioner.new(env, provisioner.config)
|
||||
end
|
||||
|
||||
# Instantiate and prepare them.
|
||||
provisioners.map { |p| p.prepare }
|
||||
|
||||
# Continue, we need the VM to be booted.
|
||||
@app.call(env)
|
||||
|
||||
# Actually provision
|
||||
provisioners.each do |p|
|
||||
env[:ui].info(I18n.t("vagrant.actions.vm.provision.beginning",
|
||||
:provisioner => p.class))
|
||||
|
||||
p.provision!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ module VagrantPlugins
|
|||
attr_accessor :shell
|
||||
|
||||
def validate(env, errors)
|
||||
[:username, :host, :max_tries, :timeout].each do |field|
|
||||
[:username, :max_tries, :timeout].each do |field|
|
||||
value = instance_variable_get("@#{field}".to_sym)
|
||||
errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !value
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ module VagrantPlugins
|
|||
return
|
||||
end
|
||||
|
||||
if !(provisioner <= Vagrant.plugin("1", :provisioner))
|
||||
if !(provisioner <= Vagrant.plugin("2", :provisioner))
|
||||
errors.add(I18n.t("vagrant.config.vm.provisioner_invalid_class", :shortcut => shortcut))
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ module VagrantPlugins
|
|||
autoload :NFS, File.expand_path("../action/nfs", __FILE__)
|
||||
autoload :Package, File.expand_path("../action/package", __FILE__)
|
||||
autoload :PackageVagrantfile, File.expand_path("../action/package_vagrantfile", __FILE__)
|
||||
autoload :Provision, File.expand_path("../action/provision", __FILE__)
|
||||
autoload :ProvisionerCleanup, File.expand_path("../action/provisioner_cleanup", __FILE__)
|
||||
autoload :PruneNFSExports, File.expand_path("../action/prune_nfs_exports", __FILE__)
|
||||
autoload :Resume, File.expand_path("../action/resume", __FILE__)
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
require "log4r"
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class Provision
|
||||
def initialize(app, env)
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::provision")
|
||||
@app = app
|
||||
|
||||
env["provision.enabled"] = true if !env.has_key?("provision.enabled")
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@env = env
|
||||
|
||||
provisioners = nil
|
||||
|
||||
# We set this here so that even if this value is changed in the future,
|
||||
# it stays constant to what we expect here in this moment.
|
||||
enabled = env["provision.enabled"]
|
||||
|
||||
# Instantiate and prepare the provisioners. Preparation must happen here
|
||||
# so that shared folders and such can properly take effect.
|
||||
provisioners = enabled_provisioners
|
||||
provisioners.map { |p| p.prepare }
|
||||
|
||||
@app.call(env)
|
||||
|
||||
if enabled
|
||||
# Take prepared provisioners and run the provisioning
|
||||
provisioners.each do |instance|
|
||||
@env[:ui].info I18n.t("vagrant.actions.vm.provision.beginning",
|
||||
:provisioner => instance.class)
|
||||
instance.provision!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def enabled_provisioners
|
||||
enabled = []
|
||||
@env[:machine].config.vm.provisioners.each do |provisioner|
|
||||
if @env["provision.types"]
|
||||
# If we've specified types of provisioners to enable, then we
|
||||
# only use those provisioners, and skip any that we haven't
|
||||
# specified.
|
||||
if !@env["provision.types"].include?(provisioner.shortcut.to_s)
|
||||
@logger.debug("Skipping provisioner: #{provisioner.shortcut}")
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
enabled << provisioner.provisioner.new(@env, provisioner.config)
|
||||
end
|
||||
|
||||
# Return the enable provisioners
|
||||
enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue