Class | MCollective::Config |
In: |
lib/mcollective/config.rb
|
Parent: | Object |
A pretty sucky config class, ripe for refactoring/improving
classesfile | [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] | |
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: 45: if File.exists?(configfile) 46: File.open(configfile, "r").each do |line| 47: 48: # strip blank spaces, tabs etc off the end of all lines 49: line.gsub!(/\s*$/, "") 50: 51: unless line =~ /^#|^$/ 52: if (line =~ /(.+?)\s*=\s*(.+)/) 53: key = $1 54: val = $2 55: 56: case key 57: when "topicsep" 58: @topicsep = val 59: when "registration" 60: @registration = val.capitalize 61: when "registerinterval" 62: @registerinterval = val.to_i 63: when "topicprefix" 64: @topicprefix = val 65: when "logfile" 66: @logfile = val 67: when "keeplogs" 68: @keeplogs = val.to_i 69: when "max_log_size" 70: @max_log_size = val.to_i 71: when "loglevel" 72: @loglevel = val 73: when "libdir" 74: paths = val.split(/:/) 75: paths.each do |path| 76: @libdir << path 77: unless $LOAD_PATH.include?(path) 78: $LOAD_PATH << path 79: end 80: end 81: when "identity" 82: @identity = val 83: when "color" 84: val =~ /^1|y/i ? @color = true : @color = false 85: when "daemonize" 86: val =~ /^1|y/i ? @daemonize = true : @daemonize = false 87: when "securityprovider" 88: @securityprovider = val.capitalize 89: when "factsource" 90: @factsource = val.capitalize 91: when "connector" 92: @connector = val.capitalize 93: when "classesfile" 94: @classesfile = val 95: when /^plugin.(.+)$/ 96: @pluginconf[$1] = val 97: when "rpcaudit" 98: val =~ /^1|y/i ? @rpcaudit = true : @rpcaudit = false 99: when "rpcauditprovider" 100: @rpcauditprovider = val.capitalize 101: when "rpcauthorization" 102: val =~ /^1|y/i ? @rpcauthorization = true : @rpcauthorization = false 103: when "rpcauthprovider" 104: @rpcauthprovider = val.capitalize 105: when "rpchelptemplate" 106: @rpchelptemplate = val 107: when "rpclimitmethod" 108: @rpclimitmethod = val.to_sym 109: when "logger_type" 110: @logger_type = val 111: when "fact_cache_time" 112: @fact_cache_time = val.to_i 113: 114: else 115: raise("Unknown config parameter #{key}") 116: end 117: end 118: end 119: end 120: 121: @configured = true 122: 123: PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") 124: PluginManager.loadclass("Mcollective::Connector::#{@connector}") 125: PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") 126: PluginManager.loadclass("Mcollective::Registration::#{@registration}") 127: PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit 128: PluginManager << {:type => "global_stats", :class => RunnerStats.new} 129: else 130: raise("Cannot find config file '#{configfile}'") 131: end 132: end