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