summaryrefslogtreecommitdiff
path: root/lib/oxidized/model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized/model')
-rw-r--r--lib/oxidized/model/aosw.rb22
-rw-r--r--lib/oxidized/model/comware.rb41
-rw-r--r--lib/oxidized/model/model.rb31
-rw-r--r--lib/oxidized/model/outputs.rb41
4 files changed, 121 insertions, 14 deletions
diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb
index 26ee0fa..203c5e0 100644
--- a/lib/oxidized/model/aosw.rb
+++ b/lib/oxidized/model/aosw.rb
@@ -1,7 +1,8 @@
class AOSW < Oxidized::Model
- # AOSW - Alcatel-Lucent OS - Wireless
- # Used in Alcatel OAW-4750 WLAN controller (Aruba)
+ # AOSW Aruba Wireless
+ # Used in Alcatel OAW-4750 WLAN controller
+ # Also Dell controllers
comment '# '
prompt /^\([^)]+\) #/
@@ -16,8 +17,7 @@ class AOSW < Oxidized::Model
end
cmd 'show inventory' do |cfg|
- cfg = cfg.each_line.take_while { |line| not line.match /Output \d Config/i }
- comment cfg.join
+ clean cfg
end
cmd 'show slots' do |cfg|
@@ -40,4 +40,18 @@ class AOSW < Oxidized::Model
pre_logout 'exit'
end
+ def clean cfg
+ out = []
+ cfg.each_line do |line|
+ # drop the temperature, fan speed and voltage, which change each run
+ next if line.match /Output \d Config/i
+ next if line.match /(Tachometers|Temperatures|Voltages)/
+ next if line.match /((Card|CPU) Temperature|Chassis Fan|VMON1[0-9])/
+ next if line.match /[0-9]+ (RPM|mV|C)$/
+ out << line.strip
+ end
+ out = out.join "\n"
+ out << "\n"
+ end
+
end
diff --git a/lib/oxidized/model/comware.rb b/lib/oxidized/model/comware.rb
new file mode 100644
index 0000000..c09a128
--- /dev/null
+++ b/lib/oxidized/model/comware.rb
@@ -0,0 +1,41 @@
+class Comware < Oxidized::Model
+ # HP (A-series)/H3C/3Com Comware
+
+ prompt /^(<[\w.-]+>)$/
+ comment '# '
+
+ # example how to handle pager
+ #expect /^\s*---- More ----$/ do |data, re|
+ # send ' '
+ # data.sub re, ''
+ #end
+
+ cmd :all do |cfg|
+ #cfg.gsub! /^.*\e\[42D/, '' # example how to handle pager
+ cfg.each_line.to_a[1..-2].join
+ end
+
+ cfg :telnet do
+ username /^Username:$/
+ password /^Password:$/
+ end
+
+ cfg :telnet, :ssh do
+ post_login 'screen-length disable'
+ post_login 'undo terminal monitor'
+ pre_logout 'quit'
+ end
+
+ cmd 'display version' do |cfg|
+ cfg = cfg.each_line.select {|l| not l.match /uptime/ }.join
+ comment cfg
+ end
+
+ cmd 'display device' do |cfg|
+ comment cfg
+ end
+
+ cmd 'display current-configuration' do |cfg|
+ cfg
+ end
+end
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb
index c3d8760..d3f54b9 100644
--- a/lib/oxidized/model/model.rb
+++ b/lib/oxidized/model/model.rb
@@ -1,3 +1,5 @@
+require_relative 'outputs'
+
module Oxidized
class Model
include Oxidized::Config::Vars
@@ -77,17 +79,16 @@ module Oxidized
def cmd string, &block
out = @input.cmd string
return false unless out
- out = Oxidized::String.new out
self.class.cmds[:all].each do |all_block|
- out = instance_exec out, string, &all_block
+ out = instance_exec Oxidized::String.new(out), string, &all_block
end
if vars :remove_secret
self.class.cmds[:secret].each do |all_block|
- out = instance_exec out, string, &all_block
+ out = instance_exec Oxidized::String.new(out), string, &all_block
end
end
- out = instance_exec out, &block if block
- out
+ out = instance_exec Oxidized::String.new(out), &block if block
+ process_cmd_output out, string
end
def output
@@ -124,20 +125,20 @@ module Oxidized
end
def get
- data, pre = '', ''
+ outputs = Outputs.new
procs = self.class.procs
self.class.cmds[:cmd].each do |command, block|
out = cmd command, &block
return false unless out
- data << out.to_s
+ outputs << out
end
procs[:pre].each do |pre_proc|
- pre << instance_eval(&pre_proc).to_s
+ outputs.unshift Oxidized::String.new(instance_eval(&pre_proc))
end
procs[:post].each do |post_proc|
- data << instance_eval(&post_proc).to_s
+ outputs << Oxidized::String.new(instance_eval(&post_proc))
end
- pre + data
+ outputs
end
def comment _comment
@@ -148,5 +149,15 @@ module Oxidized
data
end
+ private
+
+ def process_cmd_output output, name
+ if output.class != Oxidized::String
+ output = Oxidized::String.new output
+ end
+ output.set_cmd(name)
+ output
+ end
+
end
end
diff --git a/lib/oxidized/model/outputs.rb b/lib/oxidized/model/outputs.rb
new file mode 100644
index 0000000..a668e9d
--- /dev/null
+++ b/lib/oxidized/model/outputs.rb
@@ -0,0 +1,41 @@
+module Oxidized
+ class Model
+ class Outputs
+
+ def to_cfg
+ type_to_str(nil)
+ end
+
+ def type_to_str want_type
+ type(want_type).map { |out| out }.join
+ end
+
+ def << output
+ @outputs << output
+ end
+
+ def unshift output
+ @outputs.unshift output
+ end
+
+ def all
+ @outputs
+ end
+
+ def type type
+ @outputs.select { |out| out.type==type }
+ end
+
+ def types
+ @outputs.map { |out| out.type }.uniq.compact
+ end
+
+ private
+
+ def initialize
+ @outputs = []
+ end
+
+ end
+ end
+end