Sha256: a4172b7f0aa1e37b139888d4c0c99dada0b3711057edf844d2bc159aa6be4da1

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

require 'log4r'

module VagrantPlugins
  module ProviderLibvirt
    module Action
      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)
          @@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.define_storage_pool_xml(
                to_xml('default_storage_pool'))
              libvirt_pool.build
              libvirt_pool.create
            rescue => e
              raise Errors::CreatingStoragePoolError,
                :error_message => e.message
            end
            raise Errors::NoStoragePool if !libvirt_pool
          end

          @app.call(env)
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vagrant-libvirt-0.0.30 lib/vagrant-libvirt/action/handle_storage_pool.rb
vagrant-libvirt-0.0.29 lib/vagrant-libvirt/action/handle_storage_pool.rb
vagrant-libvirt-0.0.28 lib/vagrant-libvirt/action/handle_storage_pool.rb
vagrant-libvirt-0.0.27 lib/vagrant-libvirt/action/handle_storage_pool.rb
vagrant-libvirt-0.0.26 lib/vagrant-libvirt/action/handle_storage_pool.rb
vagrant-libvirt-0.0.25 lib/vagrant-libvirt/action/handle_storage_pool.rb