Fix some issues with the atomic counter and chef-solo
This commit is contained in:
parent
8ff269c341
commit
7df5cf6c9d
|
@ -4,6 +4,14 @@ module Vagrant
|
||||||
# chef-solo and chef-client provisioning are stored. This is **not an actual
|
# chef-solo and chef-client provisioning are stored. This is **not an actual
|
||||||
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
|
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
|
||||||
class Chef < Base
|
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
|
def prepare
|
||||||
raise ChefError, :invalid_provisioner
|
raise ChefError, :invalid_provisioner
|
||||||
end
|
end
|
||||||
|
@ -76,8 +84,6 @@ module Vagrant
|
||||||
class Chef < Base
|
class Chef < Base
|
||||||
# This is the configuration which is available through `config.chef`
|
# This is the configuration which is available through `config.chef`
|
||||||
class Config < Vagrant::Config::Base
|
class Config < Vagrant::Config::Base
|
||||||
extend Util::Counter
|
|
||||||
|
|
||||||
# Shared config
|
# Shared config
|
||||||
attr_accessor :node_name
|
attr_accessor :node_name
|
||||||
attr_accessor :provisioning_path
|
attr_accessor :provisioning_path
|
||||||
|
@ -95,7 +101,7 @@ module Vagrant
|
||||||
attr_writer :run_list
|
attr_writer :run_list
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@provisioning_path = "/tmp/vagrant-chef-#{self.class.get_and_update_counter}"
|
@provisioning_path = nil
|
||||||
@log_level = :info
|
@log_level = :info
|
||||||
@json = {}
|
@json = {}
|
||||||
@http_proxy = nil
|
@http_proxy = nil
|
||||||
|
|
|
@ -5,6 +5,7 @@ module Vagrant
|
||||||
register :chef_solo
|
register :chef_solo
|
||||||
|
|
||||||
extend Util::Counter
|
extend Util::Counter
|
||||||
|
include Util::Counter
|
||||||
|
|
||||||
class Config < Chef::Config
|
class Config < Chef::Config
|
||||||
attr_accessor :cookbooks_path
|
attr_accessor :cookbooks_path
|
||||||
|
@ -71,7 +72,7 @@ module Vagrant
|
||||||
remote_path = nil
|
remote_path = nil
|
||||||
if type == :host
|
if type == :host
|
||||||
# Path exists on the host, setup the remote path
|
# 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
|
else
|
||||||
# Path already exists on the virtual machine. Expand it
|
# Path already exists on the virtual machine. Expand it
|
||||||
# relative to where we're provisioning.
|
# relative to where we're provisioning.
|
||||||
|
@ -88,7 +89,7 @@ module Vagrant
|
||||||
def share_folders(prefix, folders)
|
def share_folders(prefix, folders)
|
||||||
folders.each do |type, local_path, remote_path|
|
folders.each do |type, local_path, remote_path|
|
||||||
if type == :host
|
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)
|
remote_path, local_path, :nfs => config.nfs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,11 +5,13 @@ module Vagrant
|
||||||
# Atomic counter implementation. This is useful for incrementing
|
# Atomic counter implementation. This is useful for incrementing
|
||||||
# a counter which is guaranteed to only be used once in its class.
|
# a counter which is guaranteed to only be used once in its class.
|
||||||
module Counter
|
module Counter
|
||||||
def get_and_update_counter
|
def get_and_update_counter(name=nil)
|
||||||
|
name ||= :global
|
||||||
|
|
||||||
mutex.synchronize do
|
mutex.synchronize do
|
||||||
@__counter ||= 1
|
@__counter ||= Hash.new(1)
|
||||||
result = @__counter
|
result = @__counter[name]
|
||||||
@__counter += 1
|
@__counter[name] += 1
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue