Class: VagrantPlugins::ProviderKvm::Action::CheckBox

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-kvm/action/check_box.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ CheckBox

Returns a new instance of CheckBox.



5
6
7
# File 'lib/vagrant-kvm/action/check_box.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object

Raises:

  • (Vagrant::Errors::BoxNotSpecified)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant-kvm/action/check_box.rb', line 9

def call(env)
  box_name = env[:machine].config.vm.box
  raise Vagrant::Errors::BoxNotSpecified if !box_name

  if !env[:box_collection].find(box_name, :kvm)
    box_url = env[:machine].config.vm.box_url
    raise Vagrant::Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url

    # Add the box then reload the box collection so that it becomes
    # aware of it.
    env[:ui].info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
    env[:action_runner].run(Vagrant::Action.action_box_add, {
      :box_name     => box_name,
      :box_provider => env[:machine].provider_name,
      :box_url      => box_url
    })

    # Reload the environment and set the VM to be the new loaded VM.
    env[:machine] = env[:machine].env.machine(
      env[:machine].name, env[:machine].provider_name, true)
  end

  @app.call(env)
end