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] 
factsource  [R] 
identity  [R] 
keeplogs  [R] 
libdir  [R] 
logfile  [R] 
loglevel  [R] 
max_log_size  [R] 
pluginconf  [R] 
registerinterval  [R] 
registration  [R] 
rpcaudit  [R] 
rpcauditprovider  [R] 
rpcauthorization  [R] 
rpcauthprovider  [R] 
rpchelptemplate  [R] 
securityprovider  [R] 
topicprefix  [R] 
topicsep  [R] 

Public Class methods

[Source]

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

Public Instance methods

[Source]

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

[Validate]