Merge pull request #62 from elyast/hotfix/1.3.0_ip_resolver
Allow ip resolver to know for which vm other current vm's IP is being resolved
This commit is contained in:
		
						commit
						ef410e6c04
					
				| 
						 | 
					@ -81,10 +81,11 @@ where host name is stored in ssh_info hash of each machine.
 | 
				
			||||||
This causes generation of invalid /etc/hosts file.
 | 
					This causes generation of invalid /etc/hosts file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Custom IP resolver gives you oportunity to calculate IP address
 | 
					Custom IP resolver gives you oportunity to calculate IP address
 | 
				
			||||||
for each machine by yourself. For example:
 | 
					for each machine by yourself, giving You also access to the machine that is
 | 
				
			||||||
 | 
					updating /etc/hosts. For example:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```ruby
 | 
					```ruby
 | 
				
			||||||
config.hostmanager.ip_resolver = proc do |vm|
 | 
					config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
 | 
				
			||||||
  if hostname = (vm.ssh_info && vm.ssh_info[:host])
 | 
					  if hostname = (vm.ssh_info && vm.ssh_info[:host])
 | 
				
			||||||
    `host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1]
 | 
					    `host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1]
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ module VagrantPlugins
 | 
				
			||||||
        # download and modify file with Vagrant-managed entries
 | 
					        # download and modify file with Vagrant-managed entries
 | 
				
			||||||
        file = @global_env.tmp_path.join("hosts.#{machine.name}")
 | 
					        file = @global_env.tmp_path.join("hosts.#{machine.name}")
 | 
				
			||||||
        machine.communicate.download(realhostfile, file)
 | 
					        machine.communicate.download(realhostfile, file)
 | 
				
			||||||
        update_file(file)
 | 
					        update_file(file, machine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # upload modified file and remove temporary file
 | 
					        # upload modified file and remove temporary file
 | 
				
			||||||
        machine.communicate.upload(file, '/tmp/hosts')
 | 
					        machine.communicate.upload(file, '/tmp/hosts')
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ module VagrantPlugins
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      private
 | 
					      private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def update_file(file)
 | 
					      def update_file(file, resolving_machine=nil)
 | 
				
			||||||
        # build array of host file entries from Vagrant configuration
 | 
					        # build array of host file entries from Vagrant configuration
 | 
				
			||||||
        entries = []
 | 
					        entries = []
 | 
				
			||||||
        destroyed_entries = []
 | 
					        destroyed_entries = []
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ module VagrantPlugins
 | 
				
			||||||
            machine = @global_env.machine(name, p)
 | 
					            machine = @global_env.machine(name, p)
 | 
				
			||||||
            host = machine.config.vm.hostname || name
 | 
					            host = machine.config.vm.hostname || name
 | 
				
			||||||
            id = machine.id
 | 
					            id = machine.id
 | 
				
			||||||
            ip = get_ip_address(machine)
 | 
					            ip = get_ip_address(machine, resolving_machine)
 | 
				
			||||||
            aliases = machine.config.hostmanager.aliases.join(' ').chomp
 | 
					            aliases = machine.config.hostmanager.aliases.join(' ').chomp
 | 
				
			||||||
            if id.nil?
 | 
					            if id.nil?
 | 
				
			||||||
              destroyed_entries << "#{ip}\t#{host} #{aliases}"
 | 
					              destroyed_entries << "#{ip}\t#{host} #{aliases}"
 | 
				
			||||||
| 
						 | 
					@ -94,10 +94,10 @@ module VagrantPlugins
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def get_ip_address(machine)
 | 
					      def get_ip_address(machine, resolving_machine)
 | 
				
			||||||
        custom_ip_resolver = machine.config.hostmanager.ip_resolver
 | 
					        custom_ip_resolver = machine.config.hostmanager.ip_resolver
 | 
				
			||||||
        if custom_ip_resolver
 | 
					        if custom_ip_resolver
 | 
				
			||||||
          custom_ip_resolver.call(machine)
 | 
					          custom_ip_resolver.call(machine, resolving_machine)
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          ip = nil
 | 
					          ip = nil
 | 
				
			||||||
          if machine.config.hostmanager.ignore_private_ip != true
 | 
					          if machine.config.hostmanager.ignore_private_ip != true
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue