Class: MCollective::Config
- Inherits:
-
Object
- Object
- MCollective::Config
- Includes:
- Singleton
- Defined in:
- lib/mcollective/config.rb
Overview
A pretty sucky config class, ripe for refactoring/improving
Instance Attribute Summary collapse
-
#classesfile ⇒ Object
readonly
Returns the value of attribute classesfile.
-
#collectives ⇒ Object
readonly
Returns the value of attribute collectives.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#configdir ⇒ Object
readonly
Returns the value of attribute configdir.
-
#configfile ⇒ Object
readonly
Returns the value of attribute configfile.
-
#configured ⇒ Object
readonly
Returns the value of attribute configured.
-
#connector ⇒ Object
readonly
Returns the value of attribute connector.
-
#daemonize ⇒ Object
readonly
Returns the value of attribute daemonize.
-
#default_discovery_method ⇒ Object
readonly
Returns the value of attribute default_discovery_method.
-
#default_discovery_options ⇒ Object
readonly
Returns the value of attribute default_discovery_options.
-
#direct_addressing ⇒ Object
readonly
Returns the value of attribute direct_addressing.
-
#direct_addressing_threshold ⇒ Object
readonly
Returns the value of attribute direct_addressing_threshold.
-
#fact_cache_time ⇒ Object
readonly
Returns the value of attribute fact_cache_time.
-
#factsource ⇒ Object
readonly
Returns the value of attribute factsource.
-
#helptemplatedir ⇒ Object
readonly
Returns the value of attribute helptemplatedir.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#keeplogs ⇒ Object
readonly
Returns the value of attribute keeplogs.
-
#libdir ⇒ Object
readonly
Returns the value of attribute libdir.
-
#logfacility ⇒ Object
readonly
Returns the value of attribute logfacility.
-
#logfile ⇒ Object
readonly
Returns the value of attribute logfile.
-
#logger_type ⇒ Object
readonly
Returns the value of attribute logger_type.
-
#loglevel ⇒ Object
readonly
Returns the value of attribute loglevel.
-
#main_collective ⇒ Object
readonly
Returns the value of attribute main_collective.
-
#max_log_size ⇒ Object
readonly
Returns the value of attribute max_log_size.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#pluginconf ⇒ Object
readonly
Returns the value of attribute pluginconf.
-
#queueprefix ⇒ Object
readonly
Returns the value of attribute queueprefix.
-
#registerinterval ⇒ Object
readonly
Returns the value of attribute registerinterval.
-
#registration ⇒ Object
readonly
Returns the value of attribute registration.
-
#registration_collective ⇒ Object
readonly
Returns the value of attribute registration_collective.
-
#rpcaudit ⇒ Object
readonly
Returns the value of attribute rpcaudit.
-
#rpcauditprovider ⇒ Object
readonly
Returns the value of attribute rpcauditprovider.
-
#rpcauthorization ⇒ Object
readonly
Returns the value of attribute rpcauthorization.
-
#rpcauthprovider ⇒ Object
readonly
Returns the value of attribute rpcauthprovider.
-
#rpchelptemplate ⇒ Object
readonly
Returns the value of attribute rpchelptemplate.
-
#rpclimitmethod ⇒ Object
readonly
Returns the value of attribute rpclimitmethod.
-
#securityprovider ⇒ Object
readonly
Returns the value of attribute securityprovider.
-
#ssl_cipher ⇒ Object
readonly
Returns the value of attribute ssl_cipher.
-
#topicprefix ⇒ Object
readonly
Returns the value of attribute topicprefix.
-
#topicsep ⇒ Object
readonly
Returns the value of attribute topicsep.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #loadconfig(configfile) ⇒ Object
- #read_plugin_config_dir(dir) ⇒ Object
- #set_config_defaults(configfile) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
19 20 21 |
# File 'lib/mcollective/config.rb', line 19 def initialize @configured = false end |
Instance Attribute Details
#classesfile ⇒ Object (readonly)
Returns the value of attribute classesfile.
11 12 13 |
# File 'lib/mcollective/config.rb', line 11 def classesfile @classesfile end |
#collectives ⇒ Object (readonly)
Returns the value of attribute collectives.
14 15 16 |
# File 'lib/mcollective/config.rb', line 14 def collectives @collectives end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
13 14 15 |
# File 'lib/mcollective/config.rb', line 13 def color @color end |
#configdir ⇒ Object (readonly)
Returns the value of attribute configdir.
12 13 14 |
# File 'lib/mcollective/config.rb', line 12 def configdir @configdir end |
#configfile ⇒ Object (readonly)
Returns the value of attribute configfile.
13 14 15 |
# File 'lib/mcollective/config.rb', line 13 def configfile @configfile end |
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def configured @configured end |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
10 11 12 |
# File 'lib/mcollective/config.rb', line 10 def connector @connector end |
#daemonize ⇒ Object (readonly)
Returns the value of attribute daemonize.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def daemonize @daemonize end |
#default_discovery_method ⇒ Object (readonly)
Returns the value of attribute default_discovery_method.
17 18 19 |
# File 'lib/mcollective/config.rb', line 17 def default_discovery_method @default_discovery_method end |
#default_discovery_options ⇒ Object (readonly)
Returns the value of attribute default_discovery_options.
17 18 19 |
# File 'lib/mcollective/config.rb', line 17 def @default_discovery_options end |
#direct_addressing ⇒ Object (readonly)
Returns the value of attribute direct_addressing.
16 17 18 |
# File 'lib/mcollective/config.rb', line 16 def direct_addressing @direct_addressing end |
#direct_addressing_threshold ⇒ Object (readonly)
Returns the value of attribute direct_addressing_threshold.
16 17 18 |
# File 'lib/mcollective/config.rb', line 16 def direct_addressing_threshold @direct_addressing_threshold end |
#fact_cache_time ⇒ Object (readonly)
Returns the value of attribute fact_cache_time.
14 15 16 |
# File 'lib/mcollective/config.rb', line 14 def fact_cache_time @fact_cache_time end |
#factsource ⇒ Object (readonly)
Returns the value of attribute factsource.
10 11 12 |
# File 'lib/mcollective/config.rb', line 10 def factsource @factsource end |
#helptemplatedir ⇒ Object (readonly)
Returns the value of attribute helptemplatedir.
16 17 18 |
# File 'lib/mcollective/config.rb', line 16 def helptemplatedir @helptemplatedir end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
10 11 12 |
# File 'lib/mcollective/config.rb', line 10 def identity @identity end |
#keeplogs ⇒ Object (readonly)
Returns the value of attribute keeplogs.
9 10 11 |
# File 'lib/mcollective/config.rb', line 9 def keeplogs @keeplogs end |
#libdir ⇒ Object (readonly)
Returns the value of attribute libdir.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def libdir @libdir end |
#logfacility ⇒ Object (readonly)
Returns the value of attribute logfacility.
9 10 11 |
# File 'lib/mcollective/config.rb', line 9 def logfacility @logfacility end |
#logfile ⇒ Object (readonly)
Returns the value of attribute logfile.
9 10 11 |
# File 'lib/mcollective/config.rb', line 9 def logfile @logfile end |
#logger_type ⇒ Object (readonly)
Returns the value of attribute logger_type.
14 15 16 |
# File 'lib/mcollective/config.rb', line 14 def logger_type @logger_type end |
#loglevel ⇒ Object (readonly)
Returns the value of attribute loglevel.
9 10 11 |
# File 'lib/mcollective/config.rb', line 9 def loglevel @loglevel end |
#main_collective ⇒ Object (readonly)
Returns the value of attribute main_collective.
15 16 17 |
# File 'lib/mcollective/config.rb', line 15 def main_collective @main_collective end |
#max_log_size ⇒ Object (readonly)
Returns the value of attribute max_log_size.
9 10 11 |
# File 'lib/mcollective/config.rb', line 9 def max_log_size @max_log_size end |
#mode ⇒ Object
Returns the value of attribute mode.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def mode @mode end |
#pluginconf ⇒ Object (readonly)
Returns the value of attribute pluginconf.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def pluginconf @pluginconf end |
#queueprefix ⇒ Object (readonly)
Returns the value of attribute queueprefix.
17 18 19 |
# File 'lib/mcollective/config.rb', line 17 def queueprefix @queueprefix end |
#registerinterval ⇒ Object (readonly)
Returns the value of attribute registerinterval.
11 12 13 |
# File 'lib/mcollective/config.rb', line 11 def registerinterval @registerinterval end |
#registration ⇒ Object (readonly)
Returns the value of attribute registration.
11 12 13 |
# File 'lib/mcollective/config.rb', line 11 def registration @registration end |
#registration_collective ⇒ Object (readonly)
Returns the value of attribute registration_collective.
15 16 17 |
# File 'lib/mcollective/config.rb', line 15 def registration_collective @registration_collective end |
#rpcaudit ⇒ Object (readonly)
Returns the value of attribute rpcaudit.
12 13 14 |
# File 'lib/mcollective/config.rb', line 12 def rpcaudit @rpcaudit end |
#rpcauditprovider ⇒ Object (readonly)
Returns the value of attribute rpcauditprovider.
12 13 14 |
# File 'lib/mcollective/config.rb', line 12 def rpcauditprovider @rpcauditprovider end |
#rpcauthorization ⇒ Object (readonly)
Returns the value of attribute rpcauthorization.
13 14 15 |
# File 'lib/mcollective/config.rb', line 13 def @rpcauthorization end |
#rpcauthprovider ⇒ Object (readonly)
Returns the value of attribute rpcauthprovider.
12 13 14 |
# File 'lib/mcollective/config.rb', line 12 def rpcauthprovider @rpcauthprovider end |
#rpchelptemplate ⇒ Object (readonly)
Returns the value of attribute rpchelptemplate.
13 14 15 |
# File 'lib/mcollective/config.rb', line 13 def rpchelptemplate @rpchelptemplate end |
#rpclimitmethod ⇒ Object (readonly)
Returns the value of attribute rpclimitmethod.
14 15 16 |
# File 'lib/mcollective/config.rb', line 14 def rpclimitmethod @rpclimitmethod end |
#securityprovider ⇒ Object (readonly)
Returns the value of attribute securityprovider.
10 11 12 |
# File 'lib/mcollective/config.rb', line 10 def securityprovider @securityprovider end |
#ssl_cipher ⇒ Object (readonly)
Returns the value of attribute ssl_cipher.
15 16 17 |
# File 'lib/mcollective/config.rb', line 15 def ssl_cipher @ssl_cipher end |
#topicprefix ⇒ Object (readonly)
Returns the value of attribute topicprefix.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def topicprefix @topicprefix end |
#topicsep ⇒ Object (readonly)
Returns the value of attribute topicsep.
11 12 13 |
# File 'lib/mcollective/config.rb', line 11 def topicsep @topicsep end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
16 17 18 |
# File 'lib/mcollective/config.rb', line 16 def ttl @ttl end |
Instance Method Details
#loadconfig(configfile) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/mcollective/config.rb', line 23 def loadconfig(configfile) set_config_defaults(configfile) if File.exists?(configfile) File.open(configfile, "r").each do |line| # strip blank spaces, tabs etc off the end of all lines line.gsub!(/\s*$/, "") unless line =~ /^#|^$/ if (line =~ /(.+?)\s*=\s*(.+)/) key = $1 val = $2 case key when "topicsep" @topicsep = val when "registration" @registration = val.capitalize when "registration_collective" @registration_collective = val when "registerinterval" @registerinterval = val.to_i when "collectives" @collectives = val.split(",").map {|c| c.strip} when "main_collective" @main_collective = val when "topicprefix" @topicprefix = val when "queueprefix" @queueprefix = val when "logfile" @logfile = val when "keeplogs" @keeplogs = val.to_i when "max_log_size" @max_log_size = val.to_i when "loglevel" @loglevel = val when "logfacility" @logfacility = val when "libdir" paths = val.split(File::PATH_SEPARATOR) paths.each do |path| @libdir << path unless $LOAD_PATH.include?(path) $LOAD_PATH << path end end when "identity" @identity = val when "direct_addressing" val =~ /^1|y/i ? @direct_addressing = true : @direct_addressing = false when "direct_addressing_threshold" @direct_addressing_threshold = val.to_i when "color" val =~ /^1|y/i ? @color = true : @color = false when "daemonize" val =~ /^1|y/i ? @daemonize = true : @daemonize = false when "securityprovider" @securityprovider = val.capitalize when "factsource" @factsource = val.capitalize when "connector" @connector = val.capitalize when "classesfile" @classesfile = val when /^plugin.(.+)$/ @pluginconf[$1] = val when "rpcaudit" val =~ /^1|y/i ? @rpcaudit = true : @rpcaudit = false when "rpcauditprovider" @rpcauditprovider = val.capitalize when "rpcauthorization" val =~ /^1|y/i ? @rpcauthorization = true : @rpcauthorization = false when "rpcauthprovider" @rpcauthprovider = val.capitalize when "rpchelptemplate" @rpchelptemplate = val when "rpclimitmethod" @rpclimitmethod = val.to_sym when "logger_type" @logger_type = val when "fact_cache_time" @fact_cache_time = val.to_i when "ssl_cipher" @ssl_cipher = val when "ttl" @ttl = val.to_i when "helptemplatedir" @helptemplatedir = val when "default_discovery_options" @default_discovery_options << val when "default_discovery_method" @default_discovery_method = val else raise("Unknown config parameter #{key}") end end end end read_plugin_config_dir("#{@configdir}/plugin.d") raise 'Identities can only match /\w\.\-/' unless @identity.match(/^[\w\.\-]+$/) @configured = true @libdir.each {|dir| Log.warn("Cannot find libdir: #{dir}") unless File.directory?(dir)} if @logger_type == "syslog" raise "The sylog logger is not usable on the Windows platform" if Util.windows? end PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") PluginManager.loadclass("Mcollective::Connector::#{@connector}") PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") PluginManager.loadclass("Mcollective::Registration::#{@registration}") PluginManager.loadclass("Mcollective::Audit::#{@rpcauditprovider}") if @rpcaudit PluginManager << {:type => "global_stats", :class => RunnerStats.new} else raise("Cannot find config file '#{configfile}'") end end |
#read_plugin_config_dir(dir) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/mcollective/config.rb', line 196 def read_plugin_config_dir(dir) return unless File.directory?(dir) Dir.new(dir).each do |pluginconfigfile| next unless pluginconfigfile =~ /^([\w]+).cfg$/ plugin = $1 File.open("#{dir}/#{pluginconfigfile}", "r").each do |line| # strip blank lines line.gsub!(/\s*$/, "") next if line =~ /^#|^$/ if (line =~ /(.+?)\s*=\s*(.+)/) key = $1 val = $2 @pluginconf["#{plugin}.#{key}"] = val end end end end |
#set_config_defaults(configfile) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mcollective/config.rb', line 148 def set_config_defaults(configfile) @stomp = Hash.new @subscribe = Array.new @pluginconf = Hash.new @connector = "Stomp" @securityprovider = "Psk" @factsource = "Yaml" @identity = Socket.gethostname @registration = "Agentlist" @registerinterval = 0 @registration_collective = nil @topicsep = "." @topicprefix = "/topic/" @queueprefix = "/queue/" @classesfile = "/var/lib/puppet/state/classes.txt" @rpcaudit = false @rpcauditprovider = "" @rpcauthorization = false @rpcauthprovider = "" @configdir = File.dirname(configfile) @color = !Util.windows? @configfile = configfile @logger_type = "file" @keeplogs = 5 @max_log_size = 2097152 @rpclimitmethod = :first @libdir = Array.new @fact_cache_time = 300 @loglevel = "info" @logfacility = "user" @collectives = ["mcollective"] @main_collective = @collectives.first @ssl_cipher = "aes-256-cbc" @direct_addressing = false @direct_addressing_threshold = 10 @default_discovery_method = "mc" @default_discovery_options = [] @ttl = 60 @mode = :client # look in the config dir for the template so users can provide their own and windows # with odd paths will just work more often, but fall back to old behavior if it does # not exist @rpchelptemplate = File.join(File.dirname(configfile), "rpc-help.erb") @rpchelptemplate = "/etc/mcollective/rpc-help.erb" unless File.exists?(@rpchelptemplate) @helptemplatedir = File.dirname(@rpchelptemplate) end |