Class: ConnectivityHelper
- Inherits:
-
Object
- Object
- ConnectivityHelper
- Defined in:
- lib/knife-clc/bootstrap/connectivity_helper.rb
Instance Method Summary collapse
Instance Method Details
#test_ssh_tunnel(params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/knife-clc/bootstrap/connectivity_helper.rb', line 22 def test_ssh_tunnel(params) host = params.fetch(:host) port = params.fetch(:port) gateway = params.fetch(:gateway) gateway_user, gateway_host = gateway.split('@') gateway_host, gateway_port = gateway_host.split(':') gateway = Net::SSH::Gateway.new(gateway_host, gateway_user, :port => gateway_port || 22) status = false gateway.open(host, port) do |local_tunnel_port| status = test_tcp(:host => 'localhost', :port => local_tunnel_port) end status rescue SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError, Errno::EPERM, Errno::ETIMEDOUT false end |
#test_tcp(params) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/knife-clc/bootstrap/connectivity_helper.rb', line 5 def test_tcp(params) host = params.fetch(:host) port = params.fetch(:port) socket = TCPSocket.new(host, port) if readable = IO.select([socket], [socket], nil, 5) yield if block_given? true else false end rescue SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH, IOError, Errno::EPERM, Errno::ETIMEDOUT false ensure socket && socket.close end |