diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index e8c768a0e..53f68bc8a 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -28,6 +28,9 @@ module Vagrant @env = env raise Errors::PackageOutputExists if File.exist?(tar_path) + raise Errors::PackageRequiresDirectory if !env["package.directory"] || + !File.directory?(env["package.directory"]) + compress @app.call(env) @@ -46,7 +49,12 @@ module Vagrant # to the temporary directory so they are included in a sub-folder within # the actual box def copy_include_files - env["package.files"].each do |from, to| + include_directory = Pathname.new(@env["package.directory"]).join("include") + + @env["package.files"].each do |from, dest| + # We place the file in the include directory + to = include_directory.join(dest) + @env[:ui].info I18n.t("vagrant.actions.general.package.packaging", :file => from) FileUtils.mkdir_p(to.parent) diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index bdff3ad27..9bcc7a089 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -14,7 +14,7 @@ module Vagrant def call(env) @env = env - raise Errors::VMPowerOffToPackage if !@env["vm"].vm.powered_off? + raise Errors::VMPowerOffToPackage if @env["vm"].state != :poweroff setup_temp_dir export @@ -38,7 +38,7 @@ module Vagrant def export @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting") - @env["vm"].vm.export(ovf_path) do |progress| + @env["vm"].driver.export(ovf_path) do |progress| @env[:ui].report_progress(progress.percent, 100, false) end end diff --git a/lib/vagrant/action/vm/package_vagrantfile.rb b/lib/vagrant/action/vm/package_vagrantfile.rb index 68f3257d2..17869091f 100644 --- a/lib/vagrant/action/vm/package_vagrantfile.rb +++ b/lib/vagrant/action/vm/package_vagrantfile.rb @@ -26,7 +26,7 @@ module Vagrant def create_vagrantfile File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f| f.write(TemplateRenderer.render("package_Vagrantfile", { - :base_mac => @env["vm"].vm.network_adapters.first.mac_address + :base_mac => @env["vm"].driver.read_mac_address })) end end diff --git a/lib/vagrant/action/vm/setup_package_files.rb b/lib/vagrant/action/vm/setup_package_files.rb index 9cb5387d5..f45210707 100644 --- a/lib/vagrant/action/vm/setup_package_files.rb +++ b/lib/vagrant/action/vm/setup_package_files.rb @@ -14,13 +14,6 @@ module Vagrant end def call(env) - raise Errors::PackageRequiresDirectory if !env["package.directory"] || - !File.directory?(env["package.directory"]) - - # Create a pathname to the directory that will store the files - # we wish to include with the box. - include_directory = Pathname.new(env["package.directory"]).join("include") - files = {} env["package.include"].each do |file| source = Pathname.new(file) @@ -31,9 +24,9 @@ module Vagrant # include directory. Kind of strange, but seems to match what people # expect based on history. if source.relative? - dest = include_directory.join(source) + dest = source else - dest = include_directory.join(source.basename) + dest = source.basename end # Assign the mapping @@ -42,7 +35,7 @@ module Vagrant if env["package.vagrantfile"] # Vagrantfiles are treated special and mapped to a specific file - files[env["package.vagrantfile"]] = include_directory.join("_Vagrantfile") + files[env["package.vagrantfile"]] = "_Vagrantfile" end # Verify the mapping diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index 3ac8a6c52..c4199cff6 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -116,11 +116,6 @@ module Vagrant execute("discardstate", @uuid) end - # Executes a raw command. - def execute_command(command) - raw(*command) - end - # Enables network adapters on this virtual machine. def enable_adapters(adapters) args = [] @@ -141,6 +136,19 @@ module Vagrant execute("modifyvm", @uuid, *args) end + # Executes a raw command. + def execute_command(command) + raw(*command) + end + + # Exports the virtual machine to the given path. + # + # @param [String] path Path to the OVF file. + def export(path) + # TODO: Progress + execute("export", @uuid, "--output", path.to_s) + end + # Forwards a set of ports for a VM. # # This will not affect any previously set forwarded ports, @@ -298,6 +306,15 @@ module Vagrant end end + # Reads the MAC address of the first network interface. + def read_mac_address + execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line| + return $1.to_s if line =~ /^macaddress1="(.+?)"$/ + end + + nil + end + # This reads the folder where VirtualBox places it's VMs. def read_machine_folder execute("list", "systemproperties").split("\n").each do |line|