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