Class: OodCore::BatchConnect::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/batch_connect/template.rb

Overview

A template class that renders a batch script designed to facilitate external connections to the running job

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = {}) ⇒ Template

Returns a new instance of Template.

Parameters:

  • context (#to_h) (defaults to: {})

    the context used to render the template

Options Hash (context):

  • :work_dir (#to_s)

    Working directory for batch script

  • :conn_file (#to_s) — default: "connection.yml"

    The file that holds connection information

  • :conn_params (#to_sym, Array<#to_sym>) — default: []

    A list of connection parameters added to the connection file (`:host`, `:port`, and `:password` will always exist)

  • :bash_helpers (#to_s) — default: "..."

    Bash helper methods

  • :min_port (#to_i) — default: 2000

    Minimum port used when looking for available port

  • :max_port (#to_i) — default: 65535

    Maximum port used when looking for available port

  • :password_size (#to_i) — default: 32

    Length of randomly generated password

  • :header (#to_s) — default: ""

    Shell code prepended at the top of the script body

  • :footer (#to_s) — default: ""

    Shell code appended at the bottom of the script body

  • :script_wrapper (#to_s) — default: "%s"

    Bash code that wraps around the body of the template script (use `%s` to interpolate the body)

  • :set_host (#to_s) — default: "host=$(hostname)"

    Bash code used to set the `host` environment variable used for connection information

  • :before_script (#to_s) — default: "..."

    Bash code run before the main script is forked off

  • :before_file (#to_s) — default: "before.sh"

    Path to script that is sourced before main script is forked (assumes you don't modify `:before_script`)

  • :run_script (#to_s) — default: "..."

    Bash code that is forked off and treated as the main script

  • :script_file (#to_s) — default: "./script.sh"

    Path to script that is forked as the main scripta (assumes you don't modify `:run_script`)

  • :timeout (#to_s) — default: ""

    Timeout the main script in seconds, if empty then let script run for full walltime (assumes you don't modify `:run_script`)

  • :clean_script (#to_s) — default: "..."

    Bash code run during clean up after job finishes

  • :clean_file (#to_s) — default: "clean.sh"

    Path to script that is sourced during clean up (assumes you don't modify `:clean_script`)

Raises:

  • (ArgumentError)


56
57
58
59
# File 'lib/ood_core/batch_connect/template.rb', line 56

def initialize(context = {})
  @context = context.to_h.compact.symbolize_keys
  raise ArgumentError, "No work_dir specified. Missing argument: work_dir" unless context.include?(:work_dir)
end

Instance Attribute Details

#contextHash (readonly)

The context used to render this template

Returns:

  • (Hash)

    context hash



13
14
15
# File 'lib/ood_core/batch_connect/template.rb', line 13

def context
  @context
end

Instance Method Details

#to_sString

Render this template as string

Returns:

  • (String)

    rendered template



63
64
65
66
67
68
69
# File 'lib/ood_core/batch_connect/template.rb', line 63

def to_s
  <<-EOT.gsub(/^ {10}/, '')
    #{header}
    #{script_wrapper}
    #{footer}
  EOT
end