Class: Tunneler::SshTunnel::Gateway

Inherits:
Net::SSH::Gateway
  • Object
show all
Defined in:
lib/tunneler/ssh_tunnel.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, user, options = {}) ⇒ Gateway

Returns a new instance of Gateway.



28
29
30
31
32
33
# File 'lib/tunneler/ssh_tunnel.rb', line 28

def initialize(host, user, options={})
  super
  @host = host
  @user = user
  @options = options
end

Class Method Details

.connect(host, user, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/tunneler/ssh_tunnel.rb', line 35

def self.connect(host, user, options={})
  gateway = self.new(host, user, options)
  gateway.open("127.0.0.1", self.random_open_port)
  gateway
end

.random_open_portObject



41
42
43
44
45
# File 'lib/tunneler/ssh_tunnel.rb', line 41

def self.random_open_port
  socket = Socket.new(:INET, :STREAM, 0)
  socket.bind(Addrinfo.tcp("127.0.0.1", 0))
  socket.local_address.ip_port
end

Instance Method Details

#reconnectObject



47
48
49
50
# File 'lib/tunneler/ssh_tunnel.rb', line 47

def reconnect
  shutdown!
  self.class.connect(@host,@user,@options)
end