Skip to content

Commit

Permalink
setting host can now be modified with set_host
Browse files Browse the repository at this point in the history
Fixes #42
  • Loading branch information
Jeremy Nicklas committed Jul 12, 2017
1 parent b74009b commit c907761
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Setting the host in a batch_connect batch script can now be directly
manipulated through the `set_host` initialization parameter.
[#42](https://github.com/OSC/ood_core/issues/42)

## [0.0.5] - 2017-07-05

### Added
Expand Down
13 changes: 12 additions & 1 deletion lib/ood_core/batch_connect/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Template
# @option context [#to_s] :script_wrapper ("%s") Bash code that wraps
# around the body of the template script (use `%s` to interpolate the
# body)
# @option context [#to_s] :set_host ("host=$(hostname)") Bash code used
# to set the `host` environment variable used for connection
# information
# @option context [#to_s] :before_script ("...") Bash code run before the
# main script is forked off
# @option context [#to_s] :before_file ("before.sh") Path to script that
Expand Down Expand Up @@ -78,6 +81,11 @@ def conn_params
(conn_params + [:host, :port, :password]).uniq
end

# Bash script used to define the `host` environment variable
def set_host
context.fetch(:set_host, "host=$(hostname)").to_s
end

# Helper methods used in the bash scripts
def bash_helpers
context.fetch(:bash_helpers) do
Expand Down Expand Up @@ -126,7 +134,7 @@ def before_script
context.fetch(:before_script) do
before_file = context.fetch(:before_file, "before.sh").to_s

"host=$(hostname)\n[[ -e \"#{before_file}\" ]] && source \"#{before_file}\""
"[[ -e \"#{before_file}\" ]] && source \"#{before_file}\""
end.to_s
end

Expand Down Expand Up @@ -184,6 +192,9 @@ def base_script
#{bash_helpers}
# Set host of current machine
#{set_host}
#{before_script}
echo "Script starting..."
Expand Down

0 comments on commit c907761

Please sign in to comment.