2012-08-15 05:38:41 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
|
|
|
class Import
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.import.importing",
|
|
|
|
:name => env[:machine].box.name)
|
|
|
|
|
|
|
|
# Import the virtual machine
|
|
|
|
ovf_file = env[:machine].box.directory.join("box.ovf").to_s
|
2013-02-10 03:36:56 +00:00
|
|
|
if Vagrant::Util::Platform.cygwin?
|
|
|
|
ovf_file = `cygpath -w #{ovf_file}`.chomp
|
|
|
|
end
|
2013-02-10 03:42:04 +00:00
|
|
|
env[:machine].id = env[:machine].provider.driver.import(ovf_file) do |progress|
|
2012-08-15 05:38:41 +00:00
|
|
|
env[:ui].clear_line
|
|
|
|
env[:ui].report_progress(progress, 100, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Clear the line one last time since the progress meter doesn't disappear
|
|
|
|
# immediately.
|
|
|
|
env[:ui].clear_line
|
|
|
|
|
|
|
|
# If we got interrupted, then the import could have been
|
|
|
|
# interrupted and its not a big deal. Just return out.
|
|
|
|
return if env[:interrupted]
|
|
|
|
|
|
|
|
# Flag as erroneous and return if import failed
|
|
|
|
raise Vagrant::Errors::VMImportFailure if !env[:machine].id
|
|
|
|
|
|
|
|
# Import completed successfully. Continue the chain
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def recover(env)
|
2013-01-21 17:38:37 +00:00
|
|
|
if env[:machine].provider.state.id != :not_created
|
2012-08-15 05:38:41 +00:00
|
|
|
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
|
|
|
|
|
|
|
# Interrupted, destroy the VM. We note that we don't want to
|
2012-12-23 06:43:35 +00:00
|
|
|
# validate the configuration here, and we don't want to confirm
|
|
|
|
# we want to destroy.
|
2012-08-15 05:38:41 +00:00
|
|
|
destroy_env = env.clone
|
2013-01-18 21:26:14 +00:00
|
|
|
destroy_env[:config_validate] = false
|
2012-12-23 06:43:35 +00:00
|
|
|
destroy_env[:force_confirm_destroy] = true
|
2012-08-15 05:38:41 +00:00
|
|
|
env[:action_runner].run(Action.action_destroy, destroy_env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|