Module: Bcome::Ssh::DriverConnection
- Included in:
- Driver
- Defined in:
- lib/objects/ssh/driver_concerns/connection.rb
Constant Summary collapse
- DEFAULT_TIMEOUT_IN_SECONDS =
1
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #close_ssh_connection ⇒ Object
- #has_open_ssh_con? ⇒ Boolean
- #net_ssh_params ⇒ Object
- #node_host_or_ip ⇒ Object
-
#proxy ⇒ Object
PROXYING –.
-
#ssh_connect! ⇒ Object
CONNECTION –.
- #ssh_connection(ping = false) ⇒ Object
- #timeout_in_seconds ⇒ Object
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/objects/ssh/driver_concerns/connection.rb', line 7 def connection @connection end |
Instance Method Details
#close_ssh_connection ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# 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? ⇒ Boolean
42 43 44 |
# File 'lib/objects/ssh/driver_concerns/connection.rb', line 42 def has_open_ssh_con? !@connection.nil? && !@connection.closed? end |
#net_ssh_params ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/objects/ssh/driver_concerns/connection.rb', line 51 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 ⇒ Object
46 47 48 49 |
# 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? has_proxy? ? @context_node.internal_ip_address : @context_node.public_ip_address end |
#proxy ⇒ Object
PROXYING –
66 67 68 |
# File 'lib/objects/ssh/driver_concerns/connection.rb', line 66 def proxy connection_wrangler.proxy end |
#ssh_connect! ⇒ Object
CONNECTION –
11 12 13 14 15 16 17 18 19 20 |
# 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.}" end @connection end |
#ssh_connection(ping = false) ⇒ Object
33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
60 61 62 |
# File 'lib/objects/ssh/driver_concerns/connection.rb', line 60 def timeout_in_seconds @config[:timeout_in_seconds] ||= DEFAULT_TIMEOUT_IN_SECONDS end |