mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
add step to remove stale volume on destroy action
This commit is contained in:
parent
b6babcdade
commit
2e01a54fc3
@ -155,8 +155,15 @@ module VagrantPlugins
|
|||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, IsCreated do |env, b2|
|
b.use Call, IsCreated do |env, b2|
|
||||||
|
if !env[:result]
|
||||||
|
# Try to remove stale volumes anyway
|
||||||
|
b2.use ConnectLibvirt
|
||||||
|
b2.use SetNameOfDomain
|
||||||
|
b2.use RemoveStaleVolume
|
||||||
if !env[:result]
|
if !env[:result]
|
||||||
b2.use MessageNotCreated
|
b2.use MessageNotCreated
|
||||||
|
end
|
||||||
|
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -338,6 +345,8 @@ module VagrantPlugins
|
|||||||
autoload :MessageNotRunning, action_root.join('message_not_running')
|
autoload :MessageNotRunning, action_root.join('message_not_running')
|
||||||
autoload :MessageNotSuspended, action_root.join('message_not_suspended')
|
autoload :MessageNotSuspended, action_root.join('message_not_suspended')
|
||||||
|
|
||||||
|
autoload :RemoveStaleVolume, action_root.join('remove_stale_volume')
|
||||||
|
|
||||||
autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
|
autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
|
||||||
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
|
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
|
||||||
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
||||||
|
49
lib/vagrant-libvirt/action/remove_stale_volume.rb
Normal file
49
lib/vagrant-libvirt/action/remove_stale_volume.rb
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
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
|
||||||
|
env[:ui].info(I18n.t('vagrant_libvirt.remove_stale_volume'))
|
||||||
|
|
||||||
|
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)
|
||||||
|
@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 = ProviderLibvirt::Util::Collection.find_matching(
|
||||||
|
env[:libvirt_compute].volumes.all, name)
|
||||||
|
if box_volume && box_volume.pool_name == fog_pool.name
|
||||||
|
@logger.info("Deleting volume #{box_volume.key}")
|
||||||
|
box_volume.destroy
|
||||||
|
env[:result] = box_volume
|
||||||
|
else
|
||||||
|
env[:result] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# Continue the middleware chain.
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -44,6 +44,8 @@ en:
|
|||||||
Rsyncing folder: %{hostpath} => %{guestpath}
|
Rsyncing folder: %{hostpath} => %{guestpath}
|
||||||
ready: |-
|
ready: |-
|
||||||
Machine is booted and ready for use!
|
Machine is booted and ready for use!
|
||||||
|
remove_stale_volume: |-
|
||||||
|
Remove stale volume...
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
package_not_supported: Not support package for libvirt. Create box manualy.
|
package_not_supported: Not support package for libvirt. Create box manualy.
|
||||||
|
Loading…
Reference in New Issue
Block a user