Class: Auger::Connection
- Inherits:
-
Object
- Object
- Auger::Connection
- Defined in:
- lib/auger/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#gateway ⇒ Object
Returns the value of attribute gateway.
-
#options ⇒ Object
Returns the value of attribute options.
-
#requests ⇒ Object
Returns the value of attribute requests.
-
#response ⇒ Object
Returns the value of attribute response.
-
#roles(*names) ⇒ Object
Returns the value of attribute roles.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(port) ⇒ Connection
constructor
A new instance of Connection.
- #method_missing(method, arg) ⇒ Object
-
#timeout(secs) ⇒ Object
explicit method to override use of timeout.rb in modules.
-
#try_close(conn) ⇒ Object
safe way to call plugin close() (rescue if the connection did not exist).
-
#try_open(server) ⇒ Object
setup options and call appropriate connection open().
-
#try_open_direct(server, options) ⇒ Object
call plugin open() and return plugin-specific connection object, or exception.
-
#try_open_tunnel(server, options) ⇒ Object
call plugin open() via an ssh tunnel.
Constructor Details
#initialize(port) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 |
# File 'lib/auger/connection.rb', line 13 def initialize(port) = {:port => port, :timeout => 5} @roles = [] @requests = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, arg) ⇒ Object
29 30 31 |
# File 'lib/auger/connection.rb', line 29 def method_missing(method, arg) [method] = arg end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def connection @connection end |
#gateway ⇒ Object
Returns the value of attribute gateway.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def gateway @gateway end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def end |
#requests ⇒ Object
Returns the value of attribute requests.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def requests @requests end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def response @response end |
#roles(*names) ⇒ Object
Returns the value of attribute roles.
5 6 7 |
# File 'lib/auger/connection.rb', line 5 def roles @roles end |
Class Method Details
.load(port, &block) ⇒ Object
7 8 9 10 11 |
# File 'lib/auger/connection.rb', line 7 def self.load(port, &block) connection = new(port) connection.instance_eval(&block) connection end |
Instance Method Details
#timeout(secs) ⇒ Object
explicit method to override use of timeout.rb in modules
25 26 27 |
# File 'lib/auger/connection.rb', line 25 def timeout(secs) [:timeout] = secs end |
#try_close(conn) ⇒ Object
safe way to call plugin close() (rescue if the connection did not exist)
63 64 65 66 67 68 69 70 |
# File 'lib/auger/connection.rb', line 63 def try_close(conn) begin self.close(conn) @gateway.shutdown! if @gateway rescue => e e end end |
#try_open(server) ⇒ Object
setup options and call appropriate connection open()
34 35 36 37 |
# File 'lib/auger/connection.rb', line 34 def try_open(server) = .merge(server.) # merge connection and server options [:tunnel] ? try_open_tunnel(server, ) : try_open_direct(server, ) end |
#try_open_direct(server, options) ⇒ Object
call plugin open() and return plugin-specific connection object, or exception
40 41 42 43 44 45 46 |
# File 'lib/auger/connection.rb', line 40 def try_open_direct(server, ) begin self.open(server.name, ) rescue => e e end end |
#try_open_tunnel(server, options) ⇒ Object
call plugin open() via an ssh tunnel
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/auger/connection.rb', line 49 def try_open_tunnel(server, ) host, user = [:tunnel].split('@').reverse #for ssh to the gateway host user ||= ENV['USER'] begin @gateway = Net::SSH::Gateway.new(host, user) gateway.open(server.name, [:port]) do |port| self.open('127.0.0.1', .merge({:port => port})) end rescue => e e end end |