summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/config.rb11
-rw-r--r--lib/oxidized/config/vars.rb6
-rw-r--r--lib/oxidized/core.rb1
-rw-r--r--lib/oxidized/node.rb2
-rw-r--r--lib/oxidized/source/csv.rb7
5 files changed, 12 insertions, 15 deletions
diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb
index fd120b6..97bd164 100644
--- a/lib/oxidized/config.rb
+++ b/lib/oxidized/config.rb
@@ -9,17 +9,6 @@ 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
diff --git a/lib/oxidized/config/vars.rb b/lib/oxidized/config/vars.rb
index bc94049..0d6aaa7 100644
--- a/lib/oxidized/config/vars.rb
+++ b/lib/oxidized/config/vars.rb
@@ -2,9 +2,9 @@ module Oxidized::Config::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]
+ r = @node.vars[name] unless @node.vars.nil?
+ r ||= Oxidized::CFG.groups[@node.group].vars[name.to_s] if Oxidized::CFG.groups.has_key?(@node.group)
+ r ||= Oxidized::CFG.vars[name.to_s]
end
end
diff --git a/lib/oxidized/core.rb b/lib/oxidized/core.rb
index c826d1e..31e7d49 100644
--- a/lib/oxidized/core.rb
+++ b/lib/oxidized/core.rb
@@ -5,6 +5,7 @@ module Oxidized
require 'oxidized/worker'
require 'oxidized/nodes'
require 'oxidized/manager'
+ require 'oxidized/config/vars'
class << self
def new *args
Core.new args
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index 0537e45..65f0c1f 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -143,7 +143,7 @@ module Oxidized
if not Oxidized.mgr.model[model]
Oxidized.mgr.add_model model or raise ModelNotFound, "#{model} not found for node #{ip}"
end
- Oxidized.mgr.model[model].new
+ Oxidized.mgr.model[model].new
end
end
diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb
index 9d291c7..113c272 100644
--- a/lib/oxidized/source/csv.rb
+++ b/lib/oxidized/source/csv.rb
@@ -20,11 +20,18 @@ class CSV < Source
nodes = []
open(@cfg.file).each_line do |line|
data = line.chomp.split @cfg.delimiter
+ # map node parameters
keys = {}
@cfg.map.each do |key, position|
keys[key.to_sym] = data[position]
end
keys[:model] = map_model keys[:model] if keys.key? :model
+
+ # map node specific vars, empty value is considered as nil
+ vars = {}
+ @cfg.vars_map.each { |key, position| vars[key.to_sym] = data[position].to_s.empty? ? nil : data[position] }
+ keys[:vars] = vars unless vars.empty?
+
nodes << keys
end
nodes