class OSC::VNC::ConnView

Provides a view for a variety of connection information templates in templates/conn. Extra options can be passed to this view and accessed directly in the mustache templates.

Attributes

connfile[R]

@return [Pathname] The path to the connection file.

script[R]

@return [ScriptView] The script object with information about the job setup.

Public Class Methods

new(script, connfile, opts = {}) click to toggle source

@param script [ScriptView] The script object with information about the job setup.. @param connfile [#to_s] The connection file with the connection information. @param opts [Hash] The options used to construct a connection information view.

# File lib/osc/vnc/connview.rb, line 20
def initialize(script, connfile, opts = {})
  @script = script
  @connfile = Pathname.new(connfile.to_s)
  refresh
end

Public Instance Methods

method_missing(method_name, *arguments, &block) click to toggle source

Check if the method call exists on @conn_context or the script object

@param method_name the method name called @param arguments the arguments to the call @param block an optional block for the call

Calls superclass method
# File lib/osc/vnc/connview.rb, line 62
def method_missing(method_name, *arguments, &block)
  @conn_context.fetch(method_name) do
    if script.respond_to? method_name
      script.send method_name
    else
      super
    end
  end
end
refresh() click to toggle source

Get connection info from file generated by PBS batch job (read template/script/vnc.mustache).

@return [ConnView] the connection view object @raise [InvalidPath] if connection file does not exist @raise [InvalidConnInfo] if connection file doesn't contain required information (i.e.: host, port, display, password)

# File lib/osc/vnc/connview.rb, line 52
def refresh
  _get_file_contents(connfile.to_s)
  self
end
respond_to_missing?(method_name, include_private = false) click to toggle source

Checks if the method responds to an instance method, or is able to proxy it to @conn_context or the script object.

@param method_name the method name to check @return [Boolean]

Calls superclass method
# File lib/osc/vnc/connview.rb, line 77
def respond_to_missing?(method_name, include_private = false)
  @conn_context.include?(method_name) || script.respond_to?(method_name) || super
end
sshhost() click to toggle source

The host to use for the ssh connection. @return [String] the hostname for the login node

# File lib/osc/vnc/connview.rb, line 42
def sshhost
  "#{script.cluster}.osc.edu"
end
sshuser() click to toggle source

The user to use for the ssh connection. @return [String] the current user

# File lib/osc/vnc/connview.rb, line 36
def sshuser
  ENV['USER']
end

Private Instance Methods

_get_file_contents(file) click to toggle source

Get connection information from a file.

# File lib/osc/vnc/connview.rb, line 85
def _get_file_contents(file)
  raise InvalidPath, "connection file doesn't exist" unless File.file?(file)
  _parse File.read(file)
end
_parse(string) click to toggle source

Parse out connection info from a string.

# File lib/osc/vnc/connview.rb, line 91
def _parse(string)
  context = Hash[string.scan(/^(.*): (.*)$/)]
  @conn_context = {}
  context.each do |key, value|
    @conn_context[key.downcase.to_sym] = value
  end
end