class MCollective::Config
A pretty sucky config class, ripe for refactoring/improving
Attributes
activate_agents[R]
classesfile[R]
collectives[R]
color[R]
configdir[R]
configfile[R]
configured[R]
connection_timeout[R]
connector[R]
daemonize[R]
default_batch_size[R]
default_batch_sleep_time[R]
default_discovery_method[R]
default_discovery_options[R]
direct_addressing[R]
direct_addressing_threshold[R]
discovery_timeout[R]
fact_cache_time[R]
factsource[R]
identity[R]
keeplogs[R]
logfacility[R]
logfile[R]
logger_type[R]
loglevel[R]
main_collective[R]
max_log_size[R]
mode[RW]
pluginconf[R]
publish_timeout[R]
registerinterval[R]
registration[R]
registration_collective[R]
registration_splay[R]
rpcaudit[R]
rpcauditprovider[R]
rpcauthprovider[R]
rpclimitmethod[R]
securityprovider[R]
soft_shutdown[R]
soft_shutdown_timeout[R]
ssl_cipher[R]
threaded[R]
ttl[R]
Public Class Methods
new()
click to toggle source
# File lib/mcollective/config.rb 22 def initialize 23 @configured = false 24 end
Public Instance Methods
libdir()
click to toggle source
# File lib/mcollective/config.rb 223 def libdir 224 $LOAD_PATH 225 end
loadconfig(configfile)
click to toggle source
# File lib/mcollective/config.rb 26 def loadconfig(configfile) 27 set_config_defaults(configfile) 28 29 if File.exists?(configfile) 30 libdirs = [] 31 File.readlines(configfile).each do |line| 32 33 # strip blank spaces, tabs etc off the end of all lines 34 line.gsub!(/\s*$/, "") 35 36 unless line =~ /^#|^$/ 37 if (line =~ /(.+?)\s*=\s*(.+)/) 38 key = $1.strip 39 val = $2 40 41 begin 42 case key 43 when "registration" 44 @registration = val.capitalize 45 when "registration_collective" 46 @registration_collective = val 47 when "registerinterval" 48 @registerinterval = Integer(val) 49 when "registration_splay" 50 @registration_splay = Util.str_to_bool(val) 51 when "collectives" 52 @collectives = val.split(",").map {|c| c.strip} 53 when "main_collective" 54 @main_collective = val 55 when "logfile" 56 @logfile = val 57 when "keeplogs" 58 @keeplogs = Integer(val) 59 when "max_log_size" 60 @max_log_size = Integer(val) 61 when "loglevel" 62 @loglevel = val 63 when "logfacility" 64 @logfacility = val 65 when "libdir" 66 paths = val.split(File::PATH_SEPARATOR) 67 paths.each do |path| 68 raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path) 69 70 libdirs << path 71 end 72 when "identity" 73 @identity = val 74 when "direct_addressing" 75 @direct_addressing = Util.str_to_bool(val) 76 when "direct_addressing_threshold" 77 @direct_addressing_threshold = Integer(val) 78 when "color" 79 @color = Util.str_to_bool(val) 80 when "daemonize" 81 @daemonize = Util.str_to_bool(val) 82 when "securityprovider" 83 @securityprovider = val.capitalize 84 when "factsource" 85 @factsource = val.capitalize 86 when "connector" 87 @connector = val.capitalize 88 when "classesfile" 89 @classesfile = val 90 when /^plugin.(.+)$/ 91 @pluginconf[$1] = val 92 when "discovery_timeout" 93 @discovery_timeout = Integer(val) 94 when "publish_timeout" 95 @publish_timeout = Integer(val) 96 when "connection_timeout" 97 @connection_timeout = Integer(val) 98 when "rpcaudit" 99 @rpcaudit = Util.str_to_bool(val) 100 when "rpcauditprovider" 101 @rpcauditprovider = val.capitalize 102 when "rpcauthorization" 103 @rpcauthorization = Util.str_to_bool(val) 104 when "rpcauthprovider" 105 @rpcauthprovider = val.capitalize 106 when "rpclimitmethod" 107 @rpclimitmethod = val.to_sym 108 when "logger_type" 109 @logger_type = val 110 when "fact_cache_time" 111 @fact_cache_time = Integer(val) 112 when "ssl_cipher" 113 @ssl_cipher = val 114 when "threaded" 115 @threaded = Util.str_to_bool(val) 116 when "ttl" 117 @ttl = Integer(val) 118 when "default_discovery_options" 119 @default_discovery_options << val 120 when "default_discovery_method" 121 @default_discovery_method = val 122 when "soft_shutdown" 123 @soft_shutdown = Util.str_to_bool(val) 124 when "soft_shutdown_timeout" 125 @soft_shutdown_timeout = Integer(val) 126 when "activate_agents" 127 @activate_agents = Util.str_to_bool(val) 128 when "default_batch_size" 129 @default_batch_size = Integer(val) 130 when "default_batch_sleep_time" 131 @default_batch_sleep_time = Float(val) 132 when "topicprefix", "topicsep", "queueprefix", "rpchelptemplate", "helptemplatedir" 133 Log.warn("Use of deprecated '#{key}' option. This option is ignored and should be removed from '#{configfile}'") 134 else 135 raise("Unknown config parameter '#{key}'") 136 end 137 rescue ArgumentError => e 138 raise "Could not parse value for configuration option '#{key}' with value '#{val}'" 139 end 140 end 141 end 142 end 143 144 read_plugin_config_dir("#{@configdir}/plugin.d") 145 146 raise 'Identities can only match /\w\.\-/' unless @identity.match(/^[\w\.\-]+$/) 147 148 @configured = true 149 150 libdirs.each do |dir| 151 unless File.directory?(dir) 152 Log.debug("Cannot find libdir: #{dir}") 153 end 154 155 # remove the old one if it exists, we're moving it to the front 156 $LOAD_PATH.reject! { |elem| elem == dir } 157 $LOAD_PATH.unshift dir 158 end 159 160 if @logger_type == "syslog" 161 raise "The sylog logger is not usable on the Windows platform" if Util.windows? 162 end 163 164 PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") 165 PluginManager.loadclass("Mcollective::Connector::#{@connector}") 166 PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") 167 PluginManager.loadclass("Mcollective::Registration::#{@registration}") 168 PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit 169 PluginManager << {:type => "global_stats", :class => RunnerStats.new} 170 171 Log.info("The Marionette Collective version #{MCollective::VERSION} started by #{$0} using config file #{configfile}") 172 else 173 raise("Cannot find config file '#{configfile}'") 174 end 175 end
read_plugin_config_dir(dir)
click to toggle source
# File lib/mcollective/config.rb 227 def read_plugin_config_dir(dir) 228 return unless File.directory?(dir) 229 230 Dir.new(dir).each do |pluginconfigfile| 231 next unless pluginconfigfile =~ /^([\w]+).cfg$/ 232 233 plugin = $1 234 File.open("#{dir}/#{pluginconfigfile}", "r").each do |line| 235 # strip blank lines 236 line.gsub!(/\s*$/, "") 237 next if line =~ /^#|^$/ 238 if (line =~ /(.+?)\s*=\s*(.+)/) 239 key = $1.strip 240 val = $2 241 @pluginconf["#{plugin}.#{key}"] = val 242 end 243 end 244 end 245 end
set_config_defaults(configfile)
click to toggle source
# File lib/mcollective/config.rb 177 def set_config_defaults(configfile) 178 @stomp = Hash.new 179 @subscribe = Array.new 180 @pluginconf = Hash.new 181 @connector = "activemq" 182 @securityprovider = "Psk" 183 @factsource = "Yaml" 184 @identity = Socket.gethostname 185 @registration = "Agentlist" 186 @registerinterval = 0 187 @registration_collective = nil 188 @registration_splay = false 189 @classesfile = "/var/lib/puppet/state/classes.txt" 190 @rpcaudit = false 191 @rpcauditprovider = "" 192 @rpcauthorization = false 193 @rpcauthprovider = "" 194 @configdir = File.dirname(configfile) 195 @color = !Util.windows? 196 @configfile = configfile 197 @logger_type = "file" 198 @keeplogs = 5 199 @max_log_size = 2097152 200 @rpclimitmethod = :first 201 @fact_cache_time = 300 202 @loglevel = "info" 203 @logfacility = "user" 204 @collectives = ["mcollective"] 205 @main_collective = @collectives.first 206 @ssl_cipher = "aes-256-cbc" 207 @direct_addressing = true 208 @direct_addressing_threshold = 10 209 @default_discovery_method = "mc" 210 @default_discovery_options = [] 211 @ttl = 60 212 @mode = :client 213 @publish_timeout = 2 214 @threaded = false 215 @soft_shutdown = false 216 @soft_shutdown_timeout = nil 217 @activate_agents = true 218 @connection_timeout = nil 219 @default_batch_size = 0 220 @default_batch_sleep_time = 1 221 end