Fix some issues with the atomic counter and chef-solo

This commit is contained in:
Mitchell Hashimoto 2011-08-03 21:28:29 -07:00
parent 8ff269c341
commit 7df5cf6c9d
3 changed files with 18 additions and 9 deletions

View File

@ -4,6 +4,14 @@ module Vagrant
# chef-solo and chef-client provisioning are stored. This is **not an actual
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
class Chef < Base
include Util::Counter
def initialize(env, config)
super
config.provisioning_path ||= "/tmp/vagrant-chef-#{get_and_update_counter(:provisioning_path)}"
end
def prepare
raise ChefError, :invalid_provisioner
end
@ -76,8 +84,6 @@ module Vagrant
class Chef < Base
# This is the configuration which is available through `config.chef`
class Config < Vagrant::Config::Base
extend Util::Counter
# Shared config
attr_accessor :node_name
attr_accessor :provisioning_path
@ -95,7 +101,7 @@ module Vagrant
attr_writer :run_list
def initialize
@provisioning_path = "/tmp/vagrant-chef-#{self.class.get_and_update_counter}"
@provisioning_path = nil
@log_level = :info
@json = {}
@http_proxy = nil

View File

@ -5,6 +5,7 @@ module Vagrant
register :chef_solo
extend Util::Counter
include Util::Counter
class Config < Chef::Config
attr_accessor :cookbooks_path
@ -71,7 +72,7 @@ module Vagrant
remote_path = nil
if type == :host
# Path exists on the host, setup the remote path
remote_path = "#{config.provisioning_path}/chef-solo-#{self.class.get_and_update_counter}"
remote_path = "#{config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}"
else
# Path already exists on the virtual machine. Expand it
# relative to where we're provisioning.
@ -88,7 +89,7 @@ module Vagrant
def share_folders(prefix, folders)
folders.each do |type, local_path, remote_path|
if type == :host
env.config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter}",
env.config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}",
remote_path, local_path, :nfs => config.nfs)
end
end

View File

@ -5,11 +5,13 @@ module Vagrant
# Atomic counter implementation. This is useful for incrementing
# a counter which is guaranteed to only be used once in its class.
module Counter
def get_and_update_counter
def get_and_update_counter(name=nil)
name ||= :global
mutex.synchronize do
@__counter ||= 1
result = @__counter
@__counter += 1
@__counter ||= Hash.new(1)
result = @__counter[name]
@__counter[name] += 1
result
end
end