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

A pretty sucky config class, ripe for refactoring/improving

Methods

loadconfig   new  

Included Modules

Singleton

Attributes

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] 

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

[Validate]