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