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.
28 29 30 31 32 |
# File 'lib/train/plugins/base_connection.rb', line 28 def initialize( = nil) @options = || {} @logger = @options.delete(:logger) || Logger.new(STDOUT) @files = {} end |
Instance Attribute Details
#files ⇒ Object (readonly)
Provide access to the files cache.
22 23 24 |
# File 'lib/train/plugins/base_connection.rb', line 22 def files @files end |
Instance Method Details
#close ⇒ Object
Closes the session connection, if it is still active.
35 36 37 |
# File 'lib/train/plugins/base_connection.rb', line 35 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.
72 73 74 |
# File 'lib/train/plugins/base_connection.rb', line 72 def file(_path, *_args) fail Train::ClientError, "#{self.class} does not implement #file(...)" end |
#load_json(j) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/train/plugins/base_connection.rb', line 45 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.
80 81 82 |
# File 'lib/train/plugins/base_connection.rb', line 80 def login_command fail Train::ClientError, "#{self.class} does not implement #run_command()" end |
#os ⇒ OSCommon
Get information on the operating system which this transport connects to.
63 64 65 |
# File 'lib/train/plugins/base_connection.rb', line 63 def os fail Train::ClientError, "#{self.class} does not implement #os()" end |
#run_command(_command) ⇒ CommandResult
Execute a command using this connection.
56 57 58 |
# File 'lib/train/plugins/base_connection.rb', line 56 def run_command(_command) fail Train::ClientError, "#{self.class} does not implement #run_command()" end |
#to_json ⇒ Object
39 40 41 42 43 |
# File 'lib/train/plugins/base_connection.rb', line 39 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.
89 90 91 |
# File 'lib/train/plugins/base_connection.rb', line 89 def wait_until_ready # this method may be left unimplemented if that is applicablelog end |