Very nice! Thanks for sharing this.

- Jamis

On May 3, 2007, at 6:00 PM, [EMAIL PROTECTED] wrote:

>
> In my networks, I need to login to a gateway server through two other
> servers.
>
> [my pc] -- [hostA] -- [hostB] -- [gateway] -- [target servers]
>
> so, I extend gateway.rb and make gateways.rb
> the way to use,
>
> gateway = Capistrano::Gateways.new(["hostA", "hostB", "gateway"],
> config).gateway
>
> you can reffer to the article below, too.
> http://weblog.jamisbuck.org/2006/9/26/inside-capistrano-the-gateway- 
> implementation.
>
> ## gateways.rb
> require 'capistrano/gateway'
>
> module Capistrano
>   class Gateways
>     MAX_PORT = 65535
>     MIN_PORT = 1024
>     def initialize(servers, options={})
>       @gateways = []
>       @next_port = MAX_PORT
>       @port_guard = Mutex.new
>       servers.to_a.flatten!
>       first, others = servers.first, servers[1..-1]
>       @gateways << Capistrano::Gateway.new(first, options)
>       others.to_a.flatten.each do |server|
>         local_port = next_port
>         @gateways.last.session.forward.local(local_port, server, 22)
>         addr = "127.0.0.1:#{local_port}"
>         @gateways << Capistrano::Gateway.new(addr, options)
>       end
>     end
>
>     def gateway
>       @gateways.last
>     end
>
>     private
>
>       def next_port
>         @port_guard.synchronize do
>           port = @next_port
>           @next_port -= 1
>           @next_port = MAX_PORT if @next_port < MIN_PORT
>           port
>         end
>       end
>   end
> end
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to