core: add option to not lock for Machine#action [GH-4574]

This commit is contained in:
Mitchell Hashimoto 2014-10-24 15:47:37 -07:00
parent adf7c17e65
commit 7b5e5668c5
2 changed files with 7 additions and 2 deletions

View File

@ -88,6 +88,8 @@ BUG FIXES:
PLUGIN AUTHOR CHANGES:
- `Machine#action` can be called with the option `lock: false` to not
acquire a machine lock.
- `Machine#reload` will now properly trigger the `machine_id_changed`
callback on providers.

View File

@ -144,9 +144,12 @@ module Vagrant
# @param [Hash] extra_env This data will be passed into the action runner
# as extra data set on the environment hash for the middleware
# runner.
def action(name, extra_env=nil)
def action(name, extra_env=nil, **opts)
@logger.info("Calling action: #{name} on provider #{@provider}")
# Default to locking
opts[:lock] = true if !opts.has_key?(:lock)
# Create a deterministic ID for this machine
vf = nil
vf = @env.vagrantfile_name[0] if @env.vagrantfile_name
@ -157,7 +160,7 @@ module Vagrant
# we will want to do more fine-grained unlocking in actions themselves
# but for a 1.6.2 release this will work.
locker = Proc.new { |*args, &block| block.call }
locker = @env.method(:lock) if !name.to_s.start_with?("ssh")
locker = @env.method(:lock) if opts[:lock] && !name.to_s.start_with?("ssh")
# Lock this machine for the duration of this action
locker.call("machine-action-#{id}") do