Fix for issue #108, add a flag to manage guest hosts file.
This commit is contained in:
parent
176d70efc5
commit
7c06c812f6
|
@ -40,6 +40,9 @@ Vagrantfile to activate this behavior.
|
|||
To update the host's `/etc/hosts` file, set the `hostmanager.manage_host`
|
||||
attribute to `true`.
|
||||
|
||||
To update the guests' `/etc/hosts` file, set the `hostmanager.manage_guest`
|
||||
attribute to `true`.
|
||||
|
||||
A machine's IP address is defined by either the static IP for a private
|
||||
network configuration or by the SSH host configuration. To disable
|
||||
using the private network IP address, set `config.hostmanager.ignore_private_ip`
|
||||
|
@ -60,6 +63,7 @@ Example configuration:
|
|||
Vagrant.configure("2") do |config|
|
||||
config.hostmanager.enabled = true
|
||||
config.hostmanager.manage_host = true
|
||||
config.hostmanager.manage_guest = true
|
||||
config.hostmanager.ignore_private_ip = false
|
||||
config.hostmanager.include_offline = true
|
||||
config.vm.define 'example-box' do |node|
|
||||
|
|
|
@ -27,11 +27,13 @@ module VagrantPlugins
|
|||
@app.call(env)
|
||||
|
||||
# update /etc/hosts file on active machines
|
||||
env[:ui].info I18n.t('vagrant_hostmanager.action.update_guests')
|
||||
@global_env.active_machines.each do |name, p|
|
||||
if p == @provider
|
||||
machine = @global_env.machine(name, p)
|
||||
@updater.update_guest(machine)
|
||||
if @machine.config.hostmanager.manage_guest?
|
||||
env[:ui].info I18n.t('vagrant_hostmanager.action.update_guests')
|
||||
@global_env.active_machines.each do |name, p|
|
||||
if p == @provider
|
||||
machine = @global_env.machine(name, p)
|
||||
@updater.update_guest(machine)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,18 +8,22 @@ module VagrantPlugins
|
|||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
global_env = env[:global_env]
|
||||
@config = Util.get_config(global_env)
|
||||
@machine = env[:machine]
|
||||
@updater = HostsFile::Updater.new(@machine.env, env[:provider])
|
||||
@logger = Log4r::Logger.new('vagrant::hostmanager::update_guest')
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', {
|
||||
:name => @machine.name
|
||||
})
|
||||
@updater.update_guest(@machine)
|
||||
if @config.hostmanager.manage_guest?
|
||||
env[:ui].info I18n.t('vagrant_hostmanager.action.update_guest', {
|
||||
:name => @machine.name
|
||||
})
|
||||
@updater.update_guest(@machine)
|
||||
|
||||
@app.call(env)
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,7 @@ module VagrantPlugins
|
|||
# update /etc/hosts file for specified guest machines
|
||||
with_target_vms(argv, options) do |machine|
|
||||
@env.action_runner.run(Action.update_guest, {
|
||||
:global_env => @env,
|
||||
:machine => machine,
|
||||
:provider => options[:provider]
|
||||
})
|
||||
|
|
|
@ -3,6 +3,7 @@ module VagrantPlugins
|
|||
class Config < Vagrant.plugin('2', :config)
|
||||
attr_accessor :enabled
|
||||
attr_accessor :manage_host
|
||||
attr_accessor :manage_guest
|
||||
attr_accessor :ignore_private_ip
|
||||
attr_accessor :aliases
|
||||
attr_accessor :include_offline
|
||||
|
@ -11,10 +12,12 @@ module VagrantPlugins
|
|||
alias_method :enabled?, :enabled
|
||||
alias_method :include_offline?, :include_offline
|
||||
alias_method :manage_host?, :manage_host
|
||||
alias_method :manage_guest?, :manage_guest
|
||||
|
||||
def initialize
|
||||
@enabled = UNSET_VALUE
|
||||
@manage_host = UNSET_VALUE
|
||||
@manage_guest = UNSET_VALUE
|
||||
@ignore_private_ip = UNSET_VALUE
|
||||
@include_offline = UNSET_VALUE
|
||||
@aliases = UNSET_VALUE
|
||||
|
@ -24,6 +27,7 @@ module VagrantPlugins
|
|||
def finalize!
|
||||
@enabled = false if @enabled == UNSET_VALUE
|
||||
@manage_host = false if @manage_host == UNSET_VALUE
|
||||
@manage_guest = false if @manage_guest == UNSET_VALUE
|
||||
@ignore_private_ip = false if @ignore_private_ip == UNSET_VALUE
|
||||
@include_offline = false if @include_offline == UNSET_VALUE
|
||||
@aliases = [] if @aliases == UNSET_VALUE
|
||||
|
@ -37,6 +41,7 @@ module VagrantPlugins
|
|||
|
||||
errors << validate_bool('hostmanager.enabled', @enabled)
|
||||
errors << validate_bool('hostmanager.manage_host', @manage_host)
|
||||
errors << validate_bool('hostmanager.manage_guest', @manage_guest)
|
||||
errors << validate_bool('hostmanager.ignore_private_ip', @ignore_private_ip)
|
||||
errors << validate_bool('hostmanager.include_offline', @include_offline)
|
||||
errors.compact!
|
||||
|
|
|
@ -12,7 +12,9 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def provision
|
||||
@updater.update_guest(@machine)
|
||||
if @config.hostmanager.manage_guest?
|
||||
@updater.update_guest(@machine)
|
||||
end
|
||||
if @config.hostmanager.manage_host?
|
||||
@updater.update_host
|
||||
end
|
||||
|
|
|
@ -16,6 +16,7 @@ Vagrant.configure('2') do |config|
|
|||
|
||||
config.hostmanager.enabled = true
|
||||
config.hostmanager.manage_host = true
|
||||
config.hostmanager.manage_guest = true
|
||||
|
||||
config.vm.define :server1 do |server|
|
||||
server.vm.hostname = 'fry'
|
||||
|
|
Loading…
Reference in New Issue