Class: VagrantVbguest::Middleware

Inherits:
Object
  • Object
show all
Includes:
Helpers::Rebootable
Defined in:
lib/vagrant-vbguest/middleware.rb

Overview

A Vagrant middleware which checks the installed VirtualBox Guest Additions to match the installed VirtualBox installation on the host system.

Instance Method Summary collapse

Methods included from Helpers::Rebootable

included, #reboot, #reboot!, #reboot?, #rebooted?

Methods included from Helpers::VmCompatible

#communicate, #driver, included

Constructor Details

#initialize(app, env) ⇒ Middleware

Returns a new instance of Middleware.



10
11
12
13
# File 'lib/vagrant-vbguest/middleware.rb', line 10

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant-vbguest/middleware.rb', line 15

def call(env)
  @env    = env
  vm      = env[:vm] || env[:machine]

  options = override_config(vm.config.vbguest.to_hash).freeze

  if options[:auto_update]
    machine = VagrantVbguest::Machine.new vm, options
    status  = machine.state
    vm.env.ui.send((:ok == status ? :success : :warn), I18n.t("vagrant_vbguest.status.#{status}", **machine.info))
    machine.run
    reboot(vm, options) if machine.reboot?
  end
rescue VagrantVbguest::Installer::NoInstallerFoundError => e
  vm.env.ui.error e.message
ensure
  @app.call(env)
end

#override_config(opts) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/vagrant-vbguest/middleware.rb', line 34

def override_config(opts)
  if opts[:auto_reboot] && Vagrant::VERSION.between?("1.1.0", "1.1.5") && Vagrant::VERSION != "1.1.4"
    @env[:ui].warn I18n.t("vagrant_vbguest.vagrant_11_reload_issues")
    opts.merge!({:auto_reboot => false})
  end
  opts
end