Class: VagrantPlugins::ProviderLibvirt::Action::CleanupOnFailure
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::CleanupOnFailure
- Defined in:
- lib/vagrant-libvirt/action/cleanup_on_failure.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #completed ⇒ Object
-
#initialize(app, _env) ⇒ CleanupOnFailure
constructor
A new instance of CleanupOnFailure.
- #recover(env) ⇒ Object
Constructor Details
#initialize(app, _env) ⇒ CleanupOnFailure
Returns a new instance of CleanupOnFailure.
8 9 10 11 12 |
# File 'lib/vagrant-libvirt/action/cleanup_on_failure.rb', line 8 def initialize(app, _env) @logger = Log4r::Logger.new('vagrant_libvirt::action::cleanup_on_failure') @app = app @cleanup = true end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/vagrant-libvirt/action/cleanup_on_failure.rb', line 14 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 ⇒ Object
50 51 52 |
# File 'lib/vagrant-libvirt/action/cleanup_on_failure.rb', line 50 def completed @cleanup = false end |
#recover(env) ⇒ Object
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 |
# File 'lib/vagrant-libvirt/action/cleanup_on_failure.rb', line 24 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 |