Class: Train::Plugins::Transport::BaseConnection

Inherits:
Object
  • Object
show all
Includes:
Extras
Defined in:
lib/train/plugins/base_connection.rb

Overview

A Connection instance can be generated and re-generated, given new connection details such as connection port, hostname, credentials, etc. This object is responsible for carrying out the actions on the remote host such as executing commands, transferring files, etc.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) {|self| ... } ⇒ BaseConnection

Create a new Connection instance.

Parameters:

  • options (Hash) (defaults to: nil)

    connection options

Yields:

  • (self)

    yields itself for block-style invocation



25
26
27
28
# File 'lib/train/plugins/base_connection.rb', line 25

def initialize(options = nil)
  @options = options || {}
  @logger = @options.delete(:logger) || Logger.new(STDOUT)
end

Instance Method Details

#closeObject

Closes the session connection, if it is still active.



31
32
33
# File 'lib/train/plugins/base_connection.rb', line 31

def close
  # this method may be left unimplemented if that is applicable
end

#file(_path, *_args) ⇒ FileCommon

Interact with files on the target. Read, write, and get metadata from files via the transport.

Parameters:

  • path (String)

    which is being inspected

Returns:

  • (FileCommon)

    file object that allows for interaction



55
56
57
# File 'lib/train/plugins/base_connection.rb', line 55

def file(_path, *_args)
  fail Train::ClientError, "#{self.class} does not implement #file(...)"
end

#login_commandLoginCommand

Builds a LoginCommand which can be used to open an interactive session on the remote host.

Returns:



63
64
65
# File 'lib/train/plugins/base_connection.rb', line 63

def 
  fail Train::ClientError, "#{self.class} does not implement #run_command()"
end

#osOSCommon

Get information on the operating system which this transport connects to.

Returns:

  • (OSCommon)

    operating system information



46
47
48
# File 'lib/train/plugins/base_connection.rb', line 46

def os
  fail Train::ClientError, "#{self.class} does not implement #os()"
end

#run_command(_command) ⇒ CommandResult

Execute a command using this connection.

Parameters:

  • command (String)

    command string to execute

Returns:



39
40
41
# File 'lib/train/plugins/base_connection.rb', line 39

def run_command(_command)
  fail Train::ClientError, "#{self.class} does not implement #run_command()"
end

#wait_until_readyObject

Block and return only when the remote host is prepared and ready to execute command and upload files. The semantics and details will vary by implementation, but a round trip through the hosted service is preferred to simply waiting on a socket to become available.



72
73
74
# File 'lib/train/plugins/base_connection.rb', line 72

def wait_until_ready
  # this method may be left unimplemented if that is applicablelog
end