class VagrantVbguest::Installer

Dispatches the installation process to a rigistered Installer implementation.

Public Class Methods

detect(vm, options) click to toggle source

Returns the class of the registered Installer class which matches first (according to it’s priority) or ‘nil` if none matches.

@param vm [Vagrant::VM] @param options [Hash]

# File lib/vagrant-vbguest/installer.rb, line 43
def detect(vm, options)
  @installers.keys.sort.reverse.each do |prio|
    klass = @installers[prio].detect { |k| k.match?(vm) }
    return klass if klass
  end
  return nil
end
new(vm, options = {}) click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 52
def initialize(vm, options = {})
  @vm = vm
  @env = vm.env
  @options = options
  @iso_path = nil
end
register(installer_class, prio = 5) click to toggle source

Register an Installer implementation. All Installer classes which wish to get picked automaticly using their ‘#match?` method have to register. Ad-hoc or small custom Installer meight not need to get registered, but need to get passed as an config option (`installer`)

Registration takes a priority which defines how specific the Installer matches a system. Low level installers, like “linux” or “bsd” use a small priority (2), while distribution installers use higher priority (5). Installers matching a specific version of a distribution should use heigher priority numbers.

@param installer_class [Class] A reference to the Installer class. @param prio [Fixnum] Priority describing how specific the Installer matches. (default: ‘5`)

# File lib/vagrant-vbguest/installer.rb, line 31
def register(installer_class, prio = 5)
  @installers ||= {}
  @installers[prio] ||= []
  @installers[prio] << installer_class
end

Public Instance Methods

cleanup() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 153
def cleanup
  return unless @guest_installer

  @guest_installer.cleanup do |type, data|
    @env.ui.info(data, :prefix => false, :new_line => false)
  end
end
guest_installer() click to toggle source

Returns an installer instance for the current vm This is either the one configured via ‘installer` option or detected from all registered installers (see {Installer.detect})

@return [Installers::Base]

# File lib/vagrant-vbguest/installer.rb, line 135
def guest_installer
  return @guest_installer if @guest_installer

  if (klass = guest_installer_class)
    @guest_installer = klass.new(@vm, @options)
  end

  @guest_installer
end
guest_installer_class() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 145
def guest_installer_class
  if @options[:installer].is_a?(Class)
    @options[:installer]
  else
    Installer.detect(@vm, @options)
  end
end
guest_version(reload=false) click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 94
def guest_version(reload=false)
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check guest version of' if !installer
  installer.guest_version(reload)
end
host_version() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 100
def host_version
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check host version of' if !installer
  installer.host_version
end
install() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 59
def install
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'install' if !installer

  with_hooks(:install) do
    installer.install do |type, data|
      @env.ui.info(data, :prefix => false, :new_line => false)
    end
  end
ensure
  cleanup
end
provides_vboxadd_tools?() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 118
def provides_vboxadd_tools?
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check platform support for vboxadd tools of' if !installer
  installer.provides_vboxadd_tools?
end
reboot_after_install?() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 112
def reboot_after_install?
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check if we need to reboot after installing' if !installer
  installer.reboot_after_install?
end
rebuild() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 72
def rebuild
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'rebuild' if !installer

  with_hooks(:rebuild) do
    installer.rebuild do |type, data|
      @env.ui.info(data, :prefix => false, :new_line => false)
    end
  end
end
run_hook(hook_name) click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 169
def run_hook(hook_name)
  hooks = @options.dig(:installer_hooks, hook_name)

  return if !hooks || hooks.empty?

  @vm.ui.info I18n.t("vagrant_vbguest.installer_hooks.#{hook_name}")
  Array(hooks).each do |l|
    @vm.communicate.sudo(l) do |type, data|
      @env.ui.info(data, :prefix => false, :new_line => false)
    end
  end
end
running?() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 106
def running?
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check current state of' if !installer
  installer.running?
end
start() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 83
def start
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'manual start' if !installer

  with_hooks(:start) do
    installer.start do |type, data|
      @env.ui.info(data, :prefix => false, :new_line => false)
    end
  end
end
vboxadd_tools_available?() click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 124
def vboxadd_tools_available?
  installer = guest_installer
  raise NoInstallerFoundError, :method => 'check for existing vboxadd tools of' if !installer
  installer.vboxadd_tools_available?
end
with_hooks(step_name) { || ... } click to toggle source
# File lib/vagrant-vbguest/installer.rb, line 161
def with_hooks(step_name)
  run_hook(:"before_#{step_name}")
  ret = yield
  run_hook(:"after_#{step_name}")

  ret
end