Class: HybridPlatformsConductor::HpcPlugins::Action::RemoteBash

Inherits:
Action
  • Object
show all
Defined in:
lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb

Overview

Execute a bash command on the remote node

Constant Summary

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Instance Method Summary collapse

Methods inherited from Action

#initialize, #prepare_for

Methods inherited from Plugin

extend_config_dsl_with, #initialize, valid?

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

This class inherits a constructor from HybridPlatformsConductor::Action

Instance Method Details

#executeObject

Execute the action

API
  • This method is mandatory

API
  • @cmd_runner is accessible

API
  • @actions_executor is accessible

API
  • @action_info is accessible with the action details

API
  • @node (String) can be used to know on which node the action is to be executed

API
  • @connector (Connector or nil) can be used to access the node’s connector if the action needs remote connection

API
  • @timeout (Integer) should be used to make sure the action execution does not get past this number of seconds

API
  • @stdout_io can be used to log stdout messages

API
  • @stderr_io can be used to log stderr messages

API
  • run_cmd(String) method can be used to execute a command. See CmdRunner#run_cmd to know about the result’s signature.



65
66
67
68
69
70
71
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 65

def execute
  bash_str = @remote_bash.map do |cmd_info|
    (cmd_info[:env].map { |var_name, var_value| "export #{var_name}='#{var_value}'" } + cmd_info[:commands]).join("\n")
  end.join("\n")
  log_debug "[#{@node}] - Execute remote Bash commands \"#{bash_str}\"..."
  @connector.remote_bash bash_str
end

#need_connector?Boolean

Do we need a connector to execute this action on a node?

Result
  • Boolean: Do we need a connector to execute this action on a node?

Returns:

  • (Boolean)


50
51
52
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 50

def need_connector?
  true
end

#setup(remote_bash) ⇒ Object

Setup the action. This is called by the constructor itself, when an action is instantiated to be executed for a node.

API
  • This method is optional

API
  • @cmd_runner is accessible

API
  • @actions_executor is accessible

Parameters
  • remote_bash (Array or Object): List of commands (or single command) to be executed. Each command can be the following:

    • String: Simple bash command.

    • Hash<Symbol, Object>: Information about the commands to execute. Can have the following properties:

      • commands (Array<String> or String): List of bash commands to execute (can be a single one) [default: ”].

      • file (String): Name of file from which commands should be taken [optional].

      • env (Hash<String, String>): Environment variables to be set before executing those commands [default: {}].



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 23

def setup(remote_bash)
  # Normalize the parameters.
  # Array< Hash<Symbol,Object> >: Simple array of info:
  # * *commands* (Array<String>): List of bash commands to execute.
  # * *env* (Hash<String, String>): Environment variables to be set before executing those commands.
  @remote_bash = (remote_bash.is_a?(Array) ? remote_bash : [remote_bash]).map do |cmd_info|
    if cmd_info.is_a?(String)
      {
        commands: [cmd_info],
        env: {}
      }
    else
      commands = []
      commands.concat(cmd_info[:commands].is_a?(String) ? [cmd_info[:commands]] : cmd_info[:commands]) if cmd_info[:commands]
      commands << File.read(cmd_info[:file]) if cmd_info[:file]
      {
        commands: commands,
        env: cmd_info[:env] || {}
      }
    end
  end
end