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

Add hooks & define active/offline as running/not #34

Merged
merged 1 commit into from
Aug 15, 2013
Merged

Add hooks & define active/offline as running/not #34

merged 1 commit into from
Aug 15, 2013

Conversation

jeremiahsnapp
Copy link

Hosts entries shouldn't only be added/removed upon creation/destruction.
The persistence of /etc/hosts entries while a vm is in a halted or
suspended state is undesirable especially when hostmanager.manage_host
is set to true. That would mean your host's /etc/hosts would retain
entries even if you aren't currently using a vm. The vm would have to
be destroyed for the entry to be removed from the host's /etc/hosts.

Adding hooks for halt, resume and suspend commands and changing the
concept of active and offline states from created or not_created to
running or not running allows a vm's entry to be added when it is put
in a running state and removed when it is not running.

The hostmanager.include_offline can be set to true if one still desires
to have not_created or not running machines' entries included in the
/etc/hosts file.

Hosts entries shouldn't only be added/removed upon creation/destruction.
The persistence of /etc/hosts entries while a vm is in a halted or
suspended state is undesirable especially when hostmanager.manage_host
is set to true. That would mean your host's /etc/hosts would retain
entries even if you aren't currently using a vm.  The vm would have to
be destroyed for the entry to be removed from the host's /etc/hosts.

Adding hooks for halt, resume and suspend commands and changing the
concept of active and offline states from created or not_created to
running or not running allows a vm's entry to be added when it is put
in a running state and removed when it is not running.

The hostmanager.include_offline can be set to true if one still desires
to have not_created or not running machines' entries included in the
/etc/hosts file.
@jeremiahsnapp
Copy link
Author

Sorry, I accidentally closed the PR.

@smdahlen
Copy link
Contributor

Looks good. Merging and pushing out a new version.

smdahlen added a commit that referenced this pull request Aug 15, 2013
Add hooks & define active/offline as running/not
@smdahlen smdahlen merged commit 2f1e3e0 into devopsgroup-io:master Aug 15, 2013
@jeremiahsnapp
Copy link
Author

Thanks a lot for merging this!

@smdahlen
Copy link
Contributor

@jeremiahsnapp fyi -- I was a bit premature in supporting this merge. The hardcoding of machine state logic broke providers other than VirtualBox. Looking at a fix now.

@smdahlen
Copy link
Contributor

@jeremiahsnapp I am reverting this commit for now as part of 1.2. The implementation needs to be rethought with support for all Vagrant providers. Since providers use different machine state's, it will require some time. Please take a look.

@jeremiahsnapp
Copy link
Author

Sorry about the extra trouble. I'm not familiar with the other providers' states so I'm not sure how much help I'll be with finding a solution. I'll see what I can figure out.

@smdahlen
Copy link
Contributor

Not your fault, I should have looked more closely. I think it would be best to avoid using machine states at all (the original code used active_machines). It might be possible to key off of the machine action they user called. For example, if they called suspend, then you know that machine should be removed from the /etc/hosts file.

@jeremiahsnapp
Copy link
Author

I agree keying off actions to trigger hostmanager would likely work but the real problem will lie in #get_machines which creates the list of machines to be added to hosts file.

I wanted to specifically differentiate between running and not running machines which wouldn't work well with some providers as you said. #active_machines just differentiates between created or not created machines.

https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/environment.rb#L151-L156

After inspecting your code more I realize that I will get the results I want without any change simply because #update_file will remove all hostmanager entries from the hosts file before adding the most recently evaluated list of machines. That means if I halt a set of vm's in one project and up a set of vm's from a different project then the old vm entries will be removed and the new vm entries will be inserted which is what I really wanted.

So this can be closed as far as I am concerned.

The only thing I might add would be a hostmanager command that would explicitly delete all hostmanager entries from the hosts file so I would be able to arbitrarily decide to clean the hosts file.

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.

None yet

2 participants