Class: Dizby::AbstractTunnel

Inherits:
Object
  • Object
show all
Defined in:
lib/dizby/tunnel/abstract.rb

Direct Known Subclasses

BasicSpawnTunnel, BasicTunnel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, strategy, user, host) ⇒ AbstractTunnel

Returns a new instance of AbstractTunnel.


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dizby/tunnel/abstract.rb', line 6

def initialize(server, strategy, user, host)
  @server = server
  @config = [user, host, @server.config[:ssh_config]]
  @strategy = strategy

  reader, writer = IO.pipe

  @thread = Thread.start do
    open_ssh(writer)
    writer.close
  end

  @thread.abort_on_exception = true

  read_ports(reader)
  reader.close
end

Instance Attribute Details

#local_port (readonly)

Returns the value of attribute local_port


50
51
52
# File 'lib/dizby/tunnel/abstract.rb', line 50

def local_port
  @local_port
end

#remote_port (readonly)

Returns the value of attribute remote_port


50
51
52
# File 'lib/dizby/tunnel/abstract.rb', line 50

def remote_port
  @remote_port
end

Instance Method Details

#close


46
47
48
# File 'lib/dizby/tunnel/abstract.rb', line 46

def close
  @thread.join
end

#get_and_write_ports(ssh, output)


42
43
44
# File 'lib/dizby/tunnel/abstract.rb', line 42

def get_and_write_ports(ssh, output)
  @strategy.write(ssh, output)
end

#open_ssh(output)

wait(ssh) is not defined in this class


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dizby/tunnel/abstract.rb', line 25

def open_ssh(output)
  ssh = nil
  begin
    ssh = Net::SSH.start(*@config)

    get_and_write_ports(ssh, output)

    wait(ssh)
  ensure
    ssh.close if ssh
  end
end

#read_ports(input)


38
39
40
# File 'lib/dizby/tunnel/abstract.rb', line 38

def read_ports(input)
  @local_port, @remote_port = @strategy.read(input)
end