mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Make network creation thread-safe, closes #104
This commit is contained in:
parent
46306503f4
commit
1aabe66b23
@ -2,6 +2,7 @@ require 'log4r'
|
|||||||
require 'vagrant/util/network_ip'
|
require 'vagrant/util/network_ip'
|
||||||
require 'vagrant/util/scoped_hash_override'
|
require 'vagrant/util/scoped_hash_override'
|
||||||
require 'ipaddr'
|
require 'ipaddr'
|
||||||
|
require 'thread'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderLibvirt
|
module ProviderLibvirt
|
||||||
@ -13,6 +14,8 @@ module VagrantPlugins
|
|||||||
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
|
||||||
include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
|
include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
|
||||||
|
|
||||||
|
@@lock = Mutex.new
|
||||||
|
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
mess = 'vagrant_libvirt::action::create_networks'
|
mess = 'vagrant_libvirt::action::create_networks'
|
||||||
@logger = Log4r::Logger.new(mess)
|
@logger = Log4r::Logger.new(mess)
|
||||||
@ -74,6 +77,10 @@ module VagrantPlugins
|
|||||||
networks.push(options)
|
networks.push(options)
|
||||||
end
|
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
|
# Iterate over networks If some network is not
|
||||||
# available, create it if possible. Otherwise raise an error.
|
# available, create it if possible. Otherwise raise an error.
|
||||||
networks.each do |options|
|
networks.each do |options|
|
||||||
@ -112,6 +119,7 @@ module VagrantPlugins
|
|||||||
autostart_network if !@interface_network[:autostart]
|
autostart_network if !@interface_network[:autostart]
|
||||||
activate_network if !@interface_network[:active]
|
activate_network if !@interface_network[:active]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user