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.
9
10
11
12
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 9
def initialize(verbose = false)
super()
@verbose = verbose
end
|
Instance Method Details
24
25
26
27
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 24
def close
@telnet.close if @telnet
@telnet = nil
end
|
#command(cmd, options = {}) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 35
def command(cmd, options = {})
send(cmd)
expect(options[:prompt] || default_prompt) do |output|
yield output if block_given?
end
end
|
18
19
20
21
22
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 18
def connect
@telnet = Net::Telnet::new("Host" => host, "Port" => port || 23,
"Timeout" => 10,
"Prompt" => default_prompt)
end
|
#expect(prompt) ⇒ Object
29
30
31
32
33
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 29
def expect(prompt)
@telnet.waitfor(prompt) do |out|
yield out if block_given?
end
end
|
#handles_login? ⇒ Boolean
14
15
16
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 14
def handles_login?
false
end
|
#send(line) ⇒ Object
42
43
44
45
|
# File 'lib/puppet/util/network_device/transport/telnet.rb', line 42
def send(line)
Puppet.debug("telnet: send #{line}") if @verbose
@telnet.puts(line)
end
|