Class: Oxidized::SSH

Inherits:
Input
  • Object
show all
Includes:
Input::CLI
Defined in:
lib/oxidized/input/ssh.rb

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

Methods included from Config::Vars

#vars

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



58
59
60
# File 'lib/oxidized/input/ssh.rb', line 58

def output
  @output
end

Instance Method Details

#cmd(cmd, expect = node.prompt) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/oxidized/input/ssh.rb', line 43

def cmd(cmd, expect = node.prompt)
  Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd} @ #{node.name} with expect: #{expect.inspect}"
  cmd_output = if @exec
                 @ssh.exec! cmd
               else
                 cmd_shell(cmd, expect).gsub("\r\n", "\n")
               end
  # Make sure we return a String
  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
# 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) }
  @log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?

  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
      
    rescue Timeout::Error
      raise PromptUndetect, [@output, 'not matching configured prompt', @node.prompt].join(' ')
    end
  end
  connected?
end

#connected?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/oxidized/input/ssh.rb', line 39

def connected?
  @ssh && (not @ssh.closed?)
end

#pty_options(hash) ⇒ Object



60
61
62
# File 'lib/oxidized/input/ssh.rb', line 60

def pty_options(hash)
  @pty_options = @pty_options.merge hash
end

#send(data) ⇒ Object



54
55
56
# File 'lib/oxidized/input/ssh.rb', line 54

def send(data)
  @ses.send_data data
end