Class: PicsolveDockerBuilder::Helpers::SshForward
- Inherits:
-
Object
- Object
- PicsolveDockerBuilder::Helpers::SshForward
- Includes:
- Base
- Defined in:
- lib/picsolve_docker_builder/helpers/ssh_forward.rb
Overview
Ruby class that can forward a remote port over SSH
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#local_port ⇒ Object
readonly
Returns the value of attribute local_port.
Class Method Summary collapse
Instance Method Summary collapse
- #bind_port ⇒ Object
-
#initialize(connection, remote_host, remote_port, local_port = nil) ⇒ SshForward
constructor
A new instance of SshForward.
Methods included from Base
#base_dir, #config, #config_file, #config_path, #config_paths, #create_logger, #default_config, #log, #read_config, #validate_config
Constructor Details
#initialize(connection, remote_host, remote_port, local_port = nil) ⇒ SshForward
Returns a new instance of SshForward.
16 17 18 19 20 21 |
# File 'lib/picsolve_docker_builder/helpers/ssh_forward.rb', line 16 def initialize(connection, remote_host, remote_port, local_port = nil) @connection = connection @remote_host = remote_host @remote_port = remote_port @local_port = local_port || remote_port end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
15 16 17 |
# File 'lib/picsolve_docker_builder/helpers/ssh_forward.rb', line 15 def connection @connection end |
#local_port ⇒ Object (readonly)
Returns the value of attribute local_port.
15 16 17 |
# File 'lib/picsolve_docker_builder/helpers/ssh_forward.rb', line 15 def local_port @local_port end |
Class Method Details
.forward(*args) ⇒ Object
8 9 10 11 12 |
# File 'lib/picsolve_docker_builder/helpers/ssh_forward.rb', line 8 def self.forward(*args) f = new(*args) f.bind_port f end |
Instance Method Details
#bind_port ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/picsolve_docker_builder/helpers/ssh_forward.rb', line 23 def bind_port tries = 0 begin connection.forward.local(@local_port, @remote_host, @remote_port) log.info "forward remote port #{@remote_host}:#{@remote_port}" \ " to local port #{@local_port}" return @local_port rescue Errno::EADDRINUSE => e # raise after five failed tries raise e if tries > 5 tries += 1 @local_port += 1 retry end end |