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

RescueFail =
{
  :debug => [
    Net::SSH::Disconnect,
  ],
  :warn => [
    RuntimeError,
    Net::SSH::AuthenticationFailed,
  ],
}

Instance Method Summary collapse

Methods included from Input::CLI

#connect_cli, #disconnect_cli, #get, #initialize, #password, #post_login, #pre_logout, #username

Methods included from Config::Vars

#vars

Instance Method Details

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



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

def cmd cmd, expect=@node.prompt
  Log.debug "SSH: #{cmd} @ #{@node.name}"
  if @exec
    @ssh.exec! cmd
  else
    cmd_shell(cmd, expect).gsub(/\r\n/, "\n")
  end
end

#connect(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/oxidized/input/ssh.rb', line 18

def connect node
  @node       = node
  @output     = ''
  @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
  secure = CFG.input.ssh.secure
  @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ssh", 'w') if CFG.input.debug?
  port = vars(:ssh_port) || 22
  @ssh = Net::SSH.start @node.ip, @node.auth[:username], :port => port.to_i,
                        :password => @node.auth[:password], :timeout => CFG.timeout,
                        :paranoid => secure,
                        :auth_methods => %w(none publickey password keyboard-interactive),
                        :number_of_password_prompts => 0
  unless @exec
    shell_open @ssh
    begin
      @username ?  : expect(@node.prompt)
    rescue Timeout::Error
      raise PromptUndetect, [ @output, 'not matching configured prompt', @node.prompt ].join(' ')
    end
  end
  connected?
end

#connected?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/oxidized/input/ssh.rb', line 41

def connected?
  @ssh and not @ssh.closed?
end

#outputObject



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

def output
  @output
end

#send(data) ⇒ Object



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

def send data
  @ses.send_data data
end