Destroying unused network interfaces via VBoxManage
This commit is contained in:
parent
d2e33768f3
commit
7a70755362
|
@ -9,17 +9,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
# Destroy all the host only network adapters which are empty.
|
env[:vm].driver.delete_unused_host_only_networks
|
||||||
VirtualBox::Global.global(true).host.network_interfaces.each do |iface|
|
|
||||||
# We only care about host only interfaces
|
|
||||||
next if iface.interface_type != :host_only
|
|
||||||
|
|
||||||
# Destroy it if there is nothing attached
|
|
||||||
if iface.attached_vms.empty?
|
|
||||||
env[:ui].info I18n.t("vagrant.actions.vm.destroy_network.destroying")
|
|
||||||
iface.destroy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Continue along
|
# Continue along
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -52,6 +52,28 @@ module Vagrant
|
||||||
execute("unregistervm", @uuid, "--delete")
|
execute("unregistervm", @uuid, "--delete")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deletes any host only networks that aren't being used for anything.
|
||||||
|
def delete_unused_host_only_networks
|
||||||
|
networks = []
|
||||||
|
execute("list", "hostonlyifs").split("\n").each do |line|
|
||||||
|
networks << $1.to_s if line =~ /^Name:\s+(.+?)$/
|
||||||
|
end
|
||||||
|
|
||||||
|
execute("list", "vms").split("\n").each do |line|
|
||||||
|
if line =~ /^".+?"\s+{(.+?)}$/
|
||||||
|
execute("showvminfo", $1.to_s, "--machinereadable").split("\n").each do |info|
|
||||||
|
if info =~ /^hostonlyadapter\d+="(.+?)"$/
|
||||||
|
networks.delete($1.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
networks.each do |name|
|
||||||
|
execute("hostonlyif", "remove", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Forwards a set of ports for a VM.
|
# Forwards a set of ports for a VM.
|
||||||
#
|
#
|
||||||
# This will not affect any previously set forwarded ports,
|
# This will not affect any previously set forwarded ports,
|
||||||
|
|
Loading…
Reference in New Issue