class VagrantPlugins::ProviderLibvirt::Action::CleanupOnFailure
Public Class Methods
new(app, _env)
click to toggle source
# File lib/vagrant-libvirt/action/cleanup_on_failure.rb, line 7 def initialize(app, _env) @logger = Log4r::Logger.new('vagrant_libvirt::action::cleanup_on_failure') @app = app @cleanup = true end
Public Instance Methods
call(env)
click to toggle source
# File lib/vagrant-libvirt/action/cleanup_on_failure.rb, line 13 def call(env) # passing a value doesn't work as the env that is updated may be dupped from # the original meaning the latter action's update is discarded. Instead pass # a reference to the method on this class that will toggle the instance # variable indicating whether cleanup is needed or not. env['vagrant-libvirt.complete'] = method(:completed) @app.call(env) end
completed()
click to toggle source
# File lib/vagrant-libvirt/action/cleanup_on_failure.rb, line 49 def completed @cleanup = false end
recover(env)
click to toggle source
# File lib/vagrant-libvirt/action/cleanup_on_failure.rb, line 23 def recover(env) return unless env[:machine] && env[:machine].state.id != :not_created # only destroy if failed to complete bring up unless @cleanup @logger.debug('VM provider setup was completed, no need to halt/destroy') return end # If we're not supposed to destroy on error then just return return unless env[:destroy_on_error] if env[:halt_on_error] halt_env = env.dup halt_env.delete(:interrupted) halt_env[:config_validate] = false env[:action_runner].run(Action.action_halt, halt_env) else destroy_env = env.dup destroy_env.delete(:interrupted) destroy_env[:config_validate] = false destroy_env[:force_confirm_destroy] = true env[:action_runner].run(Action.action_destroy, destroy_env) end end