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