Esempio n. 1
0
 def _CheckServer(self):
   try:
     numeric_project_id = gce_read.ReadNoProxy(
         gce_read.GOOGLE_GCE_METADATA_NUMERIC_PROJECT_URI)
   except (urllib2.HTTPError, urllib2.URLError, socket.timeout):
     return False
   else:
     return numeric_project_id.isdigit()
Esempio n. 2
0
def _ReadNoProxyWithCleanFailures(uri, http_errors_to_ignore=()):
    """Reads data from a URI with no proxy, yielding cloud-sdk exceptions."""
    try:
        return gce_read.ReadNoProxy(uri)
    except urllib.error.HTTPError as e:
        if e.code in http_errors_to_ignore:
            return None
        raise MetadataServerException(e)
    except urllib.error.URLError as e:
        raise CannotConnectToMetadataServerException(e)
Esempio n. 3
0
 def _CheckServer(self):
   try:
     numeric_project_id = gce_read.ReadNoProxy(
         gce_read.GOOGLE_GCE_METADATA_NUMERIC_PROJECT_URI)
   except (urllib_error.URLError, socket.error, http_client.HTTPException):
     # Depending on how a firewall/ NAT behaves, we can have different
     # exceptions at different levels in the networking stack when trying to
     # access an address that we can't reach. Capture all these exceptions.
     return False
   else:
     return numeric_project_id.isdigit()
Esempio n. 4
0
def _ReadNoProxyWithCleanFailures(uri, http_errors_to_ignore=()):
    """Reads data from a URI with no proxy, yielding cloud-sdk exceptions."""
    try:
        return gce_read.ReadNoProxy(uri)
    except urllib.error.HTTPError as e:
        if e.code in http_errors_to_ignore:
            return None
        if e.code == 403:
            raise MetadataServerException(
                'The request is rejected. Please check if the metadata server is '
                'concealed.\n'
                'See https://cloud.google.com/kubernetes-engine/docs/how-to/protecting-cluster-metadata#concealment '
                'for more information about metadata server concealment.')
        raise MetadataServerException(e)
    except urllib.error.URLError as e:
        raise CannotConnectToMetadataServerException(e)
Esempio n. 5
0
 def _CheckServer(self):
   return gce_read.ReadNoProxy(
       gce_read.GOOGLE_GCE_METADATA_NUMERIC_PROJECT_URI).isdigit()
Esempio n. 6
0
 def _CheckServer(self):
     return gce_read.ReadNoProxy(
         gce_read.GOOGLE_GCE_METADATA_NUMERIC_PROJECT_URI,
         properties.VALUES.compute.gce_metadata_check_timeout_sec.GetInt(),
     ).isdigit()