module Remotus

Contains classes and methods for creating remote connections and running commands

Constants

VERSION

Remotus gem version

Public Class Methods

clear() click to toggle source

Removes all host pools from the pool in a thread-safe manner

@return [Integer] number of host pools removed

# File lib/remotus.rb, line 42
def self.clear
  Remotus::Pool.clear
end
connect(host, **options) click to toggle source

Creates/gets a host pool for the host that can be used to perform remote operations. After creation, the host pool will persist for future connections.

@param [String] host hostname @param [Hash] options options hash @option options [Integer] :size number of connections in the pool @option options [Integer] :timeout amount of time to wait for a connection from the pool @option options [Integer] :port port to use for the connection @option options [Symbol] :proto protocol to use for the connection (:winrm, :ssh), must be specified if port is specified

@return [Remotus::HostPool] Newly created or retrieved host pool

# File lib/remotus.rb, line 24
def self.connect(host, **options)
  Remotus::Pool.connect(host, **options)
end
count() click to toggle source

Number of host pools in the connection pool

@return [Integer] number of host pools

# File lib/remotus.rb, line 33
def self.count
  Remotus::Pool.count
end
host_type(host, timeout: 1) click to toggle source

Determine remote host type by checking common ports

@param [String] host hostname @param [Integer] timeout amount of time to wait in seconds

@return [Symbol, nil] :ssh, :winrm, or nil if it cannot be determined

# File lib/remotus.rb, line 71
def self.host_type(host, timeout: 1)
  return :ssh if port_open?(host, SshConnection::REMOTE_PORT, timeout: timeout)

  return :winrm if port_open?(host, WinrmConnection::REMOTE_PORT, timeout: timeout)

  nil
end
log_formatter() click to toggle source

Gets the remotus log formatter

@return [::Logger::Formatter] current log formatter

# File lib/remotus.rb, line 106
def self.log_formatter
  @log_formatter ||= logger.formatter
end
log_formatter=(log_formatter) click to toggle source

Sets the remotus log formatter

@param [::Logger::Formatter] log_formatter new log formatter

# File lib/remotus.rb, line 115
def self.log_formatter=(log_formatter)
  @log_formatter = log_formatter
  logger.formatter = log_formatter
end
logger() click to toggle source

Gets the remotus logger

@return [Remotus::Logger] current logger

# File lib/remotus.rb, line 84
def self.logger
  @logger ||= Remotus::Logger.new($stdout, level: Logger::INFO)
end
logger=(logger) click to toggle source

Sets the remotus logger

@param [::Logger] logger logger to set

# File lib/remotus.rb, line 93
def self.logger=(logger)
  if logger.nil?
    self.logger.level = Logger::FATAL
    return self.logger
  end
  @logger = logger
end
port_open?(host, port, timeout: 1) click to toggle source

Checks if a remote port is open

@param [String] host remote host @param [Integer] port remote port @param [Integer] timeout amount of time to wait in seconds

@return [Boolean] true if port is open, false otherwise

# File lib/remotus.rb, line 55
def self.port_open?(host, port, timeout: 1)
  logger.debug { "Checking if #{host}:#{port} is accessible" }
  Socket.tcp(host, port, connect_timeout: timeout) { true }
rescue StandardError
  logger.debug { "#{host}:#{port} is inaccessible" }
  false
end