diff options
author | Saku Ytti <saku@ytti.fi> | 2014-12-03 15:22:19 +0200 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-12-03 15:22:19 +0200 |
commit | 53daa6fab0b87c6ef6dc3efda9f0eff0f6af5e3e (patch) | |
tree | c2f3e679f5770941d2dbc8036266a8617a3340c7 /lib | |
parent | 32733012e2bcda5373406aec8156dcb9c00a58ce (diff) | |
parent | 6132f0f825d281c2d5c7d918239eeec80b3e87be (diff) |
Merge branch 'master' into cfg_as_object
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oxidized/model/asa.rb | 9 | ||||
-rw-r--r-- | lib/oxidized/model/ios.rb | 4 | ||||
-rw-r--r-- | lib/oxidized/model/nos.rb | 45 | ||||
-rw-r--r-- | lib/oxidized/model/nxos.rb | 23 | ||||
-rw-r--r-- | lib/oxidized/model/powerconnect.rb | 14 | ||||
-rw-r--r-- | lib/oxidized/model/xos.rb | 40 | ||||
-rw-r--r-- | lib/oxidized/nodes.rb | 21 |
7 files changed, 138 insertions, 18 deletions
diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb index 3ee4e2d..8335b1d 100644 --- a/lib/oxidized/model/asa.rb +++ b/lib/oxidized/model/asa.rb @@ -3,7 +3,7 @@ class ASA < Oxidized::Model # Cisco ASA model # # Only SSH supported for the sake of security - prompt /^\r*([\w]+[#>]\s?)$/ + prompt /^\r*([\w.@()-\/]+[#>]\s?)$/ comment '! ' cmd :all do |cfg| @@ -16,11 +16,10 @@ class ASA < Oxidized::Model cfg end - cmd 'show clock' do |cfg| - comment cfg - end - cmd 'show version' do |cfg| + # avoid commits due to uptime / ixo-router01 up 2 mins 28 secs / ixo-router01 up 1 days 2 hours + cfg = cfg.each_line.select { |line| not line.match /\s+up\s+\d+\s+/ } + cfg = cfg.join comment cfg end diff --git a/lib/oxidized/model/ios.rb b/lib/oxidized/model/ios.rb index d2b4996..6fa3c5c 100644 --- a/lib/oxidized/model/ios.rb +++ b/lib/oxidized/model/ios.rb @@ -37,9 +37,9 @@ class IOS < Oxidized::Model end cmd 'show running-config' do |cfg| - cfg = cfg.each_line.to_a[3..-1].join + cfg = cfg.each_line.to_a[3..-1] + cfg = cfg.reject { |line| line.match /^ntp clock-period / }.join cfg.gsub! /^Current configuration : [^\n]*\n/, '' - cfg.sub! /^(ntp clock-period).*/, '! \1' cfg.gsub! /^\ tunnel\ mpls\ traffic-eng\ bandwidth[^\n]*\n*( (?:\ [^\n]*\n*)* tunnel\ mpls\ traffic-eng\ auto-bw)/mx, '\1' diff --git a/lib/oxidized/model/nos.rb b/lib/oxidized/model/nos.rb new file mode 100644 index 0000000..c2f4319 --- /dev/null +++ b/lib/oxidized/model/nos.rb @@ -0,0 +1,45 @@ +class NOS < Oxidized::Model + + # Brocade Network Operating System + + prompt /^(?:\e\[..h)?[\w.-]+# $/ + comment '! ' + + cmd :all do |cfg| + cfg.each_line.to_a[1..-2].join + end + + cmd 'show version' do |cfg| + comment cfg + end + + cmd 'show inventory' do |cfg| + comment cfg + end + + cmd 'show license' do |cfg| + comment cfg + end + + cmd 'show chassis' do |cfg| + comment cfg.each_line.reject { |line| line.match /Time/ }.join + end + + cfg 'show system' do |cfg| + commen cfg.each_line.reject { |line| line.match /Time/ or line.match /speed/ } + end + + cmd 'show running-config' + + cfg :telnet do + username /^.* login: / + username /^Password:/ + end + + cfg :telnet, :ssh do + post_login 'terminal length 0' + #post_login 'terminal width 0' + pre_logout 'exit' + end + +end diff --git a/lib/oxidized/model/nxos.rb b/lib/oxidized/model/nxos.rb new file mode 100644 index 0000000..6163724 --- /dev/null +++ b/lib/oxidized/model/nxos.rb @@ -0,0 +1,23 @@ +class NXOS < Oxidized::Model + + prompt /^(\r?[\w.@_()-]+[#]\s?)$/ + comment '! ' + + cmd 'show version' do |cfg| + cfg = cfg.each_line.take_while { |line| not line.match(/uptime/i) } + comment cfg.join "" + end + + cmd 'show inventory' do |cfg| + comment cfg + end + + cmd 'show running-config' do |cfg| + cfg.gsub! /^!Time:[^\n]*\n/, '' + end + + cfg :ssh do + post_login 'terminal length 0' + pre_logout 'exit' + end +end diff --git a/lib/oxidized/model/powerconnect.rb b/lib/oxidized/model/powerconnect.rb index 1d0352e..a1fe229 100644 --- a/lib/oxidized/model/powerconnect.rb +++ b/lib/oxidized/model/powerconnect.rb @@ -14,12 +14,14 @@ class PowerConnect < Oxidized::Model end cmd 'show version' do |cfg| - comment cfg + cfg = cfg.split("\n").select { |line| not line[/Up\sTime/] } + comment cfg.join("\n") + "\n" end cmd 'show system' do |cfg| - cfg = cfg.each_line.take_while { |line| not line.match(/uptime/i) } - comment cfg.join "\n" + cfg = cfg.split("\n").select { |line| not line[/Up\sTime/] } + cfg = cfg[0..-28]<<" " + comment cfg.join("\n") end cmd 'show running-config' @@ -31,8 +33,10 @@ class PowerConnect < Oxidized::Model cfg :telnet, :ssh do if vars :enable - send "enable\n" - send vars(:enable) + "\n" + post_login do + send "enable\n" + send vars(:enable) + "\n" + end end post_login "terminal length 0" diff --git a/lib/oxidized/model/xos.rb b/lib/oxidized/model/xos.rb new file mode 100644 index 0000000..a8292ca --- /dev/null +++ b/lib/oxidized/model/xos.rb @@ -0,0 +1,40 @@ +class XOS < Oxidized::Model + + # Extreme Networks XOS + + prompt /^*?[\w .-]+# $/ + comment '# ' + + cmd :all do |cfg| + cfg.each_line.to_a[1..-2].join.rstrip + end + + cmd 'show version' do |cfg| + comment cfg + end + + cmd 'show diagnostics' do |cfg| + comment cfg + end + + cmd 'show licenses' do |cfg| + comment cfg + end + + cmd 'show switch'do |cfg| + comment cfg.each_line.reject { |line| line.match /Time:/ or line.match /boot/i }.join + end + + cmd 'show configuration' + + cfg :telnet do + username /^login:/ + password /^passowrd:/ + end + + cfg :telnet, :ssh do + post_login 'disable clipaging' + pre_logout 'exit' + end + +end diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 6f30af4..032118d 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -9,16 +9,11 @@ module Oxidized def load node_want=nil with_lock do new = [] - node_want_ip = (IPAddr.new(node_want) rescue false) if node_want @source = CFG.source.default Oxidized.mgr.add_source @source Oxidized.mgr.source[@source].new.load.each do |node| - # we want to load specific node(s), not all of them - if node_want - next unless node_want_ip == node[:ip] or node_want.match(node[:name]) - end - + next unless node_want? node_want, node begin _node = Node.new node new.push _node @@ -33,6 +28,20 @@ module Oxidized end end + def node_want? node_want, node + return true unless node_want + node_want_ip = (IPAddr.new(node_want) rescue false) + name_is_ip = (IPAddr.new(node[:name]) rescue false) + if name_is_ip and node_want_ip == node[:name] + true + elsif node[:ip] and node_want_ip == node[:ip] + true + elsif node_want.match node[:name] + true unless name_is_ip + end + end + + def list with_lock do map { |e| e.serialize } |