From 3701b955cb9d70917945da4d6d3a8475e8df50c0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 24 Nov 2013 21:15:22 -0800 Subject: [PATCH] core: allow hooking around provisioner runs /cc @fgrehm - :) I think you'll understand. --- lib/vagrant/action.rb | 1 - lib/vagrant/action/builtin/provision.rb | 33 +++++++------------ lib/vagrant/action/builtin/provisioner_run.rb | 21 ------------ 3 files changed, 12 insertions(+), 43 deletions(-) delete mode 100644 lib/vagrant/action/builtin/provisioner_run.rb diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index deafb4a49..eec35987f 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -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" diff --git a/lib/vagrant/action/builtin/provision.rb b/lib/vagrant/action/builtin/provision.rb index 6d21fe7f6..ab0510503 100644 --- a/lib/vagrant/action/builtin/provision.rb +++ b/lib/vagrant/action/builtin/provision.rb @@ -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 diff --git a/lib/vagrant/action/builtin/provisioner_run.rb b/lib/vagrant/action/builtin/provisioner_run.rb deleted file mode 100644 index 70cbc3893..000000000 --- a/lib/vagrant/action/builtin/provisioner_run.rb +++ /dev/null @@ -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