Class: Chimp::ExecSSH

Inherits:
Executor show all
Defined in:
lib/right_chimp/exec/ExecSSH.rb

Constant Summary

Constants inherited from Executor

Chimp::Executor::STATUS_DONE, Chimp::Executor::STATUS_ERROR, Chimp::Executor::STATUS_HOLDING, Chimp::Executor::STATUS_NONE, Chimp::Executor::STATUS_RETRYING, Chimp::Executor::STATUS_RUNNING

Instance Attribute Summary collapse

Attributes inherited from Executor

#array, #dry_run, #error, #exec, #group, #inputs, #job_id, #owner, #quiet, #results, #retry_count, #retry_sleep, #server, #status, #template, #time_end, #time_start, #timeout, #verbose

Instance Method Summary collapse

Methods inherited from Executor

#cancel, #get_total_exec_time, #queue, #requeue

Constructor Details

#initialize(h = {}) ⇒ ExecSSH

Returns a new instance of ExecSSH.



8
9
10
11
# File 'lib/right_chimp/exec/ExecSSH.rb', line 8

def initialize(h={})
  super(h)
  @ssh_user = h[:ssh_user]
end

Instance Attribute Details

#ssh_userObject

Returns the value of attribute ssh_user.



6
7
8
# File 'lib/right_chimp/exec/ExecSSH.rb', line 6

def ssh_user
  @ssh_user
end

Instance Method Details

#describe_workObject



32
33
34
# File 'lib/right_chimp/exec/ExecSSH.rb', line 32

def describe_work
  return "ExecSSH job_id=#{@job_id} command=\"#{@exec}\" server=\"#{@server['nickname']}\""
end

#infoObject



36
37
38
# File 'lib/right_chimp/exec/ExecSSH.rb', line 36

def info
  return @exec.to_s
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/right_chimp/exec/ExecSSH.rb', line 13

def run
  host = @server['ip_address'] || @server['ip-address'] || nil
  @ssh_user ||= "root"
  
  if host == nil
    @server.settings
    host = @server['ip_address'] || @server['ip-address']
  end
  
  run_with_retry do
    Log.debug "ssh #{@ssh_user}@#{host} \"#{@exec}\""
    success = system("ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no #{@ssh_user}@#{host} \"#{@exec}\"")
    
    if not $?.success?
      raise "SSH failed with status: #{$?}"
    end
  end
end

#targetObject



40
41
42
# File 'lib/right_chimp/exec/ExecSSH.rb', line 40

def target
  return @server['nickname']
end