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] | |
fact_cache_time | [R] | |
factsource | [R] | |
identity | [R] | |
keeplogs | [R] | |
libdir | [R] | |
logfile | [R] | |
logger_type | [R] | |
loglevel | [R] | |
main_collective | [R] | |
max_log_size | [R] | |
pluginconf | [R] | |
registerinterval | [R] | |
registration | [R] | |
rpcaudit | [R] | |
rpcauditprovider | [R] | |
rpcauthorization | [R] | |
rpcauthprovider | [R] | |
rpchelptemplate | [R] | |
rpclimitmethod | [R] | |
securityprovider | [R] | |
topicprefix | [R] | |
topicsep | [R] |
# File lib/mcollective/config.rb, line 17 17: def loadconfig(configfile) 18: set_config_defaults(configfile) 19: 20: if File.exists?(configfile) 21: File.open(configfile, "r").each do |line| 22: 23: # strip blank spaces, tabs etc off the end of all lines 24: line.gsub!(/\s*$/, "") 25: 26: unless line =~ /^#|^$/ 27: if (line =~ /(.+?)\s*=\s*(.+)/) 28: key = $1 29: val = $2 30: 31: case key 32: when "topicsep" 33: @topicsep = val 34: when "registration" 35: @registration = val.capitalize 36: when "registerinterval" 37: @registerinterval = val.to_i 38: when "collectives" 39: @collectives = val.split(",").map {|c| c.strip} 40: when "main_collective" 41: @main_collective = val 42: when "topicprefix" 43: @topicprefix = val 44: when "logfile" 45: @logfile = val 46: when "keeplogs" 47: @keeplogs = val.to_i 48: when "max_log_size" 49: @max_log_size = val.to_i 50: when "loglevel" 51: @loglevel = val 52: when "libdir" 53: paths = val.split(/:/) 54: paths.each do |path| 55: @libdir << path 56: unless $LOAD_PATH.include?(path) 57: $LOAD_PATH << path 58: end 59: end 60: when "identity" 61: @identity = val 62: when "color" 63: val =~ /^1|y/i ? @color = true : @color = false 64: when "daemonize" 65: val =~ /^1|y/i ? @daemonize = true : @daemonize = false 66: when "securityprovider" 67: @securityprovider = val.capitalize 68: when "factsource" 69: @factsource = val.capitalize 70: when "connector" 71: @connector = val.capitalize 72: when "classesfile" 73: @classesfile = val 74: when /^plugin.(.+)$/ 75: @pluginconf[$1] = val 76: when "rpcaudit" 77: val =~ /^1|y/i ? @rpcaudit = true : @rpcaudit = false 78: when "rpcauditprovider" 79: @rpcauditprovider = val.capitalize 80: when "rpcauthorization" 81: val =~ /^1|y/i ? @rpcauthorization = true : @rpcauthorization = false 82: when "rpcauthprovider" 83: @rpcauthprovider = val.capitalize 84: when "rpchelptemplate" 85: @rpchelptemplate = val 86: when "rpclimitmethod" 87: @rpclimitmethod = val.to_sym 88: when "logger_type" 89: @logger_type = val 90: when "fact_cache_time" 91: @fact_cache_time = val.to_i 92: 93: else 94: raise("Unknown config parameter #{key}") 95: end 96: end 97: end 98: end 99: 100: read_plugin_config_dir("#{@configdir}/plugin.d") 101: 102: @configured = true 103: 104: @libdir.each {|dir| Log.warn("Cannot find libdir: #{dir}") unless File.directory?(dir)} 105: 106: PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") 107: PluginManager.loadclass("Mcollective::Connector::#{@connector}") 108: PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") 109: PluginManager.loadclass("Mcollective::Registration::#{@registration}") 110: PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit 111: PluginManager << {:type => "global_stats", :class => RunnerStats.new} 112: else 113: raise("Cannot find config file '#{configfile}'") 114: end 115: end
# File lib/mcollective/config.rb, line 148 148: def read_plugin_config_dir(dir) 149: return unless File.directory?(dir) 150: 151: Dir.new(dir).each do |pluginconfigfile| 152: next unless pluginconfigfile =~ /^([\w]+).cfg$/ 153: 154: plugin = $1 155: File.open("#{dir}/#{pluginconfigfile}", "r").each do |line| 156: # strip blank lines 157: line.gsub!(/\s*$/, "") 158: next if line =~ /^#|^$/ 159: if (line =~ /(.+?)\s*=\s*(.+)/) 160: key = $1 161: val = $2 162: @pluginconf["#{plugin}.#{key}"] = val 163: end 164: end 165: end 166: end
# File lib/mcollective/config.rb, line 117 117: def set_config_defaults(configfile) 118: @stomp = Hash.new 119: @subscribe = Array.new 120: @pluginconf = Hash.new 121: @connector = "Stomp" 122: @securityprovider = "Psk" 123: @factsource = "Yaml" 124: @identity = Socket.gethostname 125: @registration = "Agentlist" 126: @registerinterval = 0 127: @topicsep = "." 128: @classesfile = "/var/lib/puppet/classes.txt" 129: @rpcaudit = false 130: @rpcauditprovider = "" 131: @rpcauthorization = false 132: @rpcauthprovider = "" 133: @configdir = File.dirname(configfile) 134: @color = true 135: @configfile = configfile 136: @rpchelptemplate = "/etc/mcollective/rpc-help.erb" 137: @logger_type = "file" 138: @keeplogs = 5 139: @max_log_size = 2097152 140: @rpclimitmethod = :first 141: @libdir = Array.new 142: @fact_cache_time = 300 143: @loglevel = "info" 144: @collectives = ["mcollective"] 145: @main_collective = @collectives.first 146: end