class VagrantPlugins::Registration::Plugin

Public Class Methods

Source
# File lib/vagrant-registration/plugin.rb, line 106
def self.libvirt?
  defined?(VagrantPlugins::ProviderLibvirt::Provider)
end

Determines if LibVirt is provider

Source
# File lib/vagrant-registration/plugin.rb, line 27
def register(hook)
  setup_logging

  registered = false
  if virtual_box?
    hook.after(VagrantPlugins::ProviderVirtualBox::Action::WaitForCommunicator,
                VagrantPlugins::Registration::Action.action_register)
    registered = true
  end
  if libvirt?
    hook.after(VagrantPlugins::ProviderLibvirt::Action::WaitTillUp,
              VagrantPlugins::Registration::Action.action_register)
    registered = true
  end
  # Best guess for the other providers
  unless registered
    hook.after(Vagrant::Action::Builtin::WaitForCommunicator,
              VagrantPlugins::Registration::Action.action_register)
  end
end

vagrant-vbguest plugin updates GuestAdditions for VirtualBox and therefore needs to be run after the box got registered. See github.com/projectatomic/adb-vagrant-registration/issues/69

vagrant-vbguest hooks before VagrantPlugins::ProviderVirtualBox::Action::CheckGuestAdditions (see github.com/mitchellh/vagrant/blob/master/plugins/providers/virtualbox/action.rb#L81) For registration to occur in time, it has to happen before that. Using WaitForCommunicator to be sure - github.com/dotless-de/vagrant-vbguest/blob/master/lib/vagrant-vbguest.rb#L53

For vagrant-libvirt WaitTillUp is used

Source
# File lib/vagrant-registration/plugin.rb, line 75
def self.setup_logging
  require 'log4r'
  level = nil
  begin
    level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
  rescue NameError
    # This means that the logging constant wasn't found,
    # which is fine. We just keep `level` as `nil`. But
    # we tell the user.
    level = nil
  end
  # Some constants, such as "true" resolve to booleans, so the
  # above error checking doesn't catch it. This will check to make
  # sure that the log level is an integer, as Log4r requires.
  level = nil unless level.is_a?(Integer)
  # Set the logging level on all "vagrant" namespaced
  # logs as long as we have a valid level.
  if level
    logger = Log4r::Logger.new('vagrant_registration')
    logger.outputters = Log4r::Outputter.stderr
    logger.level = level
    logger = nil
  end
end

This sets up our log level to be whatever VAGRANT_LOG is for loggers prepended with ‘vagrant_registration’

Source
# File lib/vagrant-registration/plugin.rb, line 53
def unregister_on_destroy(hook)
  setup_logging
  hook.prepend(VagrantPlugins::Registration::Action.action_unregister_on_destroy)
end
Source
# File lib/vagrant-registration/plugin.rb, line 48
def unregister_on_halt(hook)
  setup_logging
  hook.prepend(VagrantPlugins::Registration::Action.action_unregister_on_halt)
end
Source
# File lib/vagrant-registration/plugin.rb, line 101
def self.virtual_box?
  defined?(VagrantPlugins::ProviderVirtualBox::Provider)
end

Determines if VirtualBox is provider