(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3)
return False
Checks to see if the metadata server is available.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        timeout (int): How long to wait for the metadata server to respond.
        retry_count (int): How many times to attempt connecting to metadata
            server using above timeout.

    Returns:
        bool: True if the metadata server is reachable, False otherwise.
Checks to see if the metadata server is available.
Checks to see if the metadata server is available .
def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3):
    """Checks to see if the metadata server is available.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        timeout (int): How long to wait for the metadata server to respond.
        retry_count (int): How many times to attempt connecting to metadata
            server using above timeout.

    Returns:
        bool: True if the metadata server is reachable, False otherwise.
    """
    # NOTE: The explicit ``timeout`` is a workaround. The underlying
    #       issue is that resolving an unknown host on some networks will take
    #       20-30 seconds; making this timeout short fixes the issue, but
    #       could lead to false negatives in the event that we are on GCE, but
    #       the metadata resolution was particularly slow. The latter case is
    #       "unlikely".
    retries = 0
    while retries < retry_count:
        try:
            response = request(
                url=_METADATA_IP_ROOT,
                method="GET",
                headers=_METADATA_HEADERS,
                timeout=timeout,
            )

            metadata_flavor = response.headers.get(_METADATA_FLAVOR_HEADER)
            return (
                response.status == http_client.OK
                and metadata_flavor == _METADATA_FLAVOR_VALUE
            )

        except exceptions.TransportError as e:
            _LOGGER.warning(
                "Compute Engine Metadata server unavailable on "
                "attempt %s of %s. Reason: %s",
                retries + 1,
                retry_count,
                e,
            )
            retries += 1

    return False
def ping ( request , timeout = _METADATA_DEFAULT_TIMEOUT , retry_count = 3 ) : # NOTE: The explicit ``timeout`` is a workaround. The underlying #       issue is that resolving an unknown host on some networks will take #       20-30 seconds; making this timeout short fixes the issue, but #       could lead to false negatives in the event that we are on GCE, but #       the metadata resolution was particularly slow. The latter case is #       "unlikely". retries = 0 while retries < retry_count : try : response = request ( url = _METADATA_IP_ROOT , method = "GET" , headers = _METADATA_HEADERS , timeout = timeout , ) metadata_flavor = response . headers . get ( _METADATA_FLAVOR_HEADER ) return ( response . status == http_client . OK and metadata_flavor == _METADATA_FLAVOR_VALUE ) except exceptions . TransportError as e : _LOGGER . warning ( "Compute Engine Metadata server unavailable on " "attempt %s of %s. Reason: %s" , retries + 1 , retry_count , e , ) retries += 1 return False