Make network creation thread-safe, closes #104

This commit is contained in:
Brian Pitts 2014-01-17 18:16:18 -06:00
parent 46306503f4
commit 1aabe66b23

View File

@ -2,6 +2,7 @@ require 'log4r'
require 'vagrant/util/network_ip'
require 'vagrant/util/scoped_hash_override'
require 'ipaddr'
require 'thread'
module VagrantPlugins
module ProviderLibvirt
@ -13,6 +14,8 @@ module VagrantPlugins
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
@@lock = Mutex.new
def initialize(app, env)
mess = 'vagrant_libvirt::action::create_networks'
@logger = Log4r::Logger.new(mess)
@ -74,6 +77,10 @@ module VagrantPlugins
networks.push(options)
end
# only one vm at a time should try to set up networks
# otherwise they'll have inconsitent views of current state
# and conduct redundant operations that cause errors
@@lock.synchronize do
# Iterate over networks If some network is not
# available, create it if possible. Otherwise raise an error.
networks.each do |options|
@ -112,6 +119,7 @@ module VagrantPlugins
autostart_network if !@interface_network[:autostart]
activate_network if !@interface_network[:active]
end
end
@app.call(env)
end