auto_nat_dns_proxy VirtualBox provider config option [GH-1313]
When set to false, Vagrant will no longer try to automatically manage NAT DNS proxy settings with VirtualBox.
This commit is contained in:
parent
25713e4568
commit
f713082280
|
@ -30,6 +30,9 @@ FEATURES:
|
|||
This decreases Vagrant's initial startup time considerably.
|
||||
- Allow "file://" URLs for box URLs. [GH-1087]
|
||||
- Emit "vagrant-mount" upstart event when NFS shares are mounted. [GH-1118]
|
||||
- Add a VirtualBox provider config `auto_nat_dns_proxy` which when set to
|
||||
false will not attempt to automatically manage NAT DNS proxy settings
|
||||
with VirtualBox. [GH-1313]
|
||||
|
||||
IMPROVEMENTS / BUG FIXES:
|
||||
|
||||
|
|
|
@ -25,28 +25,12 @@ module VagrantPlugins
|
|||
]
|
||||
attempt_and_log(command, "Enabling the Host I/O cache on the SATA controller...")
|
||||
|
||||
enable_dns_proxy = true
|
||||
begin
|
||||
contents = File.read("/etc/resolv.conf")
|
||||
|
||||
if contents =~ /^nameserver 127\.0\.(0|1)\.1$/
|
||||
# The use of both natdnsproxy and natdnshostresolver break on
|
||||
# Ubuntu 12.04 and 12.10 that uses resolvconf with localhost. When used
|
||||
# VirtualBox will give the client dns server 10.0.2.3, while
|
||||
# not binding to that address itself. Therefore disable this
|
||||
# feature if host uses the resolvconf server 127.0.0.1 or
|
||||
# 127.0.1.1
|
||||
@logger.info("Disabling DNS proxy since resolv.conf contains 127.0.0.1 or 127.0.1.1")
|
||||
enable_dns_proxy = false
|
||||
end
|
||||
rescue Errno::ENOENT; end
|
||||
if env[:machine].provider_config.auto_nat_dns_proxy
|
||||
@logger.info("Automatically figuring out whether to enable/disable NAT DNS proxy...")
|
||||
|
||||
# Enable/disable the NAT DNS proxy as necessary
|
||||
if enable_dns_proxy
|
||||
command = [
|
||||
"modifyvm", env[:machine].id,
|
||||
"--natdnsproxy1", "on"
|
||||
]
|
||||
if enable_dns_proxy?
|
||||
command = ["modifyvm", env[:machine].id, "--natdnsproxy1", "on"]
|
||||
attempt_and_log(command, "Enable the NAT DNS proxy on adapter 1...")
|
||||
else
|
||||
command = [ "modifyvm", env[:machine].id, "--natdnsproxy1", "off" ]
|
||||
|
@ -54,6 +38,9 @@ module VagrantPlugins
|
|||
command = [ "modifyvm", env[:machine].id, "--natdnshostresolver1", "off" ]
|
||||
attempt_and_log(command, "Disable the NAT DNS resolver on adapter 1...")
|
||||
end
|
||||
else
|
||||
@logger.info("NOT trying to automatically manage NAT DNS proxy.")
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
@ -70,6 +57,30 @@ module VagrantPlugins
|
|||
result = @env[:machine].provider.driver.execute_command(command)
|
||||
@logger.info("#{log} (exit status = #{result.exit_code})")
|
||||
end
|
||||
|
||||
# This uses some heuristics to determine if the NAT DNS proxy should
|
||||
# be enabled or disabled. See the comments within the function body
|
||||
# itself to see the checks it does.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def enable_dns_proxy?
|
||||
begin
|
||||
contents = File.read("/etc/resolv.conf")
|
||||
|
||||
if contents =~ /^nameserver 127\.0\.(0|1)\.1$/
|
||||
# The use of both natdnsproxy and natdnshostresolver break on
|
||||
# Ubuntu 12.04 and 12.10 that uses resolvconf with localhost. When used
|
||||
# VirtualBox will give the client dns server 10.0.2.3, while
|
||||
# not binding to that address itself. Therefore disable this
|
||||
# feature if host uses the resolvconf server 127.0.0.1 or
|
||||
# 127.0.1.1
|
||||
@logger.info("Disabling DNS proxy since resolv.conf contains 127.0.0.1 or 127.0.1.1")
|
||||
return false
|
||||
end
|
||||
rescue Errno::ENOENT; end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
class Config < Vagrant.plugin("2", :config)
|
||||
# Vagrant by default will make "smart" decisions to enable/disable
|
||||
# the NAT DNS proxy. If this is set to `true`, then the DNS proxy
|
||||
# will not be enabled, and it is up to the end user to do it.
|
||||
#
|
||||
# @return [Boolean]
|
||||
attr_accessor :auto_nat_dns_proxy
|
||||
|
||||
# An array of customizations to make on the VM prior to booting it.
|
||||
#
|
||||
# @return [Array]
|
||||
|
@ -17,6 +24,7 @@ module VagrantPlugins
|
|||
attr_reader :network_adapters
|
||||
|
||||
def initialize
|
||||
@auto_nat_dns_proxy = UNSET_VALUE
|
||||
@customizations = []
|
||||
@network_adapters = {}
|
||||
@gui = UNSET_VALUE
|
||||
|
@ -53,6 +61,9 @@ module VagrantPlugins
|
|||
# This is the hook that is called to finalize the object before it
|
||||
# is put into use.
|
||||
def finalize!
|
||||
# Default is to auto the DNS proxy
|
||||
@auto_nat_dns_proxy = true if @auto_nat_dns_proxy == UNSET_VALUE
|
||||
|
||||
# Default is to not show a GUI
|
||||
@gui = false if @gui == UNSET_VALUE
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue