Class: Oxidized::SSH
Defined Under Namespace
Classes: NoShell
Constant Summary
collapse
- RescueFail =
{
:debug => [
Net::SSH::Disconnect,
],
:warn => [
RuntimeError,
Net::SSH::AuthenticationFailed,
],
}
Instance Attribute Summary
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 Method Details
#cmd(cmd, expect = node.prompt) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/oxidized/input/ssh.rb', line 69
def cmd cmd, expect = node.prompt
Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd} @ #{node.name} with expect: #{expect.inspect}"
if @exec
@ssh.exec! cmd
else
cmd_shell(cmd, expect).gsub(/\r\n/, "\n")
end
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/oxidized/input/ssh.rb', line 19
def connect node
@node = node
@output = ''
@pty_options = { term: "vt100" }
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
secure = Oxidized.config.input.ssh.secure
@log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
port = vars(:ssh_port) || 22
ssh_opts = {
port: port.to_i,
paranoid: secure,
keepalive: true,
password: @node.auth[:password], :timeout => Oxidized.config.timeout,
number_of_password_prompts: 0,
}
auth_methods = vars(:auth_methods) || %w(none publickey password)
ssh_opts[:auth_methods] = auth_methods
Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"
if proxy_host = vars(:ssh_proxy)
proxy_command = "ssh "
proxy_command += "-o StrictHostKeyChecking=no " unless secure
proxy_command += "#{proxy_host} -W %h:%p"
proxy = Net::SSH::Proxy::Command.new(proxy_command)
ssh_opts[:proxy] = proxy
end
ssh_opts[:keys] = vars(:ssh_keys).is_a?(Array) ? vars(:ssh_keys) : [vars(:ssh_keys)] if vars(:ssh_keys)
ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}"
@ssh = Net::SSH.start(@node.ip, @node.auth[:username], 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
65
66
67
|
# File 'lib/oxidized/input/ssh.rb', line 65
def connected?
@ssh and not @ssh.closed?
end
|
#output ⇒ Object
82
83
84
|
# File 'lib/oxidized/input/ssh.rb', line 82
def output
@output
end
|
#pty_options(hash) ⇒ Object
86
87
88
|
# File 'lib/oxidized/input/ssh.rb', line 86
def pty_options hash
@pty_options = @pty_options.merge hash
end
|
#send(data) ⇒ Object
78
79
80
|
# File 'lib/oxidized/input/ssh.rb', line 78
def send data
@ses.send_data data
end
|