Class: Vagrant::Action::VM::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/vm/import.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Import

Returns a new instance of Import.



5
6
7
# File 'lib/vagrant/action/vm/import.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant/action/vm/import.rb', line 9

def call(env)
  env.ui.info I18n.t("vagrant.actions.vm.import.importing", :name => env.env.box.name)

  # Import the virtual machine
  env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file.to_s) do |progress|
    env.ui.report_progress(progress.percent, 100, false)
  end

  # Flag as erroneous and return if import failed
  raise Errors::VMImportFailure if !env["vm"].vm

  # Import completed successfully. Continue the chain
  @app.call(env)
end

#recover(env) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/vagrant/action/vm/import.rb', line 24

def recover(env)
  if env["vm"].created?
    return if env["vagrant.error"].is_a?(Errors::VagrantError)

    # Interrupted, destroy the VM
    env["actions"].run(:destroy)
  end
end