From 2debce9dd9a4005449954cea2ab4162093f56fa6 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 19 Oct 2013 12:03:51 -0300 Subject: [PATCH] core: Improve provisioner hooking by introducing a new builtin action for wrapping provisioner runs --- lib/vagrant/action.rb | 1 + lib/vagrant/action/builtin/provision.rb | 11 +--------- lib/vagrant/action/builtin/provisioner_run.rb | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 lib/vagrant/action/builtin/provisioner_run.rb diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index 52164b462..f0717805a 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -21,6 +21,7 @@ module Vagrant autoload :NFS, "vagrant/action/builtin/nfs" 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" diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 3a79c7f99..0b6830a39 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -68,19 +68,10 @@ module Vagrant # subclass and implement custom behavior if they'd like around # this step. def run_provisioner(env, name, p) - hook(:before_provisioner) - env[:ui].info(I18n.t("vagrant.actions.vm.provision.beginning", :provisioner => name)) - p.provision - - hook(:after_provisioner) - end - - def hook(name) - @logger.info("Running hook: #{name}") - callable = Action::Builder.new + callable = Builder.new.tap { |b| b.use ProvisionerRun, p } action_runner.run(callable, :action_name => name) end diff --git a/lib/vagrant/action/builtin/provisioner_run.rb b/lib/vagrant/action/builtin/provisioner_run.rb new file mode 100644 index 000000000..70cbc3893 --- /dev/null +++ b/lib/vagrant/action/builtin/provisioner_run.rb @@ -0,0 +1,21 @@ +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