From 00ce442de80f3a8865783cd0966578425d81b714 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 18 Oct 2013 18:27:01 -0300 Subject: [PATCH 1/3] core: Allow hooking before and after provisioners --- lib/vagrant/action/builtin/provision.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 99ed32f54ea..3a79c7f9907 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -68,10 +68,30 @@ def call(env) # 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 + action_runner.run(callable, :action_name => name) + end + + def action_runner + @action_runner ||= Action::Runner.new do + { + :env => @env[:env], + :machine => @env[:machine], + :ui => @env[:ui] + } + end end end end From 2debce9dd9a4005449954cea2ab4162093f56fa6 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 19 Oct 2013 12:03:51 -0300 Subject: [PATCH 2/3] 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 52164b462bb..f0717805a57 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -21,6 +21,7 @@ module Builtin 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 3a79c7f9907..0b6830a3943 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -68,19 +68,10 @@ def call(env) # 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 00000000000..70cbc38932d --- /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 From a5c15fd23000ed8a5f3ee1b1199595ed18fbf48e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Mon, 21 Oct 2013 20:50:13 -0200 Subject: [PATCH 3/3] core: Fix action name used for ProvisionerRun --- lib/vagrant/action/builtin/provision.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 0b6830a3943..b40714fd508 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -72,7 +72,10 @@ def run_provisioner(env, name, p) :provisioner => name)) callable = Builder.new.tap { |b| b.use ProvisionerRun, p } - action_runner.run(callable, :action_name => name) + action_runner.run(callable, + :action_name => :provisioner_run, + :provider_name => name + ) end def action_runner