Class: VagrantPlugins::ProviderLibvirt::Action::RemoveStaleVolume
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::RemoveStaleVolume
- Defined in:
- lib/vagrant-libvirt/action/remove_stale_volume.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env) ⇒ RemoveStaleVolume
constructor
A new instance of RemoveStaleVolume.
Constructor Details
#initialize(app, _env) ⇒ RemoveStaleVolume
Returns a new instance of RemoveStaleVolume.
10 11 12 13 14 15 16 17 |
# File 'lib/vagrant-libvirt/action/remove_stale_volume.rb', line 10 def initialize(app, _env) # log4r_config= YAML.load_file(File.join(File.dirname(__FILE__),"log4r.yaml")) # log_cfg = Log4r::YamlConfigurator # log_cfg.decode_yaml( log4r_config['log4r_config'] ) @logger = Log4r::Logger.new('vagrant_libvirt::action::remove_stale_volume') @app = app end |
Instance Method Details
#call(env) ⇒ Object
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 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vagrant-libvirt/action/remove_stale_volume.rb', line 19 def call(env) # Remove stale server volume config = env[:machine].provider_config # Check for storage pool, where box image should be created fog_pool = env[:machine].provider.driver.connection.pools.all( name: config.storage_pool_name ).first env[:result] = nil if not fog_pool @logger.debug("**** Pool #{config.storage_pool_name} not found") return @app.call(env) end @logger.debug("**** Pool #{fog_pool.name}") # This is name of newly created image for vm. name = "#{env[:domain_name]}.img" @logger.debug("**** Volume name #{name}") # remove root storage box_volume = env[:machine].provider.driver.connection.volumes.all( name: name ).find { |x| x.pool_name == fog_pool.name } if box_volume && box_volume.id env[:ui].info(I18n.t('vagrant_libvirt.remove_stale_volume')) @logger.info("Deleting volume #{box_volume.key}") box_volume.destroy env[:result] = box_volume else @logger.debug("**** Volume #{name} not found in pool #{fog_pool.name}") end # Continue the middleware chain. @app.call(env) end |