2013-12-06 20:26:48 +00:00
|
|
|
require "vagrant/util/counter"
|
|
|
|
|
2013-01-14 00:41:32 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
module Config
|
|
|
|
class Base < Vagrant.plugin("2", :config)
|
2013-12-06 20:26:48 +00:00
|
|
|
extend Vagrant::Util::Counter
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# The path to Chef's bin/ directory.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :binary_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# Arbitrary environment variables to set before running the Chef
|
|
|
|
# provisioner command.
|
|
|
|
# @return [String]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :binary_env
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The Chef log level. See the Chef docs for acceptable values.
|
|
|
|
# @return [String, Symbol]
|
2013-04-15 19:08:08 +00:00
|
|
|
attr_accessor :log_level
|
2014-10-31 18:22:09 +00:00
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
@binary_path = UNSET_VALUE
|
|
|
|
@binary_env = UNSET_VALUE
|
|
|
|
@log_level = UNSET_VALUE
|
2014-01-17 02:03:38 +00:00
|
|
|
end
|
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
def finalize!
|
2014-10-31 18:22:09 +00:00
|
|
|
@binary_path = nil if @binary_path == UNSET_VALUE
|
|
|
|
@binary_env = nil if @binary_env == UNSET_VALUE
|
|
|
|
@log_level = :info if @log_level == UNSET_VALUE
|
2013-04-15 19:08:08 +00:00
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# Make sure the version is a symbol if it's not a boolean
|
|
|
|
if @version.respond_to?(:to_sym)
|
|
|
|
@version = @version.to_sym
|
2014-01-17 02:03:38 +00:00
|
|
|
end
|
|
|
|
|
2013-04-15 19:08:08 +00:00
|
|
|
# Make sure the log level is a symbol
|
|
|
|
@log_level = @log_level.to_sym
|
2013-04-16 20:23:00 +00:00
|
|
|
end
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# Like validate, but returns a list of errors to append.
|
|
|
|
#
|
|
|
|
# @return [Array<String>]
|
2013-07-11 02:31:52 +00:00
|
|
|
def validate_base(machine)
|
2013-09-04 23:56:45 +00:00
|
|
|
errors = _detected_errors
|
2013-07-11 02:31:52 +00:00
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
if missing?(log_level)
|
|
|
|
errors << I18n.t("vagrant.provisioners.chef.log_level_empty")
|
2013-07-11 02:31:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
errors
|
|
|
|
end
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# Determine if the given string is "missing" (blank)
|
|
|
|
# @return [true, false]
|
|
|
|
def missing?(obj)
|
|
|
|
obj.to_s.strip.empty?
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|