Class | MCollective::Config |
In: |
lib/mcollective/config.rb
|
Parent: | Object |
A pretty sucky config class, ripe for refactoring/improving
classesfile | [R] | |
collectives | [R] | |
color | [R] | |
configdir | [R] | |
configfile | [R] | |
configured | [R] | |
connector | [R] | |
daemonize | [R] | |
daemonize | [R] | |
default_discovery_method | [R] | |
default_discovery_options | [R] | |
direct_addressing | [R] | |
direct_addressing_threshold | [R] | |
fact_cache_time | [R] | |
factsource | [R] | |
helptemplatedir | [R] | |
identity | [R] | |
keeplogs | [R] | |
libdir | [R] | |
logfacility | [R] | |
logfile | [R] | |
logger_type | [R] | |
loglevel | [R] | |
main_collective | [R] | |
max_log_size | [R] | |
pluginconf | [R] | |
queueprefix | [R] | |
registerinterval | [R] | |
registration | [R] | |
registration_collective | [R] | |
rpcaudit | [R] | |
rpcauditprovider | [R] | |
rpcauthorization | [R] | |
rpcauthprovider | [R] | |
rpchelptemplate | [R] | |
rpclimitmethod | [R] | |
securityprovider | [R] | |
ssl_cipher | [R] | |
topicprefix | [R] | |
topicsep | [R] | |
ttl | [R] |
# File lib/mcollective/config.rb, line 21 21: def loadconfig(configfile) 22: set_config_defaults(configfile) 23: 24: if File.exists?(configfile) 25: File.open(configfile, "r").each do |line| 26: 27: # strip blank spaces, tabs etc off the end of all lines 28: line.gsub!(/\s*$/, "") 29: 30: unless line =~ /^#|^$/ 31: if (line =~ /(.+?)\s*=\s*(.+)/) 32: key = $1 33: val = $2 34: 35: case key 36: when "topicsep" 37: @topicsep = val 38: when "registration" 39: @registration = val.capitalize 40: when "registration_collective" 41: @registration_collective = val 42: when "registerinterval" 43: @registerinterval = val.to_i 44: when "collectives" 45: @collectives = val.split(",").map {|c| c.strip} 46: when "main_collective" 47: @main_collective = val 48: when "topicprefix" 49: @topicprefix = val 50: when "queueprefix" 51: @queueprefix = val 52: when "logfile" 53: @logfile = val 54: when "keeplogs" 55: @keeplogs = val.to_i 56: when "max_log_size" 57: @max_log_size = val.to_i 58: when "loglevel" 59: @loglevel = val 60: when "logfacility" 61: @logfacility = val 62: when "libdir" 63: paths = val.split(File::PATH_SEPARATOR) 64: paths.each do |path| 65: @libdir << path 66: unless $LOAD_PATH.include?(path) 67: $LOAD_PATH << path 68: end 69: end 70: when "identity" 71: @identity = val 72: when "direct_addressing" 73: val =~ /^1|y/i ? @direct_addressing = true : @direct_addressing = false 74: when "direct_addressing_threshold" 75: @direct_addressing_threshold = val.to_i 76: when "color" 77: val =~ /^1|y/i ? @color = true : @color = false 78: when "daemonize" 79: val =~ /^1|y/i ? @daemonize = true : @daemonize = false 80: when "securityprovider" 81: @securityprovider = val.capitalize 82: when "factsource" 83: @factsource = val.capitalize 84: when "connector" 85: @connector = val.capitalize 86: when "classesfile" 87: @classesfile = val 88: when /^plugin.(.+)$/ 89: @pluginconf[$1] = val 90: when "rpcaudit" 91: val =~ /^1|y/i ? @rpcaudit = true : @rpcaudit = false 92: when "rpcauditprovider" 93: @rpcauditprovider = val.capitalize 94: when "rpcauthorization" 95: val =~ /^1|y/i ? @rpcauthorization = true : @rpcauthorization = false 96: when "rpcauthprovider" 97: @rpcauthprovider = val.capitalize 98: when "rpchelptemplate" 99: @rpchelptemplate = val 100: when "rpclimitmethod" 101: @rpclimitmethod = val.to_sym 102: when "logger_type" 103: @logger_type = val 104: when "fact_cache_time" 105: @fact_cache_time = val.to_i 106: when "ssl_cipher" 107: @ssl_cipher = val 108: when "ttl" 109: @ttl = val.to_i 110: when "helptemplatedir" 111: @helptemplatedir = val 112: when "default_discovery_options" 113: @default_discovery_options << val 114: when "default_discovery_method" 115: @default_discovery_method = val 116: else 117: raise("Unknown config parameter #{key}") 118: end 119: end 120: end 121: end 122: 123: read_plugin_config_dir("#{@configdir}/plugin.d") 124: 125: raise 'Identities can only match /\w\.\-/' unless @identity.match(/^[\w\.\-]+$/) 126: 127: @configured = true 128: 129: @libdir.each {|dir| Log.warn("Cannot find libdir: #{dir}") unless File.directory?(dir)} 130: 131: if @logger_type == "syslog" 132: raise "The sylog logger is not usable on the Windows platform" if Util.windows? 133: end 134: 135: PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") 136: PluginManager.loadclass("Mcollective::Connector::#{@connector}") 137: PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") 138: PluginManager.loadclass("Mcollective::Registration::#{@registration}") 139: PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit 140: PluginManager << {:type => "global_stats", :class => RunnerStats.new} 141: else 142: raise("Cannot find config file '#{configfile}'") 143: end 144: end
# File lib/mcollective/config.rb, line 193 193: def read_plugin_config_dir(dir) 194: return unless File.directory?(dir) 195: 196: Dir.new(dir).each do |pluginconfigfile| 197: next unless pluginconfigfile =~ /^([\w]+).cfg$/ 198: 199: plugin = $1 200: File.open("#{dir}/#{pluginconfigfile}", "r").each do |line| 201: # strip blank lines 202: line.gsub!(/\s*$/, "") 203: next if line =~ /^#|^$/ 204: if (line =~ /(.+?)\s*=\s*(.+)/) 205: key = $1 206: val = $2 207: @pluginconf["#{plugin}.#{key}"] = val 208: end 209: end 210: end 211: end
# File lib/mcollective/config.rb, line 146 146: def set_config_defaults(configfile) 147: @stomp = Hash.new 148: @subscribe = Array.new 149: @pluginconf = Hash.new 150: @connector = "Stomp" 151: @securityprovider = "Psk" 152: @factsource = "Yaml" 153: @identity = Socket.gethostname 154: @registration = "Agentlist" 155: @registerinterval = 0 156: @registration_collective = nil 157: @topicsep = "." 158: @topicprefix = "/topic/" 159: @queueprefix = "/queue/" 160: @classesfile = "/var/lib/puppet/state/classes.txt" 161: @rpcaudit = false 162: @rpcauditprovider = "" 163: @rpcauthorization = false 164: @rpcauthprovider = "" 165: @configdir = File.dirname(configfile) 166: @color = !Util.windows? 167: @configfile = configfile 168: @logger_type = "file" 169: @keeplogs = 5 170: @max_log_size = 2097152 171: @rpclimitmethod = :first 172: @libdir = Array.new 173: @fact_cache_time = 300 174: @loglevel = "info" 175: @logfacility = "user" 176: @collectives = ["mcollective"] 177: @main_collective = @collectives.first 178: @ssl_cipher = "aes-256-cbc" 179: @direct_addressing = false 180: @direct_addressing_threshold = 10 181: @default_discovery_method = "mc" 182: @default_discovery_options = [] 183: @ttl = 60 184: 185: # look in the config dir for the template so users can provide their own and windows 186: # with odd paths will just work more often, but fall back to old behavior if it does 187: # not exist 188: @rpchelptemplate = File.join(File.dirname(configfile), "rpc-help.erb") 189: @rpchelptemplate = "/etc/mcollective/rpc-help.erb" unless File.exists?(@rpchelptemplate) 190: @helptemplatedir = File.dirname(@rpchelptemplate) 191: end