Class: CloudRunner::Ssh

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :auth_methods => ["publickey"],
  :paranoid => false,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(host, user, ssh_key) ⇒ Ssh

Returns a new instance of Ssh.



13
14
15
16
17
# File 'lib/cloud_runner/ssh.rb', line 13

def initialize(host, user, ssh_key)
  raise "Host must be specified" unless @host = host
  raise "User must be specified" unless @user = user
  raise "Key must be specified"  unless @ssh_key = ssh_key
end

Instance Method Details

#run_script(local_path, out, err, opts = {}) ⇒ Object



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

def run_script(local_path, out, err, opts={})
  ssh_opts = DEFAULT_OPTIONS.clone.merge(
    :keys => [@ssh_key.private_path],
    :host_key => "ssh-#{@ssh_key.type}",
    :logger => opts[:ssh_logger] || StringIO.new,
    :verbose => :debug,
  )

  # Assume the worst
  @exit_code = 1

  Net::SSH.start(@host, @user, ssh_opts) do |ssh|
    ssh.scp.upload!(local_path, remote_path)
    ssh.exec!("chmod +x #{remote_path}")
    full_exec(ssh, remote_path, out, err)
  end

  @exit_code
end