diff options
author | Elvin Efendi <elvin.efendiev@shopify.com> | 2015-10-27 14:49:52 -0400 |
---|---|---|
committer | Elvin Efendi <elvin.efendiev@shopify.com> | 2015-11-13 11:12:31 -0500 |
commit | f2da63369fcb754e3715091cc4fd2f93db42106e (patch) | |
tree | 0e985374cc7b4bd8111c012072c39218335881ef /lib/oxidized/config.rb | |
parent | 1400b842f6dc61e662ce15f72f578a55126ffc06 (diff) |
better test framework, more specs and Travis CI
Diffstat (limited to 'lib/oxidized/config.rb')
-rw-r--r-- | lib/oxidized/config.rb | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index f45004a..36c1a8f 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -11,47 +11,52 @@ module Oxidized SourceDir = File.join Directory, %w(lib oxidized source) HookDir = File.join Directory, %w(lib oxidized hook) Sleep = 1 + + def self.load + asetus = Asetus.new(name: 'oxidized', load: false, key_to_s: true) + Oxidized.asetus = asetus + + asetus.default.username = 'username' + asetus.default.password = 'password' + asetus.default.model = 'junos' + asetus.default.interval = 3600 + asetus.default.log = File.join Config::Root, 'log' + asetus.default.debug = false + asetus.default.threads = 30 + asetus.default.timeout = 20 + asetus.default.retries = 3 + asetus.default.prompt = /^([\w.@-]+[#>]\s?)$/ + asetus.default.rest = '127.0.0.1:8888' # or false to disable + asetus.default.vars = {} # could be 'enable'=>'enablePW' + asetus.default.groups = {} # group level configuration + + asetus.default.input.default = 'ssh, telnet' + asetus.default.input.debug = false # or String for session log file + asetus.default.input.ssh.secure = false # complain about changed certs + + asetus.default.output.default = 'file' # file, git + asetus.default.source.default = 'csv' # csv, sql + + asetus.default.model_map = { + 'cisco' => 'ios', + 'juniper' => 'junos', + } + + begin + asetus.load # load system+user configs, merge to Config.cfg + rescue => error + raise InvalidConfig, "Error loading config: #{error.message}" + end + + Log.level = Logger::INFO unless asetus.cfg.debug + raise NoConfig, 'edit ~/.config/oxidized/config' if asetus.create + Log.file = asetus.cfg.log if asetus.cfg.log + + asetus + end end + class << self attr_accessor :mgr, :Hooks end - CFGS = Asetus.new :name=>'oxidized', :load=>false, :key_to_s=>true - CFGS.default.username = 'username' - CFGS.default.password = 'password' - CFGS.default.model = 'junos' - CFGS.default.interval = 3600 - CFGS.default.log = File.join Config::Root, 'log' - CFGS.default.debug = false - CFGS.default.threads = 30 - CFGS.default.timeout = 20 - CFGS.default.retries = 3 - CFGS.default.prompt = /^([\w.@-]+[#>]\s?)$/ - CFGS.default.rest = '127.0.0.1:8888' # or false to disable - CFGS.default.vars = {} # could be 'enable'=>'enablePW' - CFGS.default.groups = {} # group level configuration - - CFGS.default.input.default = 'ssh, telnet' - CFGS.default.input.debug = false # or String for session log file - CFGS.default.input.ssh.secure = false # complain about changed certs - - CFGS.default.output.default = 'file' # file, git - CFGS.default.source.default = 'csv' # csv, sql - - CFGS.default.model_map = { - 'cisco' => 'ios', - 'juniper' => 'junos', - } - - begin - CFGS.load # load system+user configs, merge to Config.cfg - rescue => error - raise InvalidConfig, "Error loading config: #{error.message}" - ensure - CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password - end - - Log.level = Logger::INFO unless CFG.debug - raise NoConfig, 'edit ~/.config/oxidized/config' if CFGS.create - Log.file = CFG.log if CFG.log - end |