Class: VagrantPlugins::Registration::Plugin

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

Class Method Summary collapse

Class Method Details

.libvirt?Boolean

Determines if LibVirt is provider

Returns:

  • (Boolean)


106
107
108
# File 'lib/vagrant-registration/plugin.rb', line 106

def self.libvirt?
  defined?(VagrantPlugins::ProviderLibvirt::Provider)
end

.register(hook) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

.setup_loggingObject

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



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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

.unregister_on_destroy(hook) ⇒ Object



53
54
55
56
# 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

.unregister_on_halt(hook) ⇒ Object



48
49
50
51
# 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

.virtual_box?Boolean

Determines if VirtualBox is provider

Returns:

  • (Boolean)


101
102
103
# File 'lib/vagrant-registration/plugin.rb', line 101

def self.virtual_box?
  defined?(VagrantPlugins::ProviderVirtualBox::Provider)
end