Class: Cisco::Telnet
- Inherits:
-
Object
show all
- Includes:
- Common
- Defined in:
- lib/cisco/telnet.rb
Instance Attribute Summary
Attributes included from Common
#host, #password, #prompt
Instance Method Summary
collapse
Methods included from Common
#clear_cmd, #clear_init, #enable, #extra_init
Constructor Details
#initialize(options) ⇒ Telnet
Returns a new instance of Telnet.
9
10
11
12
13
14
15
16
|
# File 'lib/cisco/telnet.rb', line 9
def initialize(options)
@host = options[:host]
@password = options[:password]
@prompt = options[:prompt]
@targs = options[:directargs] || ["Host" => @host]
@pwprompt = options[:pwprompt] || "Password:"
@cmdbuf, @extra_init = [], []
end
|
Instance Method Details
#close ⇒ Object
36
37
38
39
40
|
# File 'lib/cisco/telnet.rb', line 36
def close
10.times do
chn.send_data("exit\n") while @telnet.sock
end
end
|
#cmd(cmd, prompt = nil, &block) ⇒ Object
32
33
34
|
# File 'lib/cisco/telnet.rb', line 32
def cmd(cmd, prompt = nil, &block)
@cmdbuf << [cmd, prompt, block]
end
|
#run ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/cisco/telnet.rb', line 18
def run
@results = []
(@cmdbuf = [] and yield self) if block_given?
@cmdbuf.insert(0, *@extra_init) if @extra_init.any?
@telnet = Net::Telnet.new(*@targs)
login
until @cmdbuf.empty?
send_next
@results << @telnet.waitfor(@prompt) {|x| @outblock.call(x) if @outblock}
end
@results
end
|