From 16795edea8e14230b67b28e7e8503c2daffd69d2 Mon Sep 17 00:00:00 2001 From: Anton Aksola Date: Mon, 5 May 2014 09:40:11 +0300 Subject: 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 --- lib/oxidized/source/sql.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/oxidized/source') diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb index 1c4c33e..a115da8 100644 --- a/lib/oxidized/source/sql.rb +++ b/lib/oxidized/source/sql.rb @@ -35,9 +35,16 @@ class SQL < Source Sequel.sqlite @cfg.file end db[@cfg.table.to_sym].each do |node| + # map node parameters keys = {} @cfg.map.each { |key, sql_column| keys[key.to_sym] = node[sql_column.to_sym] } keys[:model] = map_model keys[:model] if keys.key? :model + + # map node specific vars + vars = {} + @cfg.vars_map.each { |key, sql_column| vars[key.to_sym] = node[sql_column.to_sym] } + keys[:vars] = vars unless vars.empty? + nodes << keys end nodes -- cgit v1.2.1