Module: Rortel::Expectical
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#info ⇒ Object
Returns the value of attribute info.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #clear_read_buffer ⇒ Object
- #close ⇒ Object
- #expect_times(pat, count, r = @r, timeout = @timeout) ⇒ Object
- #read(r = @r, timeout = @timeout, prompt = @prompt) ⇒ Object
- #run(cmd, prompt = @prompt) ⇒ Object
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
6 7 8 |
# File 'lib/rortel/expectical.rb', line 6 def error @error end |
#info ⇒ Object
Returns the value of attribute info.
6 7 8 |
# File 'lib/rortel/expectical.rb', line 6 def info @info end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/rortel/expectical.rb', line 6 def output @output end |
Instance Method Details
#clear_read_buffer ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/rortel/expectical.rb', line 52 def clear_read_buffer puts "before" while @r.gets != nil @r.gets end puts "after" end |
#close ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rortel/expectical.rb', line 41 def close begin @w.close @r.close #just to be sure, nuke it Process.kill(:SIGKILL, @p) @output.push("connection closed in close method") rescue Exception => ee @error.push("ERROR: Problem closing connection: #{ee.to_s}") end end |
#expect_times(pat, count, r = @r, timeout = @timeout) ⇒ Object
35 36 37 38 39 |
# File 'lib/rortel/expectical.rb', line 35 def expect_times(pat,count,r=@r,timeout=@timeout) count.times.each do r.expect(pat,timeout) end end |
#read(r = @r, timeout = @timeout, prompt = @prompt) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rortel/expectical.rb', line 8 def read(r=@r,timeout=@timeout,prompt=@prompt) begin r.expect(prompt,timeout) do |rec| if rec == nil then @error.push("ERROR: Timeout talking to device") close() return rec else rec=rec.to_s @output.push(rec) return rec end end rescue Exception => ee @error.push "ERROR:Exception trying to read stream: #{ee.to_s}" return @output end end |
#run(cmd, prompt = @prompt) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rortel/expectical.rb', line 26 def run(cmd,prompt=@prompt) begin @w.print("#{cmd}\r") buffer = read(@r,@timeout,prompt) rescue Exception => ee @error.push("ERROR: Exception for host while executing #{cmd}: #{ee.to_s}") end return buffer end |