Class MCollective::Config
In: lib/mcollective/config.rb
Parent: Object

A pretty sucky config class, ripe for refactoring/improving

Methods

Included Modules

Singleton

Attributes

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] 
ssl_cipher  [R] 
topicprefix  [R] 
topicsep  [R] 

Public Class methods

[Source]

    # File lib/mcollective/config.rb, line 13
13:         def initialize
14:             @configured = false
15:         end

Public Instance methods

[Source]

     # 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:                                 when "ssl_cipher"
 93:                                     @ssl_cipher = val
 94:                                 else
 95:                                     raise("Unknown config parameter #{key}")
 96:                             end
 97:                         end
 98:                     end
 99:                 end
100: 
101:                 read_plugin_config_dir("#{@configdir}/plugin.d")
102: 
103:                 @configured = true
104: 
105:                 @libdir.each {|dir| Log.warn("Cannot find libdir: #{dir}") unless File.directory?(dir)}
106: 
107:                 PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts")
108:                 PluginManager.loadclass("Mcollective::Connector::#{@connector}")
109:                 PluginManager.loadclass("Mcollective::Security::#{@securityprovider}")
110:                 PluginManager.loadclass("Mcollective::Registration::#{@registration}")
111:                 PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit
112:                 PluginManager << {:type => "global_stats", :class => RunnerStats.new}
113:             else
114:                 raise("Cannot find config file '#{configfile}'")
115:             end
116:         end

[Source]

     # File lib/mcollective/config.rb, line 150
150:         def read_plugin_config_dir(dir)
151:             return unless File.directory?(dir)
152: 
153:             Dir.new(dir).each do |pluginconfigfile|
154:                 next unless pluginconfigfile =~ /^([\w]+).cfg$/
155: 
156:                 plugin = $1
157:                 File.open("#{dir}/#{pluginconfigfile}", "r").each do |line|
158:                     # strip blank lines
159:                     line.gsub!(/\s*$/, "")
160:                     next if line =~ /^#|^$/
161:                     if (line =~ /(.+?)\s*=\s*(.+)/)
162:                         key = $1
163:                         val = $2
164:                         @pluginconf["#{plugin}.#{key}"] = val
165:                     end
166:                 end
167:             end
168:         end

[Source]

     # File lib/mcollective/config.rb, line 118
118:         def set_config_defaults(configfile)
119:             @stomp = Hash.new
120:             @subscribe = Array.new
121:             @pluginconf = Hash.new
122:             @connector = "Stomp"
123:             @securityprovider = "Psk"
124:             @factsource = "Yaml"
125:             @identity = Socket.gethostname
126:             @registration = "Agentlist"
127:             @registerinterval = 0
128:             @topicsep = "."
129:             @classesfile = "/var/lib/puppet/classes.txt"
130:             @rpcaudit = false
131:             @rpcauditprovider = ""
132:             @rpcauthorization = false
133:             @rpcauthprovider = ""
134:             @configdir = File.dirname(configfile)
135:             @color = true
136:             @configfile = configfile
137:             @rpchelptemplate = "/etc/mcollective/rpc-help.erb"
138:             @logger_type = "file"
139:             @keeplogs = 5
140:             @max_log_size = 2097152
141:             @rpclimitmethod = :first
142:             @libdir = Array.new
143:             @fact_cache_time = 300
144:             @loglevel = "info"
145:             @collectives = ["mcollective"]
146:             @main_collective = @collectives.first
147:             @ssl_cipher = "aes-256-cbc"
148:         end

[Validate]