Class: Chef::Expander::Configuration::Base
- Inherits:
-
Object
- Object
- Chef::Expander::Configuration::Base
- Includes:
- Loggable
- Defined in:
- lib/chef/expander/configuration.rb
Constant Summary collapse
- DEFAULT_PIDFILE =
Object.new
Constants included from Loggable
Class Method Summary collapse
- .configurable(setting, default = nil, &validation) ⇒ Object
- .configurables ⇒ Object
- .defaults ⇒ Object
- .from_chef_compat_config(file) ⇒ Object
- .from_hash(config_hash) ⇒ Object
- .validations ⇒ Object
Instance Method Summary collapse
- #amqp_config ⇒ Object
- #apply_defaults ⇒ Object
- #fail_if_invalid ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #invalid(message) ⇒ Object
-
#log_level=(level) ⇒ Object
override the setter for log_level to also actually set the level.
-
#log_location=(location) ⇒ Object
override the setter for log_location to re-init the logger.
- #merge_config(other) ⇒ Object
- #pidfile ⇒ Object
- #reset!(stdout = nil) ⇒ Object
-
#solr_url=(url) ⇒ Object
override the setter for solr_url for backward compatibilty.
- #validate! ⇒ Object
- #vnode_numbers ⇒ Object
Methods included from Loggable
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
204 205 206 |
# File 'lib/chef/expander/configuration.rb', line 204 def initialize reset! end |
Class Method Details
.configurable(setting, default = nil, &validation) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/chef/expander/configuration.rb', line 113 def self.configurable(setting, default=nil, &validation) attr_accessor(setting) configurables << setting defaults[setting] = default validations << validation if block_given? setting end |
.configurables ⇒ Object
101 102 103 |
# File 'lib/chef/expander/configuration.rb', line 101 def self.configurables @configurables ||= [] end |
.defaults ⇒ Object
109 110 111 |
# File 'lib/chef/expander/configuration.rb', line 109 def self.defaults @defaults ||= {} end |
.from_chef_compat_config(file) ⇒ Object
84 85 86 87 88 |
# File 'lib/chef/expander/configuration.rb', line 84 def self.from_chef_compat_config(file) config = ChefCompatibleConfig.new config.load(file) from_hash(config.config_hash) end |
.from_hash(config_hash) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/chef/expander/configuration.rb', line 90 def self.from_hash(config_hash) config = new config_hash.each do |setting, value| setter = "#{setting}=".to_sym if config.respond_to?(setter) config.send(setter, value) end end config end |
.validations ⇒ Object
105 106 107 |
# File 'lib/chef/expander/configuration.rb', line 105 def self.validations @validations ||= [] end |
Instance Method Details
#amqp_config ⇒ Object
253 254 255 |
# File 'lib/chef/expander/configuration.rb', line 253 def amqp_config {:host => amqp_host, :port => amqp_port, :user => amqp_user, :pass => amqp_pass, :vhost => amqp_vhost} end |
#apply_defaults ⇒ Object
215 216 217 218 219 |
# File 'lib/chef/expander/configuration.rb', line 215 def apply_defaults self.class.defaults.each do |setting, value| self.send("#{setting}=".to_sym, value) end end |
#fail_if_invalid ⇒ Object
228 229 230 231 232 233 |
# File 'lib/chef/expander/configuration.rb', line 228 def fail_if_invalid validate! rescue InvalidConfiguration => e @stdout.puts("Invalid configuration: #{e.}") exit(1) end |
#invalid(message) ⇒ Object
235 236 237 |
# File 'lib/chef/expander/configuration.rb', line 235 def invalid() raise InvalidConfiguration, end |
#log_level=(level) ⇒ Object
override the setter for log_level to also actually set the level
188 189 190 191 192 193 194 195 |
# File 'lib/chef/expander/configuration.rb', line 188 def log_level=(level) if level #don't accept nil for an answer level = level.to_sym Loggable::LOGGER.level = level @log_level = log_level end level end |
#log_location=(location) ⇒ Object
override the setter for log_location to re-init the logger
200 201 202 |
# File 'lib/chef/expander/configuration.rb', line 200 def log_location=(location) Loggable::LOGGER.init(location) unless location.nil? end |
#merge_config(other) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/chef/expander/configuration.rb', line 221 def merge_config(other) self.class.configurables.each do |setting| value = other.send(setting) self.send("#{setting}=".to_sym, value) if value end end |
#pidfile ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/chef/expander/configuration.rb', line 177 def pidfile if @pidfile.equal?(DEFAULT_PIDFILE) Process.euid == 0 ? '/var/run/chef-expander.pid' : '/tmp/chef-expander.pid' else @pidfile end end |
#reset!(stdout = nil) ⇒ Object
208 209 210 211 212 213 |
# File 'lib/chef/expander/configuration.rb', line 208 def reset!(stdout=nil) self.class.configurables.each do |setting| send("#{setting}=".to_sym, nil) end @stdout = stdout || STDOUT end |
#solr_url=(url) ⇒ Object
override the setter for solr_url for backward compatibilty
149 150 151 152 153 154 155 |
# File 'lib/chef/expander/configuration.rb', line 149 def solr_url=(url) if url && url == "http://localhost:8983" log.warn {"You seem to have a legacy setting for solr_url: did you mean #{url}/solr ?"} url = "#{url}/solr" end @solr_url = url end |
#validate! ⇒ Object
239 240 241 242 243 |
# File 'lib/chef/expander/configuration.rb', line 239 def validate! self.class.validations.each do |validation_proc| instance_eval(&validation_proc) end end |
#vnode_numbers ⇒ Object
245 246 247 248 249 250 251 |
# File 'lib/chef/expander/configuration.rb', line 245 def vnode_numbers vnodes_per_node = VNODES / node_count lower_bound = (index - 1) * vnodes_per_node upper_bound = lower_bound + vnodes_per_node upper_bound += VNODES % vnodes_per_node if index == node_count (lower_bound...upper_bound).to_a end |