Class: Kitchen::Transport::Base::Connection

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/transport/base.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

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Constructor Details

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

Create a new Connection instance.

Parameters:

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

    connection options

Yields:

  • (self)

    yields itself for block-style invocation



75
76
77
78
79
80
81
# File 'lib/kitchen/transport/base.rb', line 75

def initialize(options = {})
  init_options(options)

  if block_given?
    yield self
  end
end

Instance Method Details

#closeObject

Closes the session connection, if it is still active.



84
85
86
# File 'lib/kitchen/transport/base.rb', line 84

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

#execute(command) ⇒ Object

Execute a command on the remote host.

Parameters:

  • command (String)

    command string to execute

Raises:

  • (TransportFailed)

    if the command does not exit successfully, which may vary by implementation



93
94
95
# File 'lib/kitchen/transport/base.rb', line 93

def execute(command) # rubocop:disable Lint/UnusedMethodArgument
  raise ClientError, "#{self.class}#execute must be implemented"
end

#login_commandLoginCommand

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

Returns:

  • (LoginCommand)

    an object containing the array of command line tokens and exec options to be used in a fork/exec

Raises:



103
104
105
# File 'lib/kitchen/transport/base.rb', line 103

def 
  raise ActionFailed, "Remote login not supported in #{self.class}."
end

#upload(locals, remote) ⇒ Object

Uploads local files or directories to remote host.

Parameters:

  • locals (Array<String>)

    paths to local files or directories

  • remote (String)

    path to remote destination

Raises:

  • (TransportFailed)

    if the files could not all be uploaded successfully, which may vary by implementation



113
114
115
# File 'lib/kitchen/transport/base.rb', line 113

def upload(locals, remote) # rubocop:disable Lint/UnusedMethodArgument
  raise ClientError, "#{self.class}#upload must be implemented"
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.



122
123
124
# File 'lib/kitchen/transport/base.rb', line 122

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