Module: Rortel::Expectical

Included in:
Dms, Unix
Defined in:
lib/rortel/expectical.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject

Returns the value of attribute error.



6
7
8
# File 'lib/rortel/expectical.rb', line 6

def error
  @error
end

#infoObject

Returns the value of attribute info.



6
7
8
# File 'lib/rortel/expectical.rb', line 6

def info
  @info
end

#outputObject

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_bufferObject



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

#closeObject



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