Class: OSC::VNC::ConnView

Inherits:
Mustache
  • Object
show all
Defined in:
lib/osc/vnc/connview.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, connfile, opts = {}) ⇒ ConnView

Returns a new instance of ConnView.

Parameters:

  • script (ScriptView)

    The script object with information about the job setup..

  • connfile (#to_s)

    The connection file with the connection information.

  • opts (Hash) (defaults to: {})

    The options used to construct a connection information view.



20
21
22
23
24
# File 'lib/osc/vnc/connview.rb', line 20

def initialize(script, connfile, opts = {})
  @script = script
  @connfile = Pathname.new(connfile.to_s)
  refresh
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object

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

Parameters:

  • method_name

    the method name called

  • arguments

    the arguments to the call

  • block

    an optional block for the call



62
63
64
65
66
67
68
69
70
# 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

Instance Attribute Details

#connfilePathname (readonly)

Returns The path to the connection file.

Returns:

  • (Pathname)

    The path to the connection file.



15
16
17
# File 'lib/osc/vnc/connview.rb', line 15

def connfile
  @connfile
end

#scriptScriptView (readonly)

Returns The script object with information about the job setup.

Returns:

  • (ScriptView)

    The script object with information about the job setup.



12
13
14
# File 'lib/osc/vnc/connview.rb', line 12

def script
  @script
end

Instance Method Details

#refreshConnView

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

Returns:

  • (ConnView)

    the connection view object

Raises:

  • (InvalidPath)

    if connection file does not exist

  • (InvalidConnInfo)

    if connection file doesn’t contain required information (i.e.: host, port, display, password)



52
53
54
55
# File 'lib/osc/vnc/connview.rb', line 52

def refresh
  _get_file_contents(connfile.to_s)
  self
end

#render(format, context = {}) ⇒ String

Generates a string from a template depending on the format name, current options include (:jnlp, :awesim, :terminal, :txt, :vnc, :yaml) (see templates/conn/*.mustache).

Parameters:

  • format (Symbol)

    the format the connection info will be displayed in

  • context (Hash) (defaults to: {})

    the context to be applied to mustache template

Returns:

  • (String)

    the mustache generated view of the template



# File 'lib/osc/vnc/connview.rb', line 26

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

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

Parameters:

  • method_name

    the method name to check

Returns:

  • (Boolean)


77
78
79
# 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

#sshhostString

The host to use for the ssh connection.

Returns:

  • (String)

    the hostname for the login node



42
43
44
# File 'lib/osc/vnc/connview.rb', line 42

def sshhost
  "#{script.cluster}.osc.edu"
end

#sshuserString

The user to use for the ssh connection.

Returns:

  • (String)

    the current user



36
37
38
# File 'lib/osc/vnc/connview.rb', line 36

def sshuser
  ENV['USER']
end