Class: Puppet::Util::NetworkDevice::Transport::Telnet
- Inherits:
-
Base
- Object
- Base
- Puppet::Util::NetworkDevice::Transport::Telnet
show all
- Defined in:
- lib/puppet/util/network_device/transport/telnet.rb
Instance Attribute Summary
Attributes inherited from Base
#default_prompt, #host, #password, #port, #timeout, #user
Instance Method Summary
collapse
Constructor Details
#initialize(verbose = false) ⇒ Telnet
Returns a new instance of Telnet.
7
8
9
10
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 7
def initialize(verbose = false)
super()
@verbose = verbose
end
|
Instance Method Details
22
23
24
25
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 22
def close
@telnet.close if @telnet
@telnet = nil
end
|
#command(cmd, options = {}) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 33
def command(cmd, options = {})
send(cmd)
expect(options[:prompt] || default_prompt) do |output|
yield output if block_given?
end
end
|
16
17
18
19
20
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 16
def connect
@telnet = Net::Telnet::new("Host" => host, "Port" => port || 23,
"Timeout" => 10,
"Prompt" => default_prompt)
end
|
#expect(prompt) ⇒ Object
27
28
29
30
31
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 27
def expect(prompt)
@telnet.waitfor(prompt) do |out|
yield out if block_given?
end
end
|
#handles_login? ⇒ Boolean
12
13
14
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 12
def handles_login?
false
end
|
#send(line) ⇒ Object
40
41
42
43
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 40
def send(line)
Puppet.debug("telnet: send #{line}") if @verbose
@telnet.puts(line)
end
|