Class: Minicron::Transport::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/minicron/transport/ssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SSH

Set all the options for the ssh instance

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • user (String)
  • host (String)
  • port (Integer)
  • path (String)

    to the private key


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/minicron/transport/ssh.rb', line 12

def initialize(options = {})
  @user = options[:user]
  @host = options[:host]
  @port = options[:port]
  @private_key = File.expand_path(options[:private_key])

  # TODO: Make these configurable?
  @auth_methods = ['publickey']
  @host_key = 'ssh-rsa'
  @timeout = 10
end

Instance Method Details

#closeObject

Close the SSH connection


45
46
47
# File 'lib/minicron/transport/ssh.rb', line 45

def close
  @ssh.close
end

#exec!(command) ⇒ Object

Execute a command on the host and block until output is returned

Parameters:

  • command (String)

40
41
42
# File 'lib/minicron/transport/ssh.rb', line 40

def exec!(command)
  @ssh.exec!(command)
end

#openObject

Open the SSH connection


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/minicron/transport/ssh.rb', line 25

def open
  @ssh = Net::SSH.start(
    @host,
    @user,
    :port => @port,
    :keys => [@private_key],
    :auth_methods => @auth_methods,
    :host_key => @host_key,
    :timeout => @timeout
  )
end