def can_contact_metadata_server?(addr, port, timeout=2)
      t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
      saddr = Socket.pack_sockaddr_in(port, addr)
      connected = false

      begin
        t.connect_nonblock(saddr)
      rescue Errno::EINPROGRESS
        r, w, e = IO::select(nil, [t], nil, timeout)
        if !w.nil?
          connected = true
        else
          begin
            t.connect_nonblock(saddr)
          rescue Errno::EISCONN
            t.close
            connected = true
          rescue SystemCallError
          end
        end
      rescue SystemCallError
      end

      connected
    end
def can_contact_metadata_server?(addr, port, timeout=2)
      t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
      saddr = Socket.pack_sockaddr_in(port, addr)
      connected = false

      begin
        t.connect_nonblock(saddr)
      rescue Errno::EINPROGRESS
        r, w, e = IO::select(nil, [t], nil, timeout)
        if !w.nil?
          connected = true
        else
          begin
            t.connect_nonblock(saddr)
          rescue Errno::EISCONN
            t.close
            connected = true
          rescue SystemCallError
          end
        end
      rescue SystemCallError
      end

      connected
    end
Attempt to connect to the given address on the given port as a quick verification
 that the metadata service is available.

 === Parameters
 addr(String):: address of the metadata service
 port(Number):: port of the metadata service
 timeout(Number)::Optional - time to wait for a response

 === Return
 connected(Boolean):: true if a connection could be made, false otherwise