summaryrefslogtreecommitdiff
path: root/lib/oxidized/config.rb
diff options
context:
space:
mode:
authorAnton Aksola <anton.aksola@nebula.fi>2014-05-05 09:40:11 +0300
committerAnton Aksola <anton.aksola@nebula.fi>2014-05-05 09:40:11 +0300
commit16795edea8e14230b67b28e7e8503c2daffd69d2 (patch)
tree4005091b6167c400a59b309e28ee280423edce8f /lib/oxidized/config.rb
parent34af261b7928ba7d62496d2d87fbe64b1badc930 (diff)
Introduce node and group level vars
Variables can now be fed to model from multiple locations. In order of preference: 1) node (from source) 2) group 3) global In a model vars should be accessed via 'vars' helper method though it is not required. Helper method ignores nil values so care needs to taken when designing model behaviour. Support for node level vars is currently available on sql source via 'vars_map' configuration. Following example populates node vars 'enable' and 'somevariable' from sql columns 'var_enable' and 'var_somevariable' sql: adapter: sqlite file: /home/aakso/.config/oxidized/sqrouter.db table: nodes map: name: hostname model: model group: node_group username: username password: password vars_map: enable: var_enablepw somevariable: var_somevariable
Diffstat (limited to 'lib/oxidized/config.rb')
-rw-r--r--lib/oxidized/config.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb
index 9e5ec60..fd120b6 100644
--- a/lib/oxidized/config.rb
+++ b/lib/oxidized/config.rb
@@ -9,6 +9,17 @@ module Oxidized
ModelDir = File.join Directory, %w(lib oxidized model)
SourceDir = File.join Directory, %w(lib oxidized source)
Sleep = 1
+
+ module Vars
+ # convenience method for accessing node, group or global level user variables
+ # nil values will be ignored
+ def vars name
+ r = @node.vars[name]
+ r ||= CFG.groups[@node.group].vars[name.to_s] if CFG.groups.has_key?(@node.group)
+ r ||= CFG.vars[name.to_s]
+ end
+ end
+
end
class << self
attr_accessor :mgr
@@ -25,6 +36,7 @@ module Oxidized
CFGS.default.prompt = /^([\w.@-]+[#>]\s?)$/
CFGS.default.rest = '0.0.0.0:8888' # or false to disable
CFGS.default.vars = {} # could be 'enable'=>'enablePW'
+ CFGS.default.groups = {} # group level configuration
CFGS.default.remove_secret = false # runs cmd(:secret) blocks if true
CFGS.default.input.default = 'ssh, telnet'