class VagrantPlugins::Registration::Action::UnregisterOnHalt

This unregisters the guest if the guest has registration capability

Public Class Methods

new(app, env) click to toggle source
# 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

Public Instance Methods

call(env) click to toggle source
# 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) && !config.skip && config.unregister_on_halt
    env[:ui].info('Unregistering box with vagrant-registration...')
    guest.capability(:registration_unregister)
  end

  @logger.debug('Unregistration is skipped due to the configuration') if config.skip
  @logger.debug('Unregistration is skipped on halt due to the configuration') 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('Guest is not available, ignore unregistration')
  @app.call(env)
end

Private Instance Methods

capabilities_provided?(guest) click to toggle source

Check if registration capabilities are available

# File lib/vagrant-registration/action/unregister_on_halt.rb, line 36
def capabilities_provided?(guest)
  if guest.capability?(:registration_unregister) && guest.capability?(:registration_manager_installed)
    true
  else
    @logger.debug('Unregistration is skipped due to the missing guest capability')
    false
  end
end
manager_installed?(guest) click to toggle source

Check if selected registration manager is installed

# File lib/vagrant-registration/action/unregister_on_halt.rb, line 46
def manager_installed?(guest)
  if guest.capability(:registration_manager_installed)
    true
  else
    @logger.debug('Registration manager not found on guest')
    false
  end
end