Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make http://metadata.google.internal configurable #40317

Merged
merged 2 commits into from Aug 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions tensorflow/python/tpu/client/client.py
Expand Up @@ -38,17 +38,23 @@
_ENDPOINTS_SEPARATOR = ','
_DEFAULT_ENV_VARIABLE = 'TPU_NAME'
_DISCOVERY_SERVICE_URL_ENV_VARIABLE = 'TPU_API_DISCOVERY_URL'
_GCE_METADATA_ENDPOINT = 'http://metadata.google.internal'
_GCE_METADATA_URL_ENV_VARIABLE = 'GCE_METADATA_IP'
_DEFAULT_ENDPOINT_PORT = '8470'


def _environment_discovery_url():
return os.environ.get(_DISCOVERY_SERVICE_URL_ENV_VARIABLE)


def _gce_metadata_endpoint():
return 'http://' + os.environ.get(
_GCE_METADATA_URL_ENV_VARIABLE,
'metadata.google.internal')


def _request_compute_metadata(path):
req = request.Request(
'%s/computeMetadata/v1/%s' % (_GCE_METADATA_ENDPOINT, path),
'%s/computeMetadata/v1/%s' % (_gce_metadata_endpoint(), path),
headers={'Metadata-Flavor': 'Google'})
resp = request.urlopen(req)
return _as_text(resp.read())
Expand Down