my idea is

* add new variable in the configuration
 set :gateway {..}
 set :default_connect_direct, true  # new variable

* modify connect_to() method in GatewayConnectionFactory class

  def connet_to(server)
+   if fetch(:default_connect_direct, false) && !@gateways[server.host]
+     SSH.connect(server, @options)
+   else
       # original
+   end
  end


I expect that the client connects to server directly if
:default_connect_direct is true and a gateway for a server is not
defined explicitly.
but it didn't work yet... returned err

NoMethodError: undefined method `fetch' ...


On Fri, Dec 9, 2011 at 1:20 AM, Nobuhiro Nikushi <[email protected]> wrote:
> Hi, Rafa.
>
> The pull request for multiple gateways support was already merged to
> master tree. Try latest 2.x version. also can see the code in
>
> https://github.com/capistrano/capistrano/blob/master/lib/capistrano/configuration/connections.rb
>
> It seems original GatewayConnectionFactory instance only create
> tunneled connection. following part in connections.rb sets default
> gateway server implicitly.
>
> ==
> class GatewayConnectionFactory
>  def initialize(gateway, options)
>      # snip ..
>    @gateways = {}
>    if gateway.is_a?(Hash)
>      # snip ..
>      gateway.each do |gw, hosts|
>        gateway_connection = add_gateway(gw)
>        [*hosts].each do |host|
>        @gateways[:default] ||= gateway_connection
>        @gateways[host] = gateway_connection
>      end
>    end
> ==
>
> Dose anyone have good solution?
>
> On Thu, Dec 8, 2011 at 3:21 AM, Rafa García <[email protected]> wrote:
>> I've never done it but there's a pull request relatid with your problem:
>>
>> https://github.com/capistrano/capistrano/pull/18
>>
>> So I think it should works :)
>>
>>
>> 2011/12/6 Donovan Bray <[email protected]>
>>>
>>> You know now that I look at my code and scripts i think it just appears to
>>> work for me, because even though I specify different gateways both sets of
>>> servers are reachable by either gateway. I had assumed that the gateway was
>>> part of the server definition.  So ignore what I said.
>>>
>>>
>>> On Dec 6, 2011, at 3:25 AM, Nobuhiro Nikushi <[email protected]> wrote:
>>>
>>> > The recipe you suggested did not work. Client still login to the
>>> > server a and b via gate1.
>>> >
>>> > $ cap prod deploy:check              #  multistage gem extention is
>>> > installed
>>> >  * 20:04:11 == Currently executing `prod'
>>> >    triggering start callbacks for `deploy:check'
>>> >  * 20:04:11 == Currently executing `multistage:ensure'
>>> >  * 20:04:11 == Currently executing `deploy:check'
>>> >    servers: ["a", "b", "c", "d"]
>>> >  * establishing connection to gateway `"gate1"'
>>> >  * Creating gateway using gate1
>>> >  * establishing connection to `a' via gateway    # <-- still connect
>>> > to gateway.....
>>> >  * establishing connection to `b' via gateway    # <-- still connect
>>> > to gateway....
>>> >  * establishing connection to `c' via gateway
>>> >  * establishing connection to `d' via gateway
>>> >
>>> > --Nobuhiro Nikushi
>>> >
>>> > On Tue, Dec 6, 2011 at 2:48 PM, Donovan Bray <[email protected]> wrote:
>>> >> server "a", :app
>>> >> server "b", :app
>>> >>
>>> >> set :gateway, 'gate1'
>>> >>
>>> >> server "c", :app
>>> >> server "d", :app
>>> >>
>>> >> Will do what you want, the first two wont have a gateway, but the
>>> >> latter two will and they'll all be in the app role
>>> >>
>>> >> On Dec 5, 2011, at 9:45 AM, Nobuhiro Nikushi <[email protected]>
>>> >> wrote:
>>> >>
>>> >>> Hi all. I'm trying my Capfile to choise whether or not to use gateway
>>> >>> server depend on servers or roles.
>>> >>>
>>> >>> my enviroment:
>>> >>> client ----------------> server_a
>>> >>>         ----------------> server_b
>>> >>>         --> gate1  --> server_c
>>> >>>         --> gate1  --> server_d
>>> >>>
>>> >>> I tried the multiple-gateways function supported after 2.6.0.
>>> >>> https://github.com/capistrano/capistrano/pull/18
>>> >>>
>>> >>> I tried following codes, it work well for server_c and d. but not work
>>> >>> for server_a and b. cap try to connect via gate1 :(
>>> >>>
>>> >>> set :gateway, {
>>> >>>  'gate1' => [ 'server_c', 'server_d' ],
>>> >>> }
>>> >>>
>>> >>> I want client to connect to server_a and b directly.
>>> >>>
>>> >>> Does anyone have good idea?
>>> >>>
>>> >>> --Nobuhiro Nikushi
>>> >>>
>>> >>> --
>>> >>> * You received this message because you are subscribed to the Google
>>> >>> Groups "Capistrano" group.
>>> >>> * To post to this group, send email to [email protected]
>>> >>> * To unsubscribe from this group, send email to
>>> >>> [email protected] For more options, visit this 
>>> >>> group
>>> >>> at http://groups.google.com/group/capistrano?hl=en
>>> >>
>>> >> --
>>> >> * You received this message because you are subscribed to the Google
>>> >> Groups "Capistrano" group.
>>> >> * To post to this group, send email to [email protected]
>>> >> * To unsubscribe from this group, send email to
>>> >> [email protected] For more options, visit this 
>>> >> group
>>> >> at http://groups.google.com/group/capistrano?hl=en
>>> >
>>> > --
>>> > * You received this message because you are subscribed to the Google
>>> > Groups "Capistrano" group.
>>> > * To post to this group, send email to [email protected]
>>> > * To unsubscribe from this group, send email to
>>> > [email protected] For more options, visit this group
>>> > at http://groups.google.com/group/capistrano?hl=en
>>>
>>> --
>>> * You received this message because you are subscribed to the Google
>>> Groups "Capistrano" group.
>>> * To post to this group, send email to [email protected]
>>> * To unsubscribe from this group, send email to
>>> [email protected] For more options, visit this group
>>> at http://groups.google.com/group/capistrano?hl=en
>>
>>
>> --
>> * You received this message because you are subscribed to the Google Groups
>> "Capistrano" group.
>> * To post to this group, send email to [email protected]
>> * To unsubscribe from this group, send email to
>> [email protected] For more options, visit this group
>> at http://groups.google.com/group/capistrano?hl=en

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to [email protected]
* To unsubscribe from this group, send email to 
[email protected] For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Reply via email to