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

[util] Fix get_hostname for windows ec2 instances #2451

Merged
merged 1 commit into from
May 13, 2016

Conversation

hkaj
Copy link
Member

@hkaj hkaj commented Apr 28, 2016

Right now get_hostname never resolves to an EC2 instance id for windows host because the condition to look for it didn't include empty hostnames. This PR fixes that.

# try and find a EC2 instance ID
if (Platform.is_ecs_instance()) or \
(hostname is not None and True in [hostname.lower().startswith(p) for p in [u'ip-', u'domu']]) or \
(hostname is None and os_name == 'windows'):
instanceid = EC2.get_instance_id(config)
Copy link
Member

@yannmh yannmh Apr 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to this bloc, the code never attempts to resolve the Windows hostname as _get_hostname_unix is called on UNIX system only. The hostname == None, and we have no clue whether the host belongs or not to EC2.

It'd be better if we can get a sense of it and spare undesired call to the EC2.get_instance_id method. We could for instance eval the socket.gethostname value sooner on Windows systems.

@yannmh yannmh self-assigned this Apr 29, 2016
@yannmh yannmh added this to the 5.8.0 milestone Apr 29, 2016
@yannmh yannmh added the bugfix label Apr 29, 2016
@yannmh yannmh assigned hkaj and unassigned yannmh Apr 29, 2016
@hkaj hkaj force-pushed the haissam/get_hostname_fix branch from d9663d4 to dab517f Compare May 2, 2016 14:00
@hkaj
Copy link
Member Author

hkaj commented May 2, 2016

@yannmh Thanks for the feedback, socket.gethostname is not relevant in this case as it will return something like WIN-XXXXXX which doesn't help figuring out wether this is an EC2 host or not, but I used something less costly to determine that (os.path.exists). Let me know what you think.

@olivielpeau olivielpeau assigned yannmh and unassigned hkaj May 2, 2016
@yannmh
Copy link
Member

yannmh commented May 13, 2016

Looks good. Thanks @hkaj.

@yannmh yannmh merged commit 2f8812a into master May 13, 2016
@yannmh yannmh deleted the haissam/get_hostname_fix branch May 13, 2016 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants