From b2ee015d009683e3e010d4a8c99218cf8d4b6f44 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Jul 2013 13:13:11 -0700 Subject: [PATCH] VirtualBox no longer removes network interfaces [GH-1324] --- CHANGELOG.md | 5 +++++ .../action/destroy_unused_network_interfaces.rb | 10 ++++++++-- plugins/providers/virtualbox/config.rb | 13 +++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c1d8bfc7..49ef901aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ FEATURES: - VirtualBox VBoxManage customizations can now be specified to run pre-boot (the default and existing functionality, pre-import, or post-boot. [GH-1247] + - VirtualBox no longer destroys unused network interfaces by default. + This didn't work across multi-user systems and required admin privileges + on Windows, so it has been disabled by default. It can be enabled using + the VirtualBox provider-specific `destroy_unused_network_interfaces` + configuration by setting it to true. [GH-1324] IMPROVEMENTS: diff --git a/plugins/providers/virtualbox/action/destroy_unused_network_interfaces.rb b/plugins/providers/virtualbox/action/destroy_unused_network_interfaces.rb index 0897ef6dd..c703790e0 100644 --- a/plugins/providers/virtualbox/action/destroy_unused_network_interfaces.rb +++ b/plugins/providers/virtualbox/action/destroy_unused_network_interfaces.rb @@ -1,14 +1,20 @@ +require "log4r" + module VagrantPlugins module ProviderVirtualBox module Action class DestroyUnusedNetworkInterfaces def initialize(app, env) @app = app + @logger = Log4r::Logger.new("vagrant::plugins::virtualbox::destroy_unused_netifs") end def call(env) - env[:machine].provider.driver.delete_unused_host_only_networks - @app.call(env) + if env[:machine].provider_config.destroy_unused_network_interfaces + @logger.info("Destroying unused network interfaces...") + env[:machine].provider.driver.delete_unused_host_only_networks + @app.call(env) + end end end end diff --git a/plugins/providers/virtualbox/config.rb b/plugins/providers/virtualbox/config.rb index 40ff19997..7bb3cd0d6 100644 --- a/plugins/providers/virtualbox/config.rb +++ b/plugins/providers/virtualbox/config.rb @@ -13,6 +13,14 @@ module VagrantPlugins # @return [Array] attr_reader :customizations + # If true, unused network interfaces will automatically be deleted. + # This defaults to false because the detection does not work across + # multiple users, and because on Windows this operation requires + # administrative privileges. + # + # @return [Boolean] + attr_accessor :destroy_unused_network_interfaces + # If set to `true`, then VirtualBox will be launched with a GUI. # # @return [Boolean] @@ -32,6 +40,7 @@ module VagrantPlugins def initialize @auto_nat_dns_proxy = UNSET_VALUE @customizations = [] + @destroy_unused_network_interfaces = UNSET_VALUE @name = UNSET_VALUE @network_adapters = {} @gui = UNSET_VALUE @@ -73,6 +82,10 @@ module VagrantPlugins # Default is to auto the DNS proxy @auto_nat_dns_proxy = true if @auto_nat_dns_proxy == UNSET_VALUE + if @destroy_unused_network_interfaces == UNSET_VALUE + @destroy_unused_network_interfaces = false + end + # Default is to not show a GUI @gui = false if @gui == UNSET_VALUE