class Train::Plugins::Transport::BaseConnection
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 Fletcher Nichol <fnichol@nichol.ca>
Attributes
@return [Logger] logger for reporting information @api private
@return [Hash] connection options @api private
Public Class Methods
Create a new Connection instance.
@param options [Hash] connection options @yield [self] yields itself for block-style invocation
# File lib/train/plugins/base_connection.rb, line 25 def initialize(options = nil) @options = options || {} @logger = @options.delete(:logger) || Logger.new(STDOUT) end
Public Instance Methods
Closes the session connection, if it is still active.
# File lib/train/plugins/base_connection.rb, line 31 def close # this method may be left unimplemented if that is applicable end
Interact with files on the target. Read, write, and get metadata from files via the transport.
@param [String] path which is being inspected @return [FileCommon] file object that allows for interaction
# File lib/train/plugins/base_connection.rb, line 55 def file(_path, *_args) fail Train::ClientError, "#{self.class} does not implement #file(...)" end
Builds a LoginCommand which can be used to open an interactive session on the remote host.
@return [LoginCommand] array of command line tokens
# File lib/train/plugins/base_connection.rb, line 63 def login_command fail Train::ClientError, "#{self.class} does not implement #run_command()" end
Get information on the operating system which this transport connects to.
@return [OSCommon] operating system information
# File lib/train/plugins/base_connection.rb, line 46 def os fail Train::ClientError, "#{self.class} does not implement #os()" end
Execute a command using this connection.
@param command [String] command string to execute @return [CommandResult] contains the result of running the command
# File lib/train/plugins/base_connection.rb, line 39 def run_command(_command) fail Train::ClientError, "#{self.class} does not implement #run_command()" end
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.
# File lib/train/plugins/base_connection.rb, line 72 def wait_until_ready # this method may be left unimplemented if that is applicablelog end