Class: VagrantPlugins::AVF::SshForwarder
- Inherits:
-
Object
- Object
- VagrantPlugins::AVF::SshForwarder
- Defined in:
- lib/vagrant_provider_avf/ssh_forwarder.rb
Constant Summary collapse
- START_TIMEOUT_SECONDS =
2- POLL_INTERVAL_SECONDS =
0.05
Instance Method Summary collapse
- #alive?(process_id) ⇒ Boolean
- #cleanup_files ⇒ Object
-
#initialize(machine_data_dir:, process_control: ProcessControl.new, ruby_path: RbConfig.ruby) ⇒ SshForwarder
constructor
A new instance of SshForwarder.
- #start(listen_port:, target_host:, target_port:) ⇒ Object
- #stop(process_id) ⇒ Object
Constructor Details
#initialize(machine_data_dir:, process_control: ProcessControl.new, ruby_path: RbConfig.ruby) ⇒ SshForwarder
Returns a new instance of SshForwarder.
11 12 13 14 15 |
# File 'lib/vagrant_provider_avf/ssh_forwarder.rb', line 11 def initialize(machine_data_dir:, process_control: ProcessControl.new, ruby_path: RbConfig.ruby) @machine_data_dir = Pathname.new(machine_data_dir) @process_control = process_control @ruby_path = ruby_path end |
Instance Method Details
#alive?(process_id) ⇒ Boolean
35 36 37 |
# File 'lib/vagrant_provider_avf/ssh_forwarder.rb', line 35 def alive?(process_id) process_id && @process_control.alive?(process_id) end |
#cleanup_files ⇒ Object
45 46 47 48 49 |
# File 'lib/vagrant_provider_avf/ssh_forwarder.rb', line 45 def cleanup_files [request_path, ready_path, error_path, log_path].each do |path| path.delete if path.exist? end end |
#start(listen_port:, target_host:, target_port:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant_provider_avf/ssh_forwarder.rb', line 17 def start(listen_port:, target_host:, target_port:) cleanup_files write_request(listen_port, target_host, target_port) process_id = @process_control.spawn( [@ruby_path, runner_path.to_s, request_path.to_s], out: log_path.to_s, err: log_path.to_s ) wait_for_start(process_id) process_id rescue Errors::SshForwarderStartFailed raise rescue StandardError => error raise Errors::SshForwarderStartFailed, error. end |
#stop(process_id) ⇒ Object
39 40 41 42 43 |
# File 'lib/vagrant_provider_avf/ssh_forwarder.rb', line 39 def stop(process_id) return unless process_id @process_control.stop(process_id, timeout: START_TIMEOUT_SECONDS) end |