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.



48
49
50
51
52
53
54
55
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 48

def execute
  bash_commands = (@remote_bash[:env] || {}).map { |var_name, var_value| "export #{var_name}='#{var_value}'" }
  bash_commands.concat(@remote_bash[:commands].clone) if @remote_bash.key?(:commands)
  bash_commands << File.read(@remote_bash[:file]) if @remote_bash.key?(:file)
  bash_str = bash_commands.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)


33
34
35
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 33

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< Hash<Symbol, Object> or Array<String> or String>): List of bash actions to execute. Each action can have the following properties:

    • commands (Array<String> or String): List of bash commands to execute (can be a single one). This is the default property also that allows to not use the Hash form for brevity.

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

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



21
22
23
24
25
26
27
# File 'lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb', line 21

def setup(remote_bash)
  @remote_bash = remote_bash
  # Normalize the parameters
  @remote_bash = [@remote_bash] if @remote_bash.is_a?(String)
  @remote_bash = { commands: @remote_bash } if @remote_bash.is_a?(Array)
  @remote_bash[:commands] = [@remote_bash[:commands]] if @remote_bash[:commands].is_a?(String)
end