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