Add machine for hook and action triggers

This commit is contained in:
Brian Cain 2019-01-23 14:46:19 -08:00
parent 37d71898a3
commit 071d8b09cd
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
5 changed files with 25 additions and 8 deletions

View File

@ -17,7 +17,10 @@ module Vagrant
end
def call(env)
@triggers.fire_triggers(@action_name, :after, nil, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers");
machine = env[:machine]
machine_name = machine.name if machine
@triggers.fire_triggers(@action_name, :after, machine_name, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers");
# Carry on
@app.call(env)

View File

@ -14,7 +14,10 @@ module Vagrant
end
def call(env)
@triggers.fire_triggers(@action_name, :before, nil, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers");
machine = env[:machine]
machine_name = machine.name if machine
@triggers.fire_triggers(@action_name, :before, machine_name, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers");
# Carry on
@app.call(env)

View File

@ -40,8 +40,11 @@ module Vagrant
# the `env` is coming from, we can wait until they're merged into a single
# hash above.
env = environment[:env]
machine = environment[:machine]
machine_name = machine.name if machine
ui = Vagrant::UI::Prefixed.new(env.ui, "vargant")
triggers = Vagrant::Plugin::V2::Trigger.new(env, env.vagrantfile.config.trigger, nil, ui)
triggers = Vagrant::Plugin::V2::Trigger.new(env, env.vagrantfile.config.trigger, machine, ui)
end
# Setup the action hooks
@ -73,13 +76,14 @@ module Vagrant
end
action_name = environment[:action_name]
triggers.fire_triggers(action_name, :before, nil, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
triggers.fire_triggers(action_name, :before, machine_name, :hook) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
# We place a process lock around every action that is called
@logger.info("Running action: #{environment[:action_name]} #{callable_id}")
Util::Busy.busy(int_callback) { callable.call(environment) }
triggers.fire_triggers(action_name, :after, nil, :action) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
triggers.fire_triggers(action_name, :after, machine_name, :hook) if Vagrant::Util::Experimental.feature_enabled?("typed_triggers")
# Return the environment in case there are things in there that
# the caller wants to use.

View File

@ -26,8 +26,10 @@ module Vagrant
@env = env[:env]
end
machine = env[:machine]
machine_name = machine.name if machine
ui = Vagrant::UI::Prefixed.new(@env.ui, "vargant")
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @env.vagrantfile.config.trigger, nil, ui)
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @env.vagrantfile.config.trigger, machine, ui)
end
@stack = []

View File

@ -9,7 +9,7 @@ module VagrantPlugins
# Defaults
DEFAULT_ON_ERROR = :halt
DEFAULT_EXIT_CODE = 0
VALID_TRIGGER_TYPES = [:command, :action].freeze
VALID_TRIGGER_TYPES = [:command, :action, :hook].freeze
#-------------------------------------------------------------------
# Config class for a given Trigger
@ -227,7 +227,12 @@ module VagrantPlugins
if @type == :action
actions = []
# Get every registered action hook and check if it includes the command defined
# TODO: Get every registered action and check if it includes the command defined
end
if @type == :hook
actions = []
# TODO: Get every registered hook and check if it includes the command defined
end
if @run