Update the virtualbox driver to import base boxes into a unique(ish) VM folder to prevent collisions.

This commit is contained in:
Scott Moyer 2013-04-18 11:52:39 -04:00 committed by Andy Fowler
parent a92e03cf4c
commit c2a3a30e35
1 changed files with 25 additions and 10 deletions

View File

@ -162,7 +162,29 @@ module VagrantPlugins
output = "" output = ""
total = "" total = ""
last = 0 last = 0
execute("import", ovf) do |type, data|
output = execute("import", "-n", ovf)
output =~ /Suggested VM name "(.+?)"/
suggested_name = $1.to_s
specified_name = "#{suggested_name}_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" #Millisecond + Random
#Build the specified name param list
name_params = Array.new
name_params << "--vsys" << "0" << "--vmname" << specified_name
#Extract the disks list and build the disk target params
disk_params = Array.new
disks = output.scan(/(\d+): Hard disk image: source image=.+, target path=(.+),/)
disks.each do |unit_num, path|
disk_params << "--vsys"
disk_params << "0" #Derive vsys num .. do we support OVF's with multiple machines?
disk_params << "--unit"
disk_params << unit_num
disk_params << "--disk"
disk_params << path.sub("/#{suggested_name}/", "/#{specified_name}/")
end
execute("import", ovf , *name_params, *disk_params) do |type, data|
if type == :stdout if type == :stdout
# Keep track of the stdout so that we can get the VM name # Keep track of the stdout so that we can get the VM name
output << data output << data
@ -186,16 +208,9 @@ module VagrantPlugins
end end
end end
# Find the name of the VM name
if output !~ /Suggested VM name "(.+?)"/
@logger.error("Couldn't find VM name in the output.")
return nil
end
name = $1.to_s
output = execute("list", "vms") output = execute("list", "vms")
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
if output =~ /^"#{Regexp.escape(specified_name)}" \{(.+?)\}$/
return $1.to_s return $1.to_s
end end