Class: Train::Plugins::Transport::BaseConnection
- Inherits:
-
Object
- Object
- Train::Plugins::Transport::BaseConnection
- 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.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Provide access to the files cache.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the session connection, if it is still active.
-
#file(_path, *_args) ⇒ FileCommon
Interact with files on the target.
-
#initialize(options = nil) {|self| ... } ⇒ BaseConnection
constructor
Create a new Connection instance.
- #load_json(j) ⇒ Object
-
#login_command ⇒ LoginCommand
Builds a LoginCommand which can be used to open an interactive session on the remote host.
-
#os ⇒ OSCommon
Get information on the operating system which this transport connects to.
-
#run_command(_command) ⇒ CommandResult
Execute a command using this connection.
- #to_json ⇒ Object
-
#wait_until_ready ⇒ Object
Block and return only when the remote host is prepared and ready to execute command and upload files.
Constructor Details
#initialize(options = nil) {|self| ... } ⇒ BaseConnection
Create a new Connection instance.
29 30 31 32 33 |
# File 'lib/train/plugins/base_connection.rb', line 29 def initialize( = nil) = || {} @logger = .delete(:logger) || Logger.new(STDOUT) @files = {} end |
Instance Attribute Details
#files ⇒ Object (readonly)
Provide access to the files cache.
23 24 25 |
# File 'lib/train/plugins/base_connection.rb', line 23 def files @files end |
Instance Method Details
#close ⇒ Object
Closes the session connection, if it is still active.
36 37 38 |
# File 'lib/train/plugins/base_connection.rb', line 36 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.
73 74 75 |
# File 'lib/train/plugins/base_connection.rb', line 73 def file(_path, *_args) fail Train::ClientError, "#{self.class} does not implement #file(...)" end |
#load_json(j) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/train/plugins/base_connection.rb', line 46 def load_json(j) require 'train/transports/mock' j['files'].each do |path, jf| @files[path] = Train::Transports::Mock::Connection::File.from_json(jf) end end |
#login_command ⇒ LoginCommand
Builds a LoginCommand which can be used to open an interactive session on the remote host.
81 82 83 |
# File 'lib/train/plugins/base_connection.rb', line 81 def login_command fail Train::ClientError, "#{self.class} does not implement #login_command()" end |
#os ⇒ OSCommon
Get information on the operating system which this transport connects to.
64 65 66 |
# File 'lib/train/plugins/base_connection.rb', line 64 def os fail Train::ClientError, "#{self.class} does not implement #os()" end |
#run_command(_command) ⇒ CommandResult
Execute a command using this connection.
57 58 59 |
# File 'lib/train/plugins/base_connection.rb', line 57 def run_command(_command) fail Train::ClientError, "#{self.class} does not implement #run_command()" end |
#to_json ⇒ Object
40 41 42 43 44 |
# File 'lib/train/plugins/base_connection.rb', line 40 def to_json { 'files' => Hash[@files.map { |x, y| [x, y.to_json] }], } end |
#wait_until_ready ⇒ Object
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.
90 91 92 |
# File 'lib/train/plugins/base_connection.rb', line 90 def wait_until_ready # this method may be left unimplemented if that is applicablelog end |