Change the mechanism by which useless host only networks are detected and destroyed
This commit is contained in:
parent
4d8e3dc1bf
commit
c32ab0442c
|
@ -3,6 +3,9 @@
|
|||
- VirtualBox 4.0 support. Support for VirtualBox 3.2 is _dropped_, since
|
||||
the API is so different. Stay with the 0.6.x series if you have VirtualBox
|
||||
3.2.x.
|
||||
- Changed the unused host only network destroy mechanism to check for
|
||||
uselessness after the VM is destroyed. This should result in more accurate
|
||||
checks.
|
||||
|
||||
## 0.6.9 (December 21, 2010)
|
||||
|
||||
|
|
|
@ -62,9 +62,9 @@ module Vagrant
|
|||
register(:destroy, Builder.new do
|
||||
use Action[:halt], :force => true
|
||||
use VM::ClearNFSExports
|
||||
use VM::DestroyUnusedNetworkInterfaces
|
||||
use VM::Destroy
|
||||
use VM::CleanMachineFolder
|
||||
use VM::DestroyUnusedNetworkInterfaces
|
||||
end)
|
||||
|
||||
# package - Export and package the VM
|
||||
|
|
|
@ -9,20 +9,15 @@ module Vagrant
|
|||
end
|
||||
|
||||
def call(env)
|
||||
# We need to check if the host only network specified by any
|
||||
# of the adapters would not have any more clients if it was
|
||||
# destroyed. And if so, then destroy the host only network
|
||||
# itself.
|
||||
interfaces = env["vm"].vm.network_adapters.collect do |adapter|
|
||||
adapter.host_interface_object
|
||||
end
|
||||
# Destroy all the host only network adapters which are empty.
|
||||
VirtualBox::Global.global(true).host.network_interfaces.each do |iface|
|
||||
# We only care about host only interfaces
|
||||
next if iface.interface_type != :host_only
|
||||
|
||||
interfaces.compact.uniq.each do |interface|
|
||||
# Destroy the network interface if there is only one
|
||||
# attached VM (which must be this VM)
|
||||
if interface.attached_vms.length == 1
|
||||
# Destroy it if there is nothing attached
|
||||
if iface.attached_vms.empty?
|
||||
env.ui.info I18n.t("vagrant.actions.vm.destroy_network.destroying")
|
||||
interface.destroy
|
||||
iface.destroy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,24 +16,27 @@ class DestroyUnusedNetworkInterfacesVMActionTest < Test::Unit::TestCase
|
|||
|
||||
context "calling" do
|
||||
setup do
|
||||
@network_adapters = []
|
||||
@internal_vm.stubs(:network_adapters).returns(@network_adapters)
|
||||
@interfaces = []
|
||||
global = mock("global")
|
||||
host = mock("host")
|
||||
VirtualBox::Global.stubs(:global).returns(global)
|
||||
global.stubs(:host).returns(host)
|
||||
host.stubs(:network_interfaces).returns(@interfaces)
|
||||
end
|
||||
|
||||
def stub_interface(length=5)
|
||||
def stub_interface(length=5, type=:host_only)
|
||||
interface = mock("interface")
|
||||
adapter = mock("adapter")
|
||||
adapter.stubs(:host_interface_object).returns(interface)
|
||||
interface.stubs(:interface_type).returns(type)
|
||||
interface.stubs(:attached_vms).returns(Array.new(length))
|
||||
|
||||
@network_adapters << adapter
|
||||
@interfaces << interface
|
||||
interface
|
||||
end
|
||||
|
||||
should "destroy only the unused network interfaces" do
|
||||
stub_interface(5)
|
||||
stub_interface(7)
|
||||
results = [stub_interface(1), stub_interface(1)]
|
||||
results = [stub_interface(0), stub_interface(0)]
|
||||
|
||||
results.each do |result|
|
||||
result.expects(:destroy).once
|
||||
|
|
Loading…
Reference in New Issue