Sha256: e032bb4f168e5b91e967a9806453528695e3d8598b77a3398b38c7d33cf69267

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 KB

Contents

require 'net/ssh/multi'
require 'pp'
module Mccloud
  module Command
    def server(selection=nil,options=nil)
      
      puts "Starting server mode"
      trap("INT") { puts "You've hit CTRL-C . Stopping server now"; exit }
      threads = []
      on_selected_machines(selection) do |id,vm|
        threads << Thread.new(id,vm) do |id,vm|
          public_ip_address=vm.instance.public_ip_address
          private_ip_address=vm.instance.private_ip_address
          unless public_ip_address.nil? || private_ip_address.nil?
            ssh_options={ :keys => [ vm.private_key ], :paranoid => false, :keys_only => true}
            Net::SSH.start(public_ip_address, vm.user, ssh_options) do |ssh|
              vm.forwardings.each do |forwarding|
                begin
                  puts "Forwarding remote port #{forwarding.remote} from #{vm.name} to local port #{forwarding.local}"
                  ssh.forward.local(forwarding.local, private_ip_address,forwarding.remote)
                rescue Errno::EACCES
                  puts "  Error - Access denied to forward remote port #{forwarding.remote} from #{vm.name} to local port #{forwarding.local}"
                end
              end
              ssh.loop { true }
            end
          end
        end
      end
      threads.each {|thr| thr.join}
      #puts "and we continue here"
      #sleep 30
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mccloud-0.0.13 lib/mccloud/command/server.rb
mccloud-0.0.12 lib/mccloud/command/server.rb
mccloud-0.0.11 lib/mccloud/command/server.rb
mccloud-0.0.10 lib/mccloud/command/server.rb
mccloud-0.0.9 lib/mccloud/command/server.rb
mccloud-0.0.8 lib/mccloud/command/server.rb
mccloud-0.0.7 lib/mccloud/command/server.rb
mccloud-0.0.6 lib/mccloud/command/server.rb
mccloud-0.0.5 lib/mccloud/command/server.rb
mccloud-0.0.4 lib/mccloud/command/server.rb
mccloud-0.0.3 lib/mccloud/command/server.rb