Module: Veewee::Provider::Core::ProviderCommand

Defined in:
lib/veewee/provider/core/provider/tunnel.rb

Instance Method Summary collapse

Instance Method Details

#ssh_tunnel_start(forwardings) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/veewee/provider/core/provider/tunnel.rb', line 9

def ssh_tunnel_start(forwardings)
  #ssh_options={ :keys => [ vm.private_key ], :paranoid => false, :keys_only => true}

  ssh_options={ :paranoid => false}
  host=@connection.uri.host
  user=@connection.uri.user

  ui.info "Enabling tunneling"
  @forward_threads=Array.new
  @forward_threads<< Thread.new {
    Net::SSH.start(host, user, ssh_options) do |ssh_session|
    forwardings.each do |forwarding|
      begin
        ui.info "Forwarding remote port #{forwarding[:remote_port]} from #{box_name} to local port #{forwarding[:local_port]}"
        ui.info host
        ui.info user
        ui.info ""
        ssh_session.forward.local(forwarding[:local_port], "127.0.0.1",forwarding[:remote_port])
      rescue Errno::EACCES
        ui.info "  Error - Access denied to forward remote port #{forwarding[:remote_port]} from #{name} to local port #{forwarding[:local_port]}"
      end
    end
    ssh_session.loop {true}
    end
  }
  ui.info @forward_threads.first.status
  @forward_threads.first.run
  ui.info @forward_threads.first.status

end

#ssh_tunnel_stopObject


40
41
42
# File 'lib/veewee/provider/core/provider/tunnel.rb', line 40

def ssh_tunnel_stop
  Thread.kill(@forward_threads.first)
end