Acquire lock to prevent concurrent creation of master VM for the same box.

This commit is contained in:
Manuel Pöter 2015-06-03 13:31:43 +02:00
parent c3151c0b88
commit 9d63ca4dd2
1 changed files with 36 additions and 32 deletions

View File

@ -13,16 +13,16 @@ module VagrantPlugins
def call(env)
master_id_file = env[:machine].box.directory.join("master_id")
env[:machine].env.lock(env[:machine].box.name, retry: true) do
env[:master_id] = master_id_file.read.chomp if master_id_file.file?
if env[:master_id] && env[:machine].provider.driver.vm_exists?(env[:master_id])
# Master VM already exists -> nothing to do - continue.
@app.call(env)
@logger.info("Master VM for '#{env[:machine].box.name}' already exists (id=#{env[:master_id]}) - skipping import step.")
return @app.call(env)
end
env[:ui].info I18n.t("vagrant.actions.vm.clone.importing", name: env[:machine].box.name)
#TODO - prevent concurrent creation of master vms for the same box.
# Import the virtual machine
ovf_file = env[:machine].box.directory.join("box.ovf").to_s
env[:master_id] = env[:machine].provider.driver.import(ovf_file) do |progress|
@ -48,10 +48,14 @@ module VagrantPlugins
master_id_file.open("w+") do |f|
f.write(env[:master_id])
end
end
# If we got interrupted, then the import could have been
# interrupted and its not a big deal. Just return out.
return if env[:interrupted]
if env[:interrupted]
@logger.info("Import of master VM was interrupted -> exiting.")
return
end
# Import completed successfully. Continue the chain
@app.call(env)