Class: VagrantPlugins::ProviderLibvirt::Action::HandleStoragePool
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::HandleStoragePool
- Includes:
- Util::ErbTemplate
- Defined in:
- lib/vagrant-libvirt/action/handle_storage_pool.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ HandleStoragePool
constructor
A new instance of HandleStoragePool.
Methods included from Util::ErbTemplate
Constructor Details
#initialize(app, env) ⇒ HandleStoragePool
Returns a new instance of HandleStoragePool.
9 10 11 12 |
# File 'lib/vagrant-libvirt/action/handle_storage_pool.rb', line 9 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_libvirt::action::handle_storage_pool") @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vagrant-libvirt/action/handle_storage_pool.rb', line 14 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. end raise Errors::NoStoragePool if !libvirt_pool @app.call(env) end |