Class: VagrantPlugins::Registration::Action::UnregisterOnHalt

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-registration/action/unregister_on_halt.rb

Overview

This unregisters the guest if the guest has registration capability

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ UnregisterOnHalt

Returns a new instance of UnregisterOnHalt.



8
9
10
11
# File 'lib/vagrant-registration/action/unregister_on_halt.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new('vagrant_registration::action::unregister_on_halt')
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-registration/action/unregister_on_halt.rb', line 13

def call(env)
  config = env[:machine].config.registration
  guest = env[:machine].guest

  if capabilities_provided?(guest) && manager_installed?(guest, env[:ui]) && !config.skip && config.unregister_on_halt
    env[:ui].info I18n.t('registration.action.unregister.unregistration_info')
    guest.capability(:registration_unregister)
  end

  @logger.debug(I18n.t('registration.action.unregister.skip_due_config')) if config.skip
  @logger.debug(I18n.t('registration.action.unregister.skip_on_halt_due_config')) unless config.unregister_on_halt
  @app.call(env)

# Guest might not be available after halting, so log the exception and continue
rescue => e
  @logger.info(e)
  @logger.debug I18n.t('registration.action.unregister.guest_unavailable')
  @app.call(env)
end