core: allow hooking around provisioner runs

/cc @fgrehm - :) I think you'll understand.
This commit is contained in:
Mitchell Hashimoto 2013-11-24 21:15:22 -08:00
parent d6fb083507
commit 3701b955cb
3 changed files with 12 additions and 43 deletions

View File

@ -20,7 +20,6 @@ module Vagrant
autoload :Lock, "vagrant/action/builtin/lock"
autoload :Provision, "vagrant/action/builtin/provision"
autoload :ProvisionerCleanup, "vagrant/action/builtin/provisioner_cleanup"
autoload :ProvisionerRun, "vagrant/action/builtin/provisioner_run"
autoload :SetHostname, "vagrant/action/builtin/set_hostname"
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
autoload :SSHRun, "vagrant/action/builtin/ssh_run"

View File

@ -66,33 +66,24 @@ module Vagrant
next if env[:provision_types] && \
!env[:provision_types].include?(type_name)
run_provisioner(env, type_name.to_s, p)
env[:ui].info(I18n.t(
"vagrant.actions.vm.provision.beginning",
provisioner: type_name))
env[:hook].call(:provisioner_run, env.merge(
callable: method(:run_provisioner),
provisioner: p,
provisioner_name: type_name,
))
end
end
end
# This is pulled out into a seperate method so that users can
# subclass and implement custom behavior if they'd like around
# subclass and implement custom behavior if they'd like to work around
# this step.
def run_provisioner(env, name, p)
env[:ui].info(I18n.t("vagrant.actions.vm.provision.beginning",
:provisioner => name))
callable = Builder.new.tap { |b| b.use ProvisionerRun, p }
action_runner.run(callable,
:action_name => :provisioner_run,
:provider_name => name
)
end
def action_runner
@action_runner ||= Action::Runner.new do
{
:env => @env[:env],
:machine => @env[:machine],
:ui => @env[:ui]
}
end
def run_provisioner(env)
env[:provisioner].provision
end
end
end

View File

@ -1,21 +0,0 @@
require "log4r"
module Vagrant
module Action
module Builtin
# This action is basically a wrapper on top of provisioner runs that
# enable plugins to hook around the provisioning itself
class ProvisionerRun
def initialize(app, env, provisioner)
@app = app
@provisioner = provisioner
end
def call(env)
@app.call(env)
@provisioner.provision
end
end
end
end
end