summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2013-04-21 17:31:29 +0300
committerSaku Ytti <saku@ytti.fi>2013-04-21 17:31:29 +0300
commite5ed57cbc77b241e93942af22b1d90efcfe1267f (patch)
treed283c3300cf48beb38a0bd709ce919125c639e24 /lib/oxidized
parentf715a419196c65ee0cc3b7d9e346aa2512c0cd21 (diff)
Run 'main' method if it exists
Gives alternative, maybe less awkward way to do conditional commands. You can first use cmd methods to gather stuff you want, then in main method you could conditional to things based on them, maybe futher call methods per model.
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/model/junos.rb8
-rw-r--r--lib/oxidized/model/model.rb1
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/oxidized/model/junos.rb b/lib/oxidized/model/junos.rb
index d1f4de6..72f5275 100644
--- a/lib/oxidized/model/junos.rb
+++ b/lib/oxidized/model/junos.rb
@@ -15,12 +15,12 @@ class JunOS < Oxidized::Model
cmd 'show configuration'
cmd 'show version' do |cfg|
- chassis = model $1 if cfg.match /^Model: (\S+)/
- comment cfg << chassis.to_s
+ @model = $1 if cfg.match /^Model: (\S+)/
+ comment cfg
end
- def model chassis
- case chassis
+ def main
+ case @model
when 'mx960'
cmd('show chassis fabric reachability') { |cfg| comment cfg }
end
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb
index 00a520d..b768bfb 100644
--- a/lib/oxidized/model/model.rb
+++ b/lib/oxidized/model/model.rb
@@ -62,6 +62,7 @@ module Oxidized
out = instance_exec out, &cmd_block if cmd_block
data << out.to_s
end
+ data << main.to_s if respond_to? :main
data
end