2014-09-09 17:17:04 +00:00
|
|
|
require "log4r"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
|
|
|
class CreateClone
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::action::vm::clone")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2015-10-08 15:58:47 +00:00
|
|
|
# Do the actual clone
|
2015-10-08 16:03:58 +00:00
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.clone.creating")
|
2015-10-06 18:11:41 +00:00
|
|
|
env[:machine].id = env[:machine].provider.driver.clonevm(
|
2015-10-08 16:33:55 +00:00
|
|
|
env[:clone_id], env[:clone_snapshot]) do |progress|
|
2014-09-09 17:17:04 +00:00
|
|
|
env[:ui].clear_line
|
|
|
|
env[:ui].report_progress(progress, 100, false)
|
|
|
|
end
|
|
|
|
|
2015-10-06 18:11:41 +00:00
|
|
|
# Clear the line one last time since the progress meter doesn't
|
|
|
|
# disappear immediately.
|
2014-09-09 17:17:04 +00:00
|
|
|
env[:ui].clear_line
|
|
|
|
|
|
|
|
# Flag as erroneous and return if clone failed
|
|
|
|
raise Vagrant::Errors::VMCloneFailure if !env[:machine].id
|
|
|
|
|
|
|
|
# Continue
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
|
|
|
|
def recover(env)
|
|
|
|
if env[:machine].state.id != :not_created
|
|
|
|
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
|
|
|
|
|
|
|
|
# If we're not supposed to destroy on error then just return
|
|
|
|
return if !env[:destroy_on_error]
|
|
|
|
|
|
|
|
# Interrupted, destroy the VM. We note that we don't want to
|
|
|
|
# validate the configuration here, and we don't want to confirm
|
|
|
|
# we want to destroy.
|
|
|
|
destroy_env = env.clone
|
|
|
|
destroy_env[:config_validate] = false
|
|
|
|
destroy_env[:force_confirm_destroy] = true
|
|
|
|
env[:action_runner].run(Action.action_destroy, destroy_env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|