summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-02-25 12:59:24 +0200
committerSaku Ytti <saku@ytti.fi>2014-02-25 12:59:24 +0200
commit54275a0576b05813e78aa7707111db3411602048 (patch)
tree5cb0c8c3b00839310e40de08de8502771ebd8eff
parent596607c8bad948f605fdece2829e24eac3411279 (diff)
Fix crashes on missing config
We now merge user config with bootstrap config ensuring all configuratio options are set even if not in configuratatin. Allowing us to add new configuration options, without needing for users to touch their existing configuration. All default values are still written to user config when ever CFG.save is called, which means when you change your output/input/source models and configuration is missing, instead of just adding the configuration needed for that particular module, it'll save full config to file. Don't really think that is a bug, but might be something to fix later on with maybe parameter to 'save'. Which would load user config, merge it with 'save' argument level and save user config. But unless someone is bothered by it, I won't do it. This commit fixes #1
-rw-r--r--lib/oxidized/config/bootstrap.rb3
-rw-r--r--lib/oxidized/config/core.rb9
-rw-r--r--lib/oxidized/source/csv.rb2
-rw-r--r--lib/oxidized/source/sql.rb2
-rw-r--r--oxidized.gemspec2
5 files changed, 11 insertions, 7 deletions
diff --git a/lib/oxidized/config/bootstrap.rb b/lib/oxidized/config/bootstrap.rb
index 73750de..4f9e2ab 100644
--- a/lib/oxidized/config/bootstrap.rb
+++ b/lib/oxidized/config/bootstrap.rb
@@ -10,7 +10,7 @@ module Oxidized
CFG.threads = 30
CFG.timeout = 5
CFG.prompt = /^([\w.@-]+[#>]\s?)$/
- CFG.rest = 8888
+ CFG.rest = '0.0.0.0:8888'
CFG.vars = {
:enable => 'enablePW',
}
@@ -30,5 +30,4 @@ module Oxidized
'cisco' => 'ios',
'juniper' => 'junos',
}
- CFG.save
end
diff --git a/lib/oxidized/config/core.rb b/lib/oxidized/config/core.rb
index c2cde58..9b93d91 100644
--- a/lib/oxidized/config/core.rb
+++ b/lib/oxidized/config/core.rb
@@ -11,17 +11,22 @@ module Oxidized
# load config from file or bootstrap with built-ins
def load
if File.exists? @file
- marshal_load YAML.load_file @file
+ cfg = YAML.load_file @file
+ marshal_load self.to_h.merge(cfg)
else
- require 'oxidized/config/bootstrap'
+ save
end
end
+ def defaults
+ require 'oxidized/config/bootstrap'
+ end
# save config to file
def save
File.write @file, YAML.dump(marshal_dump)
end
end
CFG = Config.new
+ CFG.defaults
CFG.load
Log.file = CFG.log if CFG.log
Log.level = Logger::INFO unless CFG.debug
diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb
index 6b08b18..cf73fc8 100644
--- a/lib/oxidized/source/csv.rb
+++ b/lib/oxidized/source/csv.rb
@@ -15,8 +15,8 @@ class CSV < Source
:model => 1,
}
}
+ CFG.save
end
- CFG.save
end
def load
diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb
index c563e15..385f632 100644
--- a/lib/oxidized/source/sql.rb
+++ b/lib/oxidized/source/sql.rb
@@ -18,8 +18,8 @@ class SQL < Source
:model => 'rancid',
}
}
+ CFG.save
end
- CFG.save
end
def load
diff --git a/oxidized.gemspec b/oxidized.gemspec
index 63de5c0..9cb6ba6 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'oxidized'
- s.version = '0.0.23'
+ s.version = '0.0.24'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Saku Ytti' ]
s.email = %w( saku@ytti.fi )