Class: Dizby::BasicSpawnTunnel
Instance Attribute Summary
#local_port, #remote_port
Instance Method Summary
collapse
#close, #open_ssh, #read_ports
Constructor Details
#initialize(server, strategy, command, user, host) ⇒ BasicSpawnTunnel
Returns a new instance of BasicSpawnTunnel.
13
14
15
16
17
|
# File 'lib/dizby/tunnel/basic_spawn.rb', line 13
def initialize(server, strategy, command, user, host)
@command = command
super(server, strategy, user, host)
end
|
Instance Method Details
#get_and_write_ports(ssh, output)
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dizby/tunnel/basic_spawn.rb', line 19
def get_and_write_ports(ssh, output)
@command.set_dynamic_mode unless @tunnel.server_port
@channel =
ssh.open_channel do |ch|
ch.exec @command.to_cmd do |_, success|
fail SpawnError, 'could not spawn host' unless success
get_remote_server_port(ch) if @command.dynamic?
end
end
ssh.loop { !@channel[:triggered] } if @command.dynamic?
@channel.eof!
super
end
|
#get_remote_server_port(ch)
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/dizby/tunnel/basic_spawn.rb', line 38
def get_remote_server_port(ch)
ch[:data] = ''
ch[:triggered] = false
ch.on_data { |_, data| ch[:data] << data }
ch.on_extended_data { |_, _, data| @server.log(data.inspect) }
ch.on_process do |_|
if !ch[:triggered] && ch[:data] =~ /Running on port (\d+)\./
@strategy.instance_variable_set(:@server_port, $~[1])
ch[:triggered] = true
end
end
end
|
#wait(ssh)
53
54
55
|
# File 'lib/dizby/tunnel/basic_spawn.rb', line 53
def wait(ssh)
ssh.loop { @channel.active? }
end
|