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