Sha256: 3a82ac61df5b3521944b65489c66f68cb9d5f1ae2a8e5bc2d3d38ba0c3564feb

Contents?: true

Size: 1.84 KB

Versions: 10

Compression:

Stored size: 1.84 KB

Contents

require 'log4r'
# require 'log4r/yamlconfigurator'

module VagrantPlugins
  module ProviderLibvirt
    module Action
      class RemoveStaleVolume
        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

        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vagrant-libvirt-0.5.3 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.5.2 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.5.1 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.5.0 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.4.1 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.4.0 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.3.0 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.2.1 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.1.2 lib/vagrant-libvirt/action/remove_stale_volume.rb
vagrant-libvirt-0.1.0 lib/vagrant-libvirt/action/remove_stale_volume.rb