[DRE-commits] [vagrant-libvirt] 92/163: Add lock around storage pool creation; closes #278
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:57:10 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag 0.0.26
in repository vagrant-libvirt.
commit 47a21433a5b215a67214c9688c3be5310e3bc2ea
Author: Brian Pitts <brian at polibyte.com>
Date: Sun Dec 7 12:16:05 2014 -0600
Add lock around storage pool creation; closes #278
---
lib/vagrant-libvirt/action/handle_storage_pool.rb | 54 ++++++++++++-----------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/lib/vagrant-libvirt/action/handle_storage_pool.rb b/lib/vagrant-libvirt/action/handle_storage_pool.rb
index 1776916..9ebae53 100644
--- a/lib/vagrant-libvirt/action/handle_storage_pool.rb
+++ b/lib/vagrant-libvirt/action/handle_storage_pool.rb
@@ -6,38 +6,42 @@ module VagrantPlugins
class HandleStoragePool
include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
+ @@lock = Mutex.new
+
def initialize(app, env)
@logger = Log4r::Logger.new("vagrant_libvirt::action::handle_storage_pool")
@app = app
end
def call(env)
- # Get config options.
- config = env[:machine].provider_config
-
- # Check for storage pool, where box image should be created
- fog_pool = ProviderLibvirt::Util::Collection.find_matching(
- env[:libvirt_compute].pools.all, config.storage_pool_name)
- return @app.call(env) if fog_pool
-
- @logger.info("No storage pool '#{config.storage_pool_name}' is available.")
-
- # If user specified other pool than default, don't create default
- # storage pool, just write error message.
- raise Errors::NoStoragePool if config.storage_pool_name != 'default'
-
- @logger.info("Creating storage pool 'default'")
-
- # Fog libvirt currently doesn't support creating pools. Use
- # ruby-libvirt client directly.
- begin
- libvirt_pool = env[:libvirt_compute].client.create_storage_pool_xml(
- to_xml('default_storage_pool'))
- rescue => e
- raise Errors::CreatingStoragePoolError,
- :error_message => e.message
+ @@lock.synchronize do
+ # Get config options.
+ config = env[:machine].provider_config
+
+ # Check for storage pool, where box image should be created
+ fog_pool = ProviderLibvirt::Util::Collection.find_matching(
+ env[:libvirt_compute].pools.all, config.storage_pool_name)
+ return @app.call(env) if fog_pool
+
+ @logger.info("No storage pool '#{config.storage_pool_name}' is available.")
+
+ # If user specified other pool than default, don't create default
+ # storage pool, just write error message.
+ raise Errors::NoStoragePool if config.storage_pool_name != 'default'
+
+ @logger.info("Creating storage pool 'default'")
+
+ # Fog libvirt currently doesn't support creating pools. Use
+ # ruby-libvirt client directly.
+ begin
+ libvirt_pool = env[:libvirt_compute].client.create_storage_pool_xml(
+ to_xml('default_storage_pool'))
+ rescue => e
+ raise Errors::CreatingStoragePoolError,
+ :error_message => e.message
+ end
+ raise Errors::NoStoragePool if !libvirt_pool
end
- raise Errors::NoStoragePool if !libvirt_pool
@app.call(env)
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git
More information about the Pkg-ruby-extras-commits
mailing list