From c2a3a30e3579bd715795b6e7cc509b34d7e93f32 Mon Sep 17 00:00:00 2001 From: Scott Moyer Date: Thu, 18 Apr 2013 11:52:39 -0400 Subject: [PATCH 1/2] Update the virtualbox driver to import base boxes into a unique(ish) VM folder to prevent collisions. --- .../virtualbox/driver/version_4_2.rb | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index a537c4a60..fe803946c 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -162,7 +162,29 @@ module VagrantPlugins output = "" total = "" 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 # Keep track of the stdout so that we can get the VM name output << data @@ -186,16 +208,9 @@ module VagrantPlugins 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") - if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/ + + if output =~ /^"#{Regexp.escape(specified_name)}" \{(.+?)\}$/ return $1.to_s end From 2e9286b4d366bb85ef4c3cd7a5f93350467bbb32 Mon Sep 17 00:00:00 2001 From: Andy Fowler Date: Fri, 8 Nov 2013 12:48:37 -0500 Subject: [PATCH 2/2] use vbox4.2 driver parallel-safe box import in 4.3 uses what @smoyer did for vbox 4.2 in vbox 4.3, tested against VBoxManage 4.3.2 --- .../virtualbox/driver/version_4_3.rb | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 123906502..6e5d2940f 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -162,7 +162,32 @@ module VagrantPlugins output = "" total = "" last = 0 - execute("import", ovf) do |type, data| + + # Dry-run the import to get the suggested name & path + output = execute("import", "-n", ovf) + output =~ /Suggested VM name "(.+?)"/ + suggested_name = $1.to_s + + # Append millisecond + random to the path in case we're importing the same box elsewhere + specified_name = "#{suggested_name}_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" + + # 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" + 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 # Keep track of the stdout so that we can get the VM name output << data @@ -186,16 +211,8 @@ module VagrantPlugins 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") - if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/ + if output =~ /^"#{Regexp.escape(specified_name)}" \{(.+?)\}$/ return $1.to_s end