lib/ridley/host_connector.rb in ridley-0.10.0 vs lib/ridley/host_connector.rb in ridley-0.10.1

- old
+ new

@@ -17,19 +17,20 @@ # # @param host [String] # the host to attempt to connect to # @option options [Hash] :ssh # * :port (Fixnum) the ssh port to connect on the node the bootstrap will be performed on (22) + # * :timeout (Float) [5.0] timeout value for testing SSH connection # @option options [Hash] :winrm # * :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985) # @param block [Proc] # an optional block that is yielded the best HostConnector # # @return [Ridley::HostConnector] a class under Ridley::HostConnector def best_connector_for(host, options = {}, &block) ssh_port, winrm_port = parse_port_options(options) - if connector_port_open?(host, ssh_port) + if connector_port_open?(host, ssh_port, options[:ssh][:timeout]) host_connector = Ridley::HostConnector::SSH elsif connector_port_open?(host, winrm_port) host_connector = Ridley::HostConnector::WinRM else raise Ridley::Errors::HostConnectionError, "No available connection method available on #{host}." @@ -47,13 +48,15 @@ # # @param host [String] # the host to attempt to connect to # @param port [Fixnum] # the port to attempt to connect on + # @param timeout [Float] + # the number of seconds to wait (default: 3) # # @return [Boolean] - def connector_port_open?(host, port) - Timeout::timeout(3) do + def connector_port_open?(host, port, timeout=3) + Timeout::timeout(timeout) do socket = TCPSocket.new(host, port) socket.close end true