Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Allow customizing the GCE metadata service address via an env var.#148

Merged
theacodes merged 3 commits intogoogleapis:masterfrom
craigcitro:metadata_address
Mar 24, 2017
Merged

Allow customizing the GCE metadata service address via an env var.#148
theacodes merged 3 commits intogoogleapis:masterfrom
craigcitro:metadata_address

Conversation

@craigcitro
Copy link
Contributor

The goal here is to make it possible for a user of a binary that depends on
this library (eg the google cloud SDK) to be able to customize where it looks
for the GCE metadata service. (An adventurous user can already customize the
GCE metadata service location via the existing global vars in this library.)

The only bit of awkwardness here is really the test: since this is a top-level
statement, reloading is the only way to ensure it works.

PTAL @jonparrott

(and why yes I DID just completely copy-paste the commit description from the oauth2client PR.)

The goal here is to make it possible for a user of a binary that depends on
this library (eg the google cloud SDK) to be able to customize where it looks
for the GCE metadata service. (An adventurous user can already customize the
GCE metadata service location via the existing global vars in this library.)

The only bit of awkwardness here is really the test: since this is a top-level
statement, reloading is the only way to ensure it works.
@dhermes
Copy link
Contributor

dhermes commented Mar 24, 2017

@craigcitro Did you want to merge in both libraries? (It's pretty unlikely oauth2client will ever get another release.)

@craigcitro
Copy link
Contributor Author

@dhermes Yep, I purposely sent the PR for both.

@jonparrott mentioned the same about oauth2client, then remembered that he had to add something silly (update the classifiers?), so it was an opportune time for me to sneak it in. 😉

fake_ip = '1.2.3.4'
os.environ['GCE_METADATA_IP'] = fake_ip
reload_module(_metadata)
try:

This comment was marked as spam.

This comment was marked as spam.

# This is used to ping the metadata server, it avoids the cost of a DNS
# lookup.
_METADATA_IP_ROOT = 'http://169.254.169.254'
_METADATA_IP_ROOT = 'http://' + os.getenv('GCE_METADATA_IP', '169.254.169.254')

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@craigcitro
Copy link
Contributor Author

OK, updated to use the constants in environment_vars -- PTAL

@theacodes
Copy link
Contributor

@craigcitro LGTM, but Travis is mad about you not using 4 spaces for indentation. :)

@craigcitro
Copy link
Contributor Author

As well he should be. Fixed.

(Do you guys autosquash or should I squash?)

@theacodes
Copy link
Contributor

(Do you guys autosquash or should I squash?)

We autosquash

crop-focus-successful-squash

@theacodes theacodes merged commit b33b802 into googleapis:master Mar 24, 2017
@theacodes
Copy link
Contributor

Thanks, @craigcitro!

@dhermes
Copy link
Contributor

dhermes commented Mar 24, 2017

🚗 squash

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants