class Commands::AbstractSSHCommand

Constants

CLOSED_DOWN_STATES
WAITING_OR_RUNNING_STATES

Attributes

dest[RW]
hostname[RW]
jobflow_detail[RW]
jobflow_id[RW]
key_pair_file[RW]
no_wait[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Commands::Command::new
# File lib/commands.rb, line 582
def initialize(*args)
  super(*args)
  @ssh_opts = ["-o ServerAliveInterval=10", "-o StrictHostKeyChecking=no"]
  @scp_opts = ["-r"]
end

Public Instance Methods

enact(client) click to toggle source
# File lib/commands.rb, line 619
def enact(client)
  self.jobflow_id = require_single_jobflow
  self.jobflow_detail = client.describe_jobflow_with_id(self.jobflow_id)
  if ! get_field(:no_wait) then
    wait_for_jobflow(client)
  end
  self.hostname = self.jobflow_detail['Instances']['MasterPublicDnsName']
  self.key_pair_file = require(:key_pair_file, "Missing required option --key-pair-file for #{name}")
end
exec(cmd) click to toggle source
# File lib/commands.rb, line 600
def exec(cmd)
  commands.exec(cmd)
end
get_scp_opts() click to toggle source
# File lib/commands.rb, line 596
def get_scp_opts
  get_field(:scp_opts, []).join(" ")
end
get_ssh_opts() click to toggle source
# File lib/commands.rb, line 592
def get_ssh_opts
  get_field(:ssh_opts, []).join(" ")
end
opts() click to toggle source
# File lib/commands.rb, line 588
def opts
  (get_field(:ssh_opts, []) + get_field(:scp_opts, [])).join(" ")
end
wait_for_jobflow(client) click to toggle source
# File lib/commands.rb, line 604
def wait_for_jobflow(client)
  while true do
    state = resolve(self.jobflow_detail, "ExecutionStatusDetail", "State")
    if WAITING_OR_RUNNING_STATES.include?(state) then
      break
    elsif CLOSED_DOWN_STATES.include?(state) then
      raise RuntimeError, "Jobflow entered #{state} while waiting to ssh"
    else
      logger.info("Jobflow is in state #{state}, waiting....")
      sleep(30)
      self.jobflow_detail = client.describe_jobflow_with_id(jobflow_id)
    end
  end
end