diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index ce2278b3b..12ea8b8dc 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -160,7 +160,7 @@ module Vagrant # as extra data set on the environment hash for the middleware # runner. def action(name, opts=nil) - @triggers.fire_before_triggers(name, @name.to_s) + @triggers.fire_triggers(name, :before, @name.to_s) @logger.info("Calling action: #{name} on provider #{@provider}") opts ||= {} @@ -206,7 +206,7 @@ module Vagrant action_result end - @triggers.fire_after_triggers(name, @name.to_s) + @triggers.fire_triggers(name, :after, @name.to_s) rescue Errors::EnvironmentLockedError raise Errors::MachineActionLockedError, action: name, diff --git a/lib/vagrant/plugin/v2/trigger.rb b/lib/vagrant/plugin/v2/trigger.rb index aaab484a1..45b611a51 100644 --- a/lib/vagrant/plugin/v2/trigger.rb +++ b/lib/vagrant/plugin/v2/trigger.rb @@ -23,36 +23,31 @@ module Vagrant @logger = Log4r::Logger.new("vagrant::trigger::#{self.class.to_s.downcase}") end - # Fires all before triggers, if any are defined for the action and guest + # Fires all triggers, if any are defined for the action and guest # # @param [Symbol] action Vagrant command to fire trigger on + # @param [Symbol] stage :before or :after # @param [String] guest_name The guest that invoked firing the triggers - def fire_before_triggers(action, guest_name) + def fire_triggers(action, stage, guest_name) # get all triggers matching action - triggers = config.before_triggers.select { |t| t.command == action } + triggers = [] + if stage == :before + triggers = config.before_triggers.select { |t| t.command == action } + elsif stage == :after + triggers = config.after_triggers.select { |t| t.command == action } + else + # raise error, stage was not given + # This is an internal error + # TODO: Make sure this error exist + raise Errors::Triggers::NoStageGiven + end + triggers = filter_triggers(triggers, guest_name) unless triggers.empty? @logger.info("Firing trigger for action #{action} on guest #{guest_name}") # TODO I18N me - @machine_ui.info("Running triggers before #{action}...") - fire(triggers, guest_name) - end - end - - # Fires all after triggers, if any are defined for the action and guest - # - # @param [Symbol] action Vagrant command to fire trigger on - # @param [String] guest_name The guest that invoked firing the triggers - def fire_after_triggers(action, guest_name) - # get all triggers matching action - triggers = config.after_triggers.select { |t| t.command == action } - triggers = filter_triggers(triggers, guest_name) - - unless triggers.empty? - @logger.info("Firing triggers for action #{action} on guest #{guest_name}") - # TODO I18N me - @machine_ui.info("Running triggers after #{action}...") + @machine_ui.info("Running triggers #{stage} #{action}...") fire(triggers, guest_name) end end