Skip to content

Commit

Permalink
Merge pull request #4 from innogames/remove_on_suspend_option
Browse files Browse the repository at this point in the history
Remove on suspend option
  • Loading branch information
agiledivider committed May 29, 2013
2 parents 0948793 + 39f2100 commit 104a5a6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

This plugin adds an entry to your /etc/hosts file on the host system.

On **up** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.
On **up**, **resume** and **reload** commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.

On **halt**, **suspend** and **destroy**, those entries will be removed again.
On **halt** and **destroy**, those entries will be removed again.
By setting the remove\_on\_suspend option, you can have them removed on **suspend**, too:

config.hostsupdater.remove_on_suspend = true

## Versions
### 0.0.4
Expand All @@ -24,9 +27,9 @@ Uninstall it with:

At the moment, the only things you need, are the hostname and a :private_network network with a fixed ip.

$ config.vm.network :private_network, ip: "192.168.3.10"
$ config.vm.hostname = "www.testing.de"
$ config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
config.vm.network :private_network, ip: "192.168.3.10"
config.vm.hostname = "www.testing.de"
config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]

This ip and the hostname will be used for the entry in the /etc/hosts file.

Expand Down
9 changes: 7 additions & 2 deletions lib/vagrant-hostsupdater/Action/RemoveHosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ def initialize(app, env)
end

def call(env)
@ui.info "Removing hosts"
removeHostEntries
machine_action = env[:machine_action]
if machine_action != :suspend || @machine.config.hostsupdater.remove_on_suspend
@ui.info "Removing hosts"
removeHostEntries
else
@ui.info "Removing on suspend disabled"
end
@app.call(env)
end

Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant-hostsupdater/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module VagrantPlugins
module HostsUpdater
class Config < Vagrant.plugin("2", :config)
attr_accessor :aliases
attr_accessor :remove_on_suspend
end
end
end
end
6 changes: 5 additions & 1 deletion lib/vagrant-hostsupdater/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ class Plugin < Vagrant.plugin('2')
hook.append(Action::UpdateHosts)
end

action_hook(:hostsupdater, :machine_action_resume) do |hook|
hook.append(Action::UpdateHosts)
end

command(:hostsupdater) do
require_relative 'command'
Command
end
end
end
end
end

0 comments on commit 104a5a6

Please sign in to comment.