Class: Proxy::RemoteExecution::Ssh::CommandAction

Inherits:
Dynflow::Action
  • Object
show all
Includes:
Dynflow::Action::Cancellable, SmartProxyDynflowCore::Callback::PlanHelper
Defined in:
lib/smart_proxy_remote_execution_ssh_core/command_action.rb

Instance Method Summary collapse

Instance Method Details

#commandObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 44

def command
  @command ||= Dispatcher::Command.new(:id                    => input[:task_id],
                                       :host                  => input[:hostname],
                                       :ssh_user              => input[:ssh_user] || 'root',
                                       :effective_user        => input[:effective_user],
                                       :script                => input[:script],
                                       :effective_user_method => input[:effective_user_method],
                                       :host_public_key       => input[:host_public_key],
                                       :verify_host           => input[:verify_host],
                                       :suspended_action      => suspended_action)
end

#failed_run?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 80

def failed_run?
  output[:exit_status] != 0
end

#finalizeObject



35
36
37
38
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 35

def finalize
  # To mark the task as a whole as failed
  error! "Script execution failed" if failed_run?
end

#finish_run(update) ⇒ Object



67
68
69
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 67

def finish_run(update)
  output[:exit_status] = update.exit_status
end

#init_runObject



56
57
58
59
60
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 56

def init_run
  output[:result] = []
  Proxy::RemoteExecution::Ssh.dispatcher.tell([:initialize_command, command])
  suspend
end

#kill_runObject



62
63
64
65
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 62

def kill_run
  Proxy::RemoteExecution::Ssh.dispatcher.tell([:kill, command])
  suspend
end

#plan(input) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 8

def plan(input)
  if callback = input['callback']
    input[:task_id] = callback['task_id']
  else
    input[:task_id] ||= SecureRandom.uuid
  end
  plan_with_callback(input)
end

#process_update(update) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 71

def process_update(update)
  output[:result].concat(update.buffer_to_hash)
  if update.exit_status
    finish_run(update)
  else
    suspend
  end
end

#rescue_strategy_for_selfObject



40
41
42
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 40

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#run(event = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/smart_proxy_remote_execution_ssh_core/command_action.rb', line 17

def run(event = nil)
  case event
  when nil
    init_run
  when CommandUpdate
    process_update(event)
  when Dynflow::Action::Cancellable::Cancel
    kill_run
  when Dynflow::Action::Skip
    # do nothing
  else
    raise "Unexpected event #{event.inspect}"
  end
rescue => e
  action_logger.error(e)
  process_update(CommandUpdate.new(CommandUpdate.encode_exception("Proxy error", e)))
end