def is_ssh_open?(ip)
      s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
      sa = Socket.sockaddr_in(locate_config_value(:ssh_port), ip)

      begin
        s.connect_nonblock(sa)
      rescue Errno::EINPROGRESS
        resp = IO.select(nil, [s], nil, 1)
        if resp.nil?
          sleep SSH_POLL_INTERVAL
          return false
        end

        begin
          s.connect_nonblock(sa)
        rescue Errno::EISCONN
          Chef::Log.debug("sshd accepting connections on #{ip}")
          yield
          return true
        rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
          sleep SSH_POLL_INTERVAL
          return false
        end
      ensure
        s && s.close
      end
    end
def is_ssh_open?(ip)
      s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
      sa = Socket.sockaddr_in(locate_config_value(:ssh_port), ip)

      begin
        s.connect_nonblock(sa)
      rescue Errno::EINPROGRESS
        resp = IO.select(nil, [s], nil, 1)
        if resp.nil?
          sleep SSH_POLL_INTERVAL
          return false
        end

        begin
          s.connect_nonblock(sa)
        rescue Errno::EISCONN
          Chef::Log.debug("sshd accepting connections on #{ip}")
          yield
          return true
        rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
          sleep SSH_POLL_INTERVAL
          return false
        end
      ensure
        s && s.close
      end
    end
noinspection RubyArgCount,RubyResolve