module Bcome::Ssh::DriverConnection

Constants

DEFAULT_TIMEOUT_IN_SECONDS

Attributes

connection[R]

Public Instance Methods

close_ssh_connection() click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 22
def close_ssh_connection
  return unless @connection

  begin
    @connection.close unless @connection.closed?
    @connection = nil
  rescue Net::SCP::Error
    @connection = nil
  end
end
has_open_ssh_con?() click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 42
def has_open_ssh_con?
  !@connection.nil? && !@connection.closed?
end
net_ssh_params() click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 56
def net_ssh_params
  params = { paranoid: false }
  params[:proxy] = proxy if has_proxy?
  params[:timeout] = timeout_in_seconds
  params[:verbose] = :fatal # All but silent

  params
end
node_host_or_ip() click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 46
def node_host_or_ip
  return @context_node.internal_ip_address if @context_node.local_network?

  if has_proxy? || !@context_node.public_ip_address
    @context_node.internal_ip_address
  else
    @context_node.public_ip_address
  end 
end
proxy() click to toggle source

PROXYING –

# File lib/objects/ssh/driver_concerns/connection.rb, line 71
def proxy
  connection_wrangler.proxy
end
ssh_connect!() click to toggle source

CONNECTION –

# File lib/objects/ssh/driver_concerns/connection.rb, line 11
def ssh_connect!
  @connection = nil
  begin
    raise ::Bcome::Exception::InvalidProxyConfig, "missing target ip address for #{@context_node.identifier}. Perhaps you meant to configure a proxy?" unless node_host_or_ip
    @connection = ::Net::SSH.start(node_host_or_ip, user, net_ssh_params)
  rescue Net::SSH::AuthenticationFailed, Net::SSH::Proxy::ConnectError, Net::SSH::ConnectionTimeout => e
    raise Bcome::Exception::CouldNotInitiateSshConnection, @context_node.namespace + "\s-\s#{e.message}"
  end
  @connection
end
ssh_connection(ping = false) click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 33
def ssh_connection(ping = false)
  if ping
    # We do not cache ping results
    ssh_connect!
  else
    has_open_ssh_con? ? @connection : ssh_connect!
  end
end
timeout_in_seconds() click to toggle source
# File lib/objects/ssh/driver_concerns/connection.rb, line 65
def timeout_in_seconds
  @config[:timeout_in_seconds] ||= DEFAULT_TIMEOUT_IN_SECONDS
end