Class: Oxidized::SSH
Defined Under Namespace
Classes: NoShell
Constant Summary
collapse
- RESCUE_FAIL =
{
debug: [
Net::SSH::Disconnect
],
warn: [
RuntimeError,
Net::SSH::AuthenticationFailed
]
}.freeze
Instance Attribute Summary collapse
Attributes included from Input::CLI
#node
Instance Method Summary
collapse
Methods included from Input::CLI
#connect_cli, #disconnect_cli, #get, #initialize, #login, #password, #post_login, #pre_logout, #username
#vars
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
66
67
68
|
# File 'lib/oxidized/input/ssh.rb', line 66
def output
@output
end
|
Instance Method Details
#cmd(cmd, expect = node.prompt) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/oxidized/input/ssh.rb', line 47
def cmd(cmd, expect = node.prompt)
Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd.dump} @ #{node.name} with expect: #{expect.inspect}"
if Oxidized.config.input.debug?
@log.puts "sent #{cmd.dump}"
@log.flush
end
cmd_output = if @exec
@ssh.exec! cmd
else
cmd_shell(cmd, expect).gsub("\r\n", "\n")
end
cmd_output.to_s
end
|
#connect(node) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/oxidized/input/ssh.rb', line 19
def connect(node)
@node = node
@output = String.new('')
@pty_options = { term: "vt100" }
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
if Oxidized.config.input.debug?
logfile = Oxidized::Config::LOG + "/#{@node.ip}-ssh"
@log = File.open(logfile, 'w')
Oxidized.logger.debug "lib/oxidized/input/ssh.rb: I/O Debuging to #{logfile}"
end
Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}"
@ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
unless @exec
shell_open @ssh
begin
login
rescue Timeout::Error
raise PromptUndetect, [@output, 'not matching configured prompt', @node.prompt].join(' ')
end
end
connected?
end
|
#connected? ⇒ Boolean
43
44
45
|
# File 'lib/oxidized/input/ssh.rb', line 43
def connected?
@ssh && (not @ssh.closed?)
end
|
#pty_options(hash) ⇒ Object
68
69
70
|
# File 'lib/oxidized/input/ssh.rb', line 68
def pty_options(hash)
@pty_options = @pty_options.merge hash
end
|
#send(data) ⇒ Object
62
63
64
|
# File 'lib/oxidized/input/ssh.rb', line 62
def send(data)
@ses.send_data data
end
|