Switch chef configuration to new-style

This commit is contained in:
Mitchell Hashimoto 2013-04-15 12:08:08 -07:00
parent 4cd9c4a231
commit 79099086f5
4 changed files with 79 additions and 46 deletions

View File

@ -2,42 +2,62 @@ module VagrantPlugins
module Chef module Chef
module Config module Config
class Base < Vagrant.plugin("2", :config) class Base < Vagrant.plugin("2", :config)
# Shared config attr_accessor :arguments
attr_accessor :node_name attr_accessor :attempts
attr_accessor :provisioning_path attr_accessor :binary_path
attr_accessor :log_level attr_accessor :binary_env
attr_accessor :json
attr_accessor :http_proxy attr_accessor :http_proxy
attr_accessor :http_proxy_user attr_accessor :http_proxy_user
attr_accessor :http_proxy_pass attr_accessor :http_proxy_pass
attr_accessor :https_proxy attr_accessor :https_proxy
attr_accessor :https_proxy_user attr_accessor :https_proxy_user
attr_accessor :https_proxy_pass attr_accessor :https_proxy_pass
attr_accessor :json
attr_accessor :log_level
attr_accessor :no_proxy attr_accessor :no_proxy
attr_accessor :binary_path attr_accessor :node_name
attr_accessor :binary_env attr_accessor :provisioning_path
attr_accessor :attempts attr_accessor :run_list
attr_accessor :arguments
attr_writer :run_list
# Provide defaults in such a way that they won't override the instance def initialize
# variable. This is so merging continues to work properly. super
def attempts; @attempts || 1; end
def json; @json ||= {}; end
def log_level; @log_level || :info; end
# This returns the json that is merged with the defaults and the @arguments = UNSET_VALUE
# user set data. @attempts = UNSET_VALUE
def merged_json @binary_path = UNSET_VALUE
original = { :instance_role => "vagrant" } @binary_env = UNSET_VALUE
original[:run_list] = @run_list if @run_list @http_proxy = UNSET_VALUE
original.merge(json || {}) @http_proxy_user = UNSET_VALUE
@http_proxy_pass = UNSET_VALUE
@https_proxy = UNSET_VALUE
@https_proxy_user = UNSET_VALUE
@https_proxy_pass = UNSET_VALUE
@log_level = UNSET_VALUE
@no_proxy = UNSET_VALUE
@node_name = UNSET_VALUE
@provisioning_path = UNSET_VALUE
@json = {}
@run_list = []
end end
# Returns the run list, but also sets it up to be empty if it def finalize!
# hasn't been defined already. @arguments = nil if @arguments == UNSET_VALUE
def run_list @attempts = 1 if @attempts == UNSET_VALUE
@run_list ||= [] @binary_path = nil if @binary_path == UNSET_VALUE
@binary_env = nil if @binary_env == UNSET_VALUE
@http_proxy = nil if @http_proxy == UNSET_VALUE
@http_proxy_user = nil if @http_proxy_user == UNSET_VALUE
@http_proxy_pass = nil if @http_proxy_pass == UNSET_VALUE
@https_proxy = nil if @https_proxy == UNSET_VALUE
@https_proxy_user = nil if @https_proxy_user == UNSET_VALUE
@https_proxy_pass = nil if @https_proxy_pass == UNSET_VALUE
@log_level = :info if @log_level == UNSET_VALUE
@no_proxy = nil if @no_proxy == UNSET_VALUE
@provisioning_path = nil if @provisioning_path == UNSET_VALUIE
# Make sure the log level is a symbol
@log_level = @log_level.to_sym
end end
# Adds a recipe to the run list # Adds a recipe to the run list
@ -51,14 +71,6 @@ module VagrantPlugins
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/ name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/
run_list << name run_list << name
end end
def instance_variables_hash
# Overridden so that the 'json' key could be removed, since its just
# merged into the config anyways
result = super
result.delete("json")
result
end
end end
end end
end end

View File

@ -5,22 +5,41 @@ module VagrantPlugins
module Config module Config
class ChefClient < Base class ChefClient < Base
attr_accessor :chef_server_url attr_accessor :chef_server_url
attr_accessor :validation_key_path
attr_accessor :validation_client_name
attr_accessor :client_key_path attr_accessor :client_key_path
attr_accessor :file_cache_path
attr_accessor :file_backup_path
attr_accessor :environment
attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret_key_path
attr_accessor :encrypted_data_bag_secret attr_accessor :encrypted_data_bag_secret
attr_accessor :environment
attr_accessor :file_cache_path
attr_accessor :file_backup_path
attr_accessor :validation_key_path
attr_accessor :validation_client_name
# Provide defaults in such a way that they won't override the instance def initialize
# variable. This is so merging continues to work properly. super
def validation_client_name; @validation_client_name || "chef-validator"; end
def client_key_path; @client_key_path || "/etc/chef/client.pem"; end @chef_server_url = UNSET_VALUE
def file_cache_path; @file_cache_path || "/srv/chef/file_store"; end @client_key_path = UNSET_VALUE
def file_backup_path; @file_backup_path || "/srv/chef/cache"; end @encrypted_data_bag_secret_key_path = UNSET_VALUE
def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end @encrypted_data_bag_secret = UNSET_VALUE
@environment = UNSET_VALUE
@file_cache_path = UNSET_VALUE
@file_backup_path = UNSET_VALUE
@validation_key_path = UNSET_VALUE
@validation_client_name = UNSET_VALUE
end
def finalize!
super
@client_key_path = "/etc/chef/client.pem" if @client_key_path == UNSET_VALUE
@file_backup_path = "/srv/chef/cache" if @file_backup_path == UNSET_VALUE
@file_cache_path = "/srv/chef/file_store" if @file_cache_path == UNSET_VALUE
@validation_client_name = "chef-validator" if @validation_client_name == UNSET_VALUE
if @encrypted_data_bag_secret == UNSET_VALUE
@encrypted_data_bag_secret = "/tmp/encrypted_data_bag_secret"
end
end
def validate(machine) def validate(machine)
errors = _detected_errors errors = _detected_errors

View File

@ -31,6 +31,8 @@ module VagrantPlugins
#------------------------------------------------------------ #------------------------------------------------------------
def finalize! def finalize!
super
@recipe_url = nil if @recipe_url == UNSET_VALUE @recipe_url = nil if @recipe_url == UNSET_VALUE
if @cookbooks_path == UNSET_VALUE if @cookbooks_path == UNSET_VALUE

View File

@ -75,7 +75,7 @@ module VagrantPlugins
@machine.env.ui.info I18n.t("vagrant.provisioners.chef.json") @machine.env.ui.info I18n.t("vagrant.provisioners.chef.json")
# Get the JSON that we're going to expose to Chef # Get the JSON that we're going to expose to Chef
json = JSON.pretty_generate(@config.merged_json) json = JSON.pretty_generate(@config.json)
# Create a temporary file to store the data so we # Create a temporary file to store the data so we
# can upload it # can upload it