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

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

Merged
merged 3 commits into from
Mar 24, 2017

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants