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
-
#activate_agents ⇒ Object
readonly
Returns the value of attribute activate_agents.
-
#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.
-
#connection_timeout ⇒ Object
readonly
Returns the value of attribute connection_timeout.
-
#connector ⇒ Object
readonly
Returns the value of attribute connector.
-
#daemonize ⇒ Object
readonly
Returns the value of attribute daemonize.
-
#default_batch_size ⇒ Object
readonly
Returns the value of attribute default_batch_size.
-
#default_batch_sleep_time ⇒ Object
readonly
Returns the value of attribute default_batch_sleep_time.
-
#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.
-
#discovery_timeout ⇒ Object
readonly
Returns the value of attribute discovery_timeout.
-
#fact_cache_time ⇒ Object
readonly
Returns the value of attribute fact_cache_time.
-
#factsource ⇒ Object
readonly
Returns the value of attribute factsource.
-
#federations ⇒ Object
Returns the value of attribute federations.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#keeplogs ⇒ Object
readonly
Returns the value of attribute keeplogs.
-
#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.
-
#publish_timeout ⇒ Object
readonly
Returns the value of attribute publish_timeout.
-
#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.
-
#registration_splay ⇒ Object
readonly
Returns the value of attribute registration_splay.
-
#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.
-
#rpclimitmethod ⇒ Object
readonly
Returns the value of attribute rpclimitmethod.
-
#securityprovider ⇒ Object
readonly
Returns the value of attribute securityprovider.
-
#soft_shutdown ⇒ Object
readonly
Returns the value of attribute soft_shutdown.
-
#soft_shutdown_timeout ⇒ Object
readonly
Returns the value of attribute soft_shutdown_timeout.
-
#ssl_cipher ⇒ Object
readonly
Returns the value of attribute ssl_cipher.
-
#threaded ⇒ Object
readonly
Returns the value of attribute threaded.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #check_deprecations ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #libdir ⇒ Object
- #loadconfig(configfile) ⇒ Object
-
#parse_config_file(configfile, libdirs) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #parse_project_config(libdirs) ⇒ Object
- #project_config_files(path) ⇒ Object
- #project_root ⇒ Object
- #read_plugin_config_dir(dir) ⇒ Object
-
#set_config_defaults(configfile) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 |
# File 'lib/mcollective/config.rb', line 16 def initialize @configured = false end |
Instance Attribute Details
#activate_agents ⇒ Object (readonly)
Returns the value of attribute activate_agents.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def activate_agents @activate_agents end |
#classesfile ⇒ Object (readonly)
Returns the value of attribute classesfile.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def classesfile @classesfile end |
#collectives ⇒ Object (readonly)
Returns the value of attribute collectives.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def collectives @collectives end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def color @color end |
#configdir ⇒ Object (readonly)
Returns the value of attribute configdir.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def configdir @configdir end |
#configfile ⇒ Object (readonly)
Returns the value of attribute configfile.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 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 |
#connection_timeout ⇒ Object (readonly)
Returns the value of attribute connection_timeout.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def connection_timeout @connection_timeout end |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 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_batch_size ⇒ Object (readonly)
Returns the value of attribute default_batch_size.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def default_batch_size @default_batch_size end |
#default_batch_sleep_time ⇒ Object (readonly)
Returns the value of attribute default_batch_sleep_time.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def default_batch_sleep_time @default_batch_sleep_time end |
#default_discovery_method ⇒ Object (readonly)
Returns the value of attribute default_discovery_method.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def default_discovery_method @default_discovery_method end |
#default_discovery_options ⇒ Object (readonly)
Returns the value of attribute default_discovery_options.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def @default_discovery_options end |
#direct_addressing ⇒ Object (readonly)
Returns the value of attribute direct_addressing.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def direct_addressing @direct_addressing end |
#direct_addressing_threshold ⇒ Object (readonly)
Returns the value of attribute direct_addressing_threshold.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def direct_addressing_threshold @direct_addressing_threshold end |
#discovery_timeout ⇒ Object (readonly)
Returns the value of attribute discovery_timeout.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def discovery_timeout @discovery_timeout end |
#fact_cache_time ⇒ Object (readonly)
Returns the value of attribute fact_cache_time.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def fact_cache_time @fact_cache_time end |
#factsource ⇒ Object (readonly)
Returns the value of attribute factsource.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def factsource @factsource end |
#federations ⇒ Object
Returns the value of attribute federations.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def federations @federations end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def identity @identity end |
#keeplogs ⇒ Object (readonly)
Returns the value of attribute keeplogs.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def keeplogs @keeplogs end |
#logfacility ⇒ Object (readonly)
Returns the value of attribute logfacility.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def logfacility @logfacility end |
#logfile ⇒ Object (readonly)
Returns the value of attribute logfile.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def logfile @logfile end |
#logger_type ⇒ Object (readonly)
Returns the value of attribute logger_type.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def logger_type @logger_type end |
#loglevel ⇒ Object (readonly)
Returns the value of attribute loglevel.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def loglevel @loglevel end |
#main_collective ⇒ Object (readonly)
Returns the value of attribute main_collective.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def main_collective @main_collective end |
#max_log_size ⇒ Object (readonly)
Returns the value of attribute max_log_size.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 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 |
#publish_timeout ⇒ Object (readonly)
Returns the value of attribute publish_timeout.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def publish_timeout @publish_timeout end |
#registerinterval ⇒ Object (readonly)
Returns the value of attribute registerinterval.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def registerinterval @registerinterval end |
#registration ⇒ Object (readonly)
Returns the value of attribute registration.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def registration @registration end |
#registration_collective ⇒ Object (readonly)
Returns the value of attribute registration_collective.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def registration_collective @registration_collective end |
#registration_splay ⇒ Object (readonly)
Returns the value of attribute registration_splay.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def registration_splay @registration_splay end |
#rpcaudit ⇒ Object (readonly)
Returns the value of attribute rpcaudit.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def rpcaudit @rpcaudit end |
#rpcauditprovider ⇒ Object (readonly)
Returns the value of attribute rpcauditprovider.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def rpcauditprovider @rpcauditprovider end |
#rpcauthorization ⇒ Object (readonly)
Returns the value of attribute rpcauthorization.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def @rpcauthorization end |
#rpcauthprovider ⇒ Object (readonly)
Returns the value of attribute rpcauthprovider.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def rpcauthprovider @rpcauthprovider end |
#rpclimitmethod ⇒ Object (readonly)
Returns the value of attribute rpclimitmethod.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def rpclimitmethod @rpclimitmethod end |
#securityprovider ⇒ Object (readonly)
Returns the value of attribute securityprovider.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def securityprovider @securityprovider end |
#soft_shutdown ⇒ Object (readonly)
Returns the value of attribute soft_shutdown.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def soft_shutdown @soft_shutdown end |
#soft_shutdown_timeout ⇒ Object (readonly)
Returns the value of attribute soft_shutdown_timeout.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def soft_shutdown_timeout @soft_shutdown_timeout end |
#ssl_cipher ⇒ Object (readonly)
Returns the value of attribute ssl_cipher.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def ssl_cipher @ssl_cipher end |
#threaded ⇒ Object (readonly)
Returns the value of attribute threaded.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def threaded @threaded end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
8 9 10 |
# File 'lib/mcollective/config.rb', line 8 def ttl @ttl end |
Instance Method Details
#check_deprecations ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/mcollective/config.rb', line 261 def check_deprecations if @pluginconf["choria.use_srv_records"] Log.warn("Configuration set 'choria.use_srv_records' which is deprecated in favor of 'choria.use_srv'.") @pluginconf["choria.use_srv"] = @pluginconf["choria.use_srv_records"] @pluginconf.delete("choria.use_srv_records") end end |
#libdir ⇒ Object
237 238 239 |
# File 'lib/mcollective/config.rb', line 237 def libdir $LOAD_PATH end |
#loadconfig(configfile) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/mcollective/config.rb', line 126 def loadconfig(configfile) set_config_defaults(configfile) if File.exist?(configfile) libdirs = [] parse_config_file(configfile, libdirs) read_plugin_config_dir("#{@configdir}/plugin.d") parse_project_config(libdirs) raise('Identities can only match /\w\.\-/') unless @identity =~ /^[\w.\-]+$/ check_deprecations @configured = true libdirs.each do |dir| Log.debug("Cannot find libdir: %s" % dir) unless File.directory?(dir) # remove the old one if it exists, we're moving it to the front $LOAD_PATH.reject! { |elem| elem == dir } $LOAD_PATH.unshift dir end raise "The sylog logger is not usable on the Windows platform" if @logger_type == "syslog" && Util.windows? unless configfile =~ /server/ PluginManager.loadclass("Mcollective::Facts::#{@factsource}_facts") PluginManager.loadclass("Mcollective::Connector::#{@connector}") PluginManager.loadclass("Mcollective::Security::#{@securityprovider}") end Log.info("The Marionette Collective version #{MCollective::VERSION} started by #{$0} using config file #{configfile}") else raise("Cannot find config file '#{configfile}'") end end |
#parse_config_file(configfile, libdirs) ⇒ Object
rubocop:disable Metrics/MethodLength
20 21 22 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 |
# File 'lib/mcollective/config.rb', line 20 def parse_config_file(configfile, libdirs) # rubocop:disable Metrics/MethodLength File.readlines(configfile).each do |line| # strip blank spaces, tabs etc off the end of all lines line.gsub!(/\s*$/, "") next if line =~ /^#|^$/ next unless line =~ /(.+?)\s*=\s*(.+)/ key = $1.strip val = $2 begin case key when "collectives" @collectives = val.split(",").map(&:strip) when "main_collective" @main_collective = val when "logfile" @logfile = val when "keeplogs" @keeplogs = Integer(val) when "max_log_size" @max_log_size = Integer(val) when "loglevel" @loglevel = val when "logfacility" @logfacility = val when "libdir" paths = val.split(File::PATH_SEPARATOR) paths.each do |path| raise("libdir paths should be absolute paths but '%s' is relative" % path) unless Util.absolute_path?(path) libdirs << path end when "identity" @identity = val when "direct_addressing" @direct_addressing = Util.str_to_bool(val) when "direct_addressing_threshold" @direct_addressing_threshold = Integer(val) when "color" @color = Util.str_to_bool(val) when "daemonize" @daemonize = Util.str_to_bool(val) 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 "discovery_timeout" @discovery_timeout = Integer(val) when "publish_timeout" @publish_timeout = Integer(val) when "connection_timeout" @connection_timeout = Integer(val) when "rpcaudit" @rpcaudit = Util.str_to_bool(val) when "rpcauditprovider" @rpcauditprovider = val.capitalize when "rpcauthorization" @rpcauthorization = Util.str_to_bool(val) when "rpcauthprovider" @rpcauthprovider = val.capitalize when "rpclimitmethod" @rpclimitmethod = val.to_sym when "logger_type" @logger_type = val when "fact_cache_time" @fact_cache_time = Integer(val) when "ssl_cipher" @ssl_cipher = val when "threaded" @threaded = Util.str_to_bool(val) when "ttl" @ttl = Integer(val) when "default_discovery_options" @default_discovery_options << val when "default_discovery_method" @default_discovery_method = val when "soft_shutdown" @soft_shutdown = Util.str_to_bool(val) when "soft_shutdown_timeout" @soft_shutdown_timeout = Integer(val) when "activate_agents" @activate_agents = Util.str_to_bool(val) when "default_batch_size" @default_batch_size = Integer(val) when "default_batch_sleep_time" @default_batch_sleep_time = Float(val) else # server config might now be choria config which will diverge from mcollective # in time, so we only raise this error when it looks like we aren't loading # a server config else we try our best to load as much as we can raise("Unknown config parameter '#{key}'") unless configfile =~ /server/ end rescue ArgumentError raise("Could not parse value for configuration option '%s' with value '%s'" % [key, val]) end end end |
#parse_project_config(libdirs) ⇒ Object
170 171 172 173 174 |
# File 'lib/mcollective/config.rb', line 170 def parse_project_config(libdirs) project_config_files(project_root).each do |pfile| parse_config_file(pfile, libdirs) end end |
#project_config_files(path) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/mcollective/config.rb', line 176 def project_config_files(path) paths = [] path = File.(path) parent = File.("..", path) paths << project_config_files(parent) if parent != path config = File.join(path, "choria.conf") paths << config if File.exist?(config) paths.flatten end |
#project_root ⇒ Object
166 167 168 |
# File 'lib/mcollective/config.rb', line 166 def project_root Dir.pwd end |
#read_plugin_config_dir(dir) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/mcollective/config.rb', line 241 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 =~ /^#|^$/ next unless line =~ /(.+?)\s*=\s*(.+)/ key = $1.strip val = $2 @pluginconf["#{plugin}.#{key}"] = val end end end |
#set_config_defaults(configfile) ⇒ Object
rubocop:disable Naming/AccessorMethodName
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/mcollective/config.rb', line 191 def set_config_defaults(configfile) # rubocop:disable Naming/AccessorMethodName @subscribe = [] @pluginconf = {} @connector = "base" @securityprovider = "Base" @factsource = "Yaml" @identity = Socket.gethostname @registration = "Base" @registerinterval = 0 @registration_collective = nil @registration_splay = false @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 @fact_cache_time = 300 @loglevel = "info" @logfacility = "user" @collectives = ["mcollective"] @main_collective = @collectives.first @ssl_cipher = "aes-256-cbc" @direct_addressing = true @direct_addressing_threshold = 10 @default_discovery_method = "mc" @default_discovery_options = [] @ttl = 60 @mode = :client @publish_timeout = 2 @threaded = false @soft_shutdown = false @soft_shutdown_timeout = nil @activate_agents = true @connection_timeout = nil @default_batch_size = 0 @default_batch_sleep_time = 1 @federations = [] end |