Class: PicsolveDockerBuilder::Helpers::SshConnection
- Inherits:
-
Object
- Object
- PicsolveDockerBuilder::Helpers::SshConnection
show all
- Includes:
- Base
- Defined in:
- lib/picsolve_docker_builder/helpers/ssh_connection.rb
Overview
Ruby class that can forward a remote port over SSH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Base
#base_dir, #config, #config_file, #config_path, #config_paths, #create_logger, #default_config, #log, #read_config, #validate_config
Constructor Details
Returns a new instance of SshConnection.
11
12
13
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 11
def initialize(opts)
@options = opts
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 10
def options
@options
end
|
Instance Method Details
#connection ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 15
def connection
@connection ||= Net::SSH.start(
ssh_host,
ssh_user,
port: ssh_port
)
end
|
#forward(*args) ⇒ Object
23
24
25
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 23
def forward(*args)
SshForward.forward(connection, *args)
end
|
#local_port ⇒ Object
63
64
65
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 63
def local_port
options[:local_port] || remote_port
end
|
#remote_host ⇒ Object
55
56
57
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 55
def remote_host
options[:remote_host]
end
|
#remote_port ⇒ Object
59
60
61
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 59
def remote_port
options[:remote_port]
end
|
#ssh_host ⇒ Object
47
48
49
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 47
def ssh_host
options[:ssh_host]
end
|
#ssh_port ⇒ Object
51
52
53
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 51
def ssh_port
options[:ssh_port] || 22
end
|
#ssh_user ⇒ Object
43
44
45
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 43
def ssh_user
options[:ssh_user] = 'core'
end
|
#start ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 27
def start
log.debug "Connecting via ssh to host '#{ssh_user}@#{ssh_host}'"
@thread = Thread.new do
connection.loop { true }
end
end
|
#stop ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/picsolve_docker_builder/helpers/ssh_connection.rb', line 35
def stop
return if @thread.nil?
@thread.kill
@thread.join
log.debug \
"Disconnected ssh connection to host '#{ssh_user}@#{ssh_host}'"
end
|