Improved resilience of the VirtualBox driver delete_unused_host_only_networks function by
ignoring VMs that may have been deleted between the calls to 'vboxmanage list vms' and 'vboxmanage showvminfo'
This commit is contained in:
parent
56c8b9269a
commit
9aecd5e1a4
|
@ -85,12 +85,19 @@ module VagrantPlugins
|
||||||
|
|
||||||
execute("list", "vms").split("\n").each do |line|
|
execute("list", "vms").split("\n").each do |line|
|
||||||
if vm_name = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
if vm_name = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
||||||
|
begin
|
||||||
info = execute("showvminfo", vm_name, "--machinereadable", retryable: true)
|
info = execute("showvminfo", vm_name, "--machinereadable", retryable: true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if network_name = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
if network_name = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
||||||
networks.delete(network_name)
|
networks.delete(network_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Vagrant::Errors::VBoxManageError => e
|
||||||
|
raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND")
|
||||||
|
|
||||||
|
# VirtualBox could not find the vm. It may have been deleted
|
||||||
|
# by another process after we called 'vboxmanage list vms'? Ignore this error.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -176,12 +176,19 @@ module VagrantPlugins
|
||||||
|
|
||||||
execute("list", "vms").split("\n").each do |line|
|
execute("list", "vms").split("\n").each do |line|
|
||||||
if vm = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
if vm = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
||||||
|
begin
|
||||||
info = execute("showvminfo", vm, "--machinereadable", retryable: true)
|
info = execute("showvminfo", vm, "--machinereadable", retryable: true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if adapter = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
if adapter = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
||||||
networks.delete(adapter)
|
networks.delete(adapter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Vagrant::Errors::VBoxManageError => e
|
||||||
|
raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND")
|
||||||
|
|
||||||
|
# VirtualBox could not find the vm. It may have been deleted
|
||||||
|
# by another process after we called 'vboxmanage list vms'? Ignore this error.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -83,12 +83,19 @@ module VagrantPlugins
|
||||||
|
|
||||||
execute("list", "vms").split("\n").each do |line|
|
execute("list", "vms").split("\n").each do |line|
|
||||||
if line =~ /^".+?"\s+\{(.+?)\}$/
|
if line =~ /^".+?"\s+\{(.+?)\}$/
|
||||||
|
begin
|
||||||
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
||||||
info.split("\n").each do |inner_line|
|
info.split("\n").each do |inner_line|
|
||||||
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
||||||
networks.delete($1.to_s)
|
networks.delete($1.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Vagrant::Errors::VBoxManageError => e
|
||||||
|
raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND")
|
||||||
|
|
||||||
|
# VirtualBox could not find the vm. It may have been deleted
|
||||||
|
# by another process after we called 'vboxmanage list vms'? Ignore this error.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -180,12 +180,19 @@ module VagrantPlugins
|
||||||
|
|
||||||
execute("list", "vms", retryable: true).split("\n").each do |line|
|
execute("list", "vms", retryable: true).split("\n").each do |line|
|
||||||
if line =~ /^".+?"\s+\{(.+?)\}$/
|
if line =~ /^".+?"\s+\{(.+?)\}$/
|
||||||
|
begin
|
||||||
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
||||||
info.split("\n").each do |inner_line|
|
info.split("\n").each do |inner_line|
|
||||||
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
||||||
networks.delete($1.to_s)
|
networks.delete($1.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Vagrant::Errors::VBoxManageError => e
|
||||||
|
raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND")
|
||||||
|
|
||||||
|
# VirtualBox could not find the vm. It may have been deleted
|
||||||
|
# by another process after we called 'vboxmanage list vms'? Ignore this error.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -176,12 +176,19 @@ module VagrantPlugins
|
||||||
|
|
||||||
execute("list", "vms", retryable: true).split("\n").each do |line|
|
execute("list", "vms", retryable: true).split("\n").each do |line|
|
||||||
if line =~ /^".+?"\s+\{(.+?)\}$/
|
if line =~ /^".+?"\s+\{(.+?)\}$/
|
||||||
|
begin
|
||||||
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
|
||||||
info.split("\n").each do |inner_line|
|
info.split("\n").each do |inner_line|
|
||||||
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
if inner_line =~ /^hostonlyadapter\d+="(.+?)"$/
|
||||||
networks.delete($1.to_s)
|
networks.delete($1.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Vagrant::Errors::VBoxManageError => e
|
||||||
|
raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND")
|
||||||
|
|
||||||
|
# VirtualBox could not find the vm. It may have been deleted
|
||||||
|
# by another process after we called 'vboxmanage list vms'? Ignore this error.
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue