Make export in general VBoxManage friendly

This commit is contained in:
Mitchell Hashimoto 2011-12-26 19:06:44 -08:00
parent fbe984b32d
commit 7e4d652702
5 changed files with 37 additions and 19 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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|