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.
-
#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.
-
#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.
-
#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.
15 16 17 |
# File 'lib/mcollective/config.rb', line 15 def initialize @configured = false end |
Instance Attribute Details
#classesfile ⇒ Object (readonly)
Returns the value of attribute classesfile.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def classesfile @classesfile end |
#collectives ⇒ Object (readonly)
Returns the value of attribute collectives.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def collectives @collectives end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def color @color end |
#configdir ⇒ Object (readonly)
Returns the value of attribute configdir.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def configdir @configdir end |
#configfile ⇒ Object (readonly)
Returns the value of attribute configfile.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def configfile @configfile end |
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def configured @configured end |
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def connector @connector end |
#daemonize ⇒ Object (readonly)
Returns the value of attribute daemonize.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def daemonize @daemonize end |
#direct_addressing ⇒ Object (readonly)
Returns the value of attribute direct_addressing.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def direct_addressing @direct_addressing end |
#direct_addressing_threshold ⇒ Object (readonly)
Returns the value of attribute direct_addressing_threshold.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def direct_addressing_threshold @direct_addressing_threshold end |
#fact_cache_time ⇒ Object (readonly)
Returns the value of attribute fact_cache_time.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def fact_cache_time @fact_cache_time end |
#factsource ⇒ Object (readonly)
Returns the value of attribute factsource.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def factsource @factsource end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def identity @identity end |
#keeplogs ⇒ Object (readonly)
Returns the value of attribute keeplogs.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def keeplogs @keeplogs end |
#libdir ⇒ Object (readonly)
Returns the value of attribute libdir.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def libdir @libdir end |
#logfacility ⇒ Object (readonly)
Returns the value of attribute logfacility.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def logfacility @logfacility end |
#logfile ⇒ Object (readonly)
Returns the value of attribute logfile.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def logfile @logfile end |
#logger_type ⇒ Object (readonly)
Returns the value of attribute logger_type.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def logger_type @logger_type end |
#loglevel ⇒ Object (readonly)
Returns the value of attribute loglevel.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def loglevel @loglevel end |
#main_collective ⇒ Object (readonly)
Returns the value of attribute main_collective.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def main_collective @main_collective end |
#max_log_size ⇒ Object (readonly)
Returns the value of attribute max_log_size.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def max_log_size @max_log_size end |
#pluginconf ⇒ Object (readonly)
Returns the value of attribute pluginconf.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def pluginconf @pluginconf end |
#queueprefix ⇒ Object (readonly)
Returns the value of attribute queueprefix.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def queueprefix @queueprefix end |
#registerinterval ⇒ Object (readonly)
Returns the value of attribute registerinterval.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def registerinterval @registerinterval end |
#registration ⇒ Object (readonly)
Returns the value of attribute registration.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def registration @registration end |
#registration_collective ⇒ Object (readonly)
Returns the value of attribute registration_collective.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def registration_collective @registration_collective end |
#rpcaudit ⇒ Object (readonly)
Returns the value of attribute rpcaudit.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def rpcaudit @rpcaudit end |
#rpcauditprovider ⇒ Object (readonly)
Returns the value of attribute rpcauditprovider.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def rpcauditprovider @rpcauditprovider end |
#rpcauthorization ⇒ Object (readonly)
Returns the value of attribute rpcauthorization.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def @rpcauthorization end |
#rpcauthprovider ⇒ Object (readonly)
Returns the value of attribute rpcauthprovider.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def rpcauthprovider @rpcauthprovider end |
#rpchelptemplate ⇒ Object (readonly)
Returns the value of attribute rpchelptemplate.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def rpchelptemplate @rpchelptemplate end |
#rpclimitmethod ⇒ Object (readonly)
Returns the value of attribute rpclimitmethod.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def rpclimitmethod @rpclimitmethod end |
#securityprovider ⇒ Object (readonly)
Returns the value of attribute securityprovider.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def securityprovider @securityprovider end |
#ssl_cipher ⇒ Object (readonly)
Returns the value of attribute ssl_cipher.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def ssl_cipher @ssl_cipher end |
#topicprefix ⇒ Object (readonly)
Returns the value of attribute topicprefix.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def topicprefix @topicprefix end |
#topicsep ⇒ Object (readonly)
Returns the value of attribute topicsep.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def topicsep @topicsep end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
6 7 8 |
# File 'lib/mcollective/config.rb', line 6 def ttl @ttl end |
Instance Method Details
#loadconfig(configfile) ⇒ Object
19 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 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mcollective/config.rb', line 19 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 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
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/mcollective/config.rb', line 182 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
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/mcollective/config.rb', line 138 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 @ttl = 60 # 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) end |