Class: Dizby::AbstractTunnel
- Inherits:
-
Object
- Object
- Dizby::AbstractTunnel
- Defined in:
- lib/dizby/tunnel/abstract.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#local_port
readonly
Returns the value of attribute local_port.
-
#remote_port
readonly
Returns the value of attribute remote_port.
Instance Method Summary collapse
- #close
- #get_and_write_ports(ssh, output)
-
#initialize(server, strategy, user, host) ⇒ AbstractTunnel
constructor
A new instance of AbstractTunnel.
-
#open_ssh(output)
wait(ssh) is not defined in this class.
- #read_ports(input)
Constructor Details
#initialize(server, strategy, user, host) ⇒ AbstractTunnel
Returns a new instance of AbstractTunnel.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dizby/tunnel/abstract.rb', line 12 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.
57 58 59 |
# File 'lib/dizby/tunnel/abstract.rb', line 57 def local_port @local_port end |
#remote_port (readonly)
Returns the value of attribute remote_port.
57 58 59 |
# File 'lib/dizby/tunnel/abstract.rb', line 57 def remote_port @remote_port end |
Instance Method Details
#close
53 54 55 |
# File 'lib/dizby/tunnel/abstract.rb', line 53 def close @thread.join end |
#get_and_write_ports(ssh, output)
49 50 51 |
# File 'lib/dizby/tunnel/abstract.rb', line 49 def get_and_write_ports(ssh, output) @strategy.write(ssh, output) end |
#open_ssh(output)
wait(ssh) is not defined in this class
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dizby/tunnel/abstract.rb', line 32 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)
45 46 47 |
# File 'lib/dizby/tunnel/abstract.rb', line 45 def read_ports(input) @local_port, @remote_port = @strategy.read(input) end |